From d3066e191dea243009c06b76640475a96e36f398 Mon Sep 17 00:00:00 2001 From: Joshua Anderson Date: Tue, 19 Jul 2016 13:32:58 -0700 Subject: [PATCH] fix(test-style): make fmt fail style-test and fix existing formatting errors --- Makefile | 7 ++++--- cli/cli.go | 1 + cmd/apps_test.go | 4 ++-- cmd/keys_test.go | 8 ++++---- cmd/ps.go | 2 +- cmd/shortcuts_test.go | 13 ++++++------- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 16adcb59..608159e2 100644 --- a/Makefile +++ b/Makefile @@ -27,9 +27,9 @@ GCS_BUCKET ?= "gs://workflow-cli" GO_FILES = $(wildcard *.go) GO_LDFLAGS = -ldflags "-s -X ${repo_path}/version.BuildVersion=${VERSION}" -GO_PACKAGES = cmd parser $(wildcard pkg/*) +GO_PACKAGES = cmd parser cli $(wildcard pkg/*) GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES)) -GOFMT = gofmt -e -l -s +GOFMT = gofmtresult=$$(gofmt -e -l -s ${GO_FILES} ${GO_PACKAGES}); if [[ -n $$gofmtresult ]]; then echo "gofmt errors found in the following files: $${gofmtresult}"; false; fi; GOTEST = go test --cover --race -v # The tag of the commit @@ -94,7 +94,8 @@ setup-gotools: test: test-style test-unit test-style: - ${DEV_ENV_CMD} sh -c '${GOFMT} ${GO_FILES} ${GO_PACKAGES} && go vet $(repo_path) $(GO_PACKAGES_REPO_PATH)' + ${DEV_ENV_CMD} bash -c '${GOFMT}' + ${DEV_ENV_CMD} sh -c 'go vet $(repo_path) $(GO_PACKAGES_REPO_PATH)' @for i in $(addsuffix /...,$(GO_PACKAGES)); do \ ${DEV_ENV_CMD} golint $$i; \ done diff --git a/cli/cli.go b/cli/cli.go index f93e1196..66ba2b92 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -1,5 +1,6 @@ package cli +// Shortcuts is a map of all the shortcuts supported by the CLI var Shortcuts = map[string]string{ "create": "apps:create", "destroy": "apps:destroy", diff --git a/cmd/apps_test.go b/cmd/apps_test.go index 47f13777..1e2f61a7 100644 --- a/cmd/apps_test.go +++ b/cmd/apps_test.go @@ -24,11 +24,11 @@ type expandURLCases struct { func TestExpandUrl(t *testing.T) { checks := []expandURLCases{ - expandURLCases{ + { Input: "test.com", Expected: "test.com", }, - expandURLCases{ + { Input: "test", Expected: "test.foo.com", }, diff --git a/cmd/keys_test.go b/cmd/keys_test.go index 4a0f4b03..27e08675 100644 --- a/cmd/keys_test.go +++ b/cmd/keys_test.go @@ -132,19 +132,19 @@ type chooseKeyCases struct { func TestChooseKey(t *testing.T) { testKeys := []api.KeyCreateRequest{ - api.KeyCreateRequest{}, + {}, } checks := []chooseKeyCases{ - chooseKeyCases{ + { Reader: strings.NewReader("-1"), Expected: "-1 is not a valid option", }, - chooseKeyCases{ + { Reader: strings.NewReader("2"), Expected: "2 is not a valid option", }, - chooseKeyCases{ + { Reader: strings.NewReader("a"), Expected: "a is not a valid integer", }, diff --git a/cmd/ps.go b/cmd/ps.go index c93ccd19..db9e9fa2 100644 --- a/cmd/ps.go +++ b/cmd/ps.go @@ -133,7 +133,7 @@ func parseType(target string, appID string) (string, string) { psType, psName := "", "" if strings.Contains(target, "-") { - replaced := strings.Replace(target, appID + "-", "", 1) + replaced := strings.Replace(target, appID+"-", "", 1) parts := strings.Split(replaced, "-") // the API requires the type, for now // regex matches against how Deployment pod name is constructed diff --git a/cmd/shortcuts_test.go b/cmd/shortcuts_test.go index 3be5ad07..b0803b77 100644 --- a/cmd/shortcuts_test.go +++ b/cmd/shortcuts_test.go @@ -1,14 +1,13 @@ package cmd import ( - "testing" + "testing" ) - func TestShortcutsList(t *testing.T) { t.Parallel() - expected := `create -> apps:create + expected := `create -> apps:create destroy -> apps:destroy info -> apps:info login -> auth:login @@ -27,9 +26,9 @@ sharing:list -> perms:list sharing:remove -> perms:delete whoami -> auth:whoami ` - actual := sortShortcuts() - if actual != expected { - t.Errorf("Expected %s, Got %s", expected, actual) - } + actual := sortShortcuts() + if actual != expected { + t.Errorf("Expected %s, Got %s", expected, actual) + } }