Skip to content

Commit c655ea0

Browse files
fix(test-style): make fmt fail style-test and fix existing formatting errors (#135)
1 parent 89e4177 commit c655ea0

6 files changed

Lines changed: 18 additions & 17 deletions

File tree

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ GCS_BUCKET ?= "gs://workflow-cli"
2525

2626
GO_FILES = $(wildcard *.go)
2727
GO_LDFLAGS = -ldflags "-s -X ${repo_path}/version.BuildVersion=${VERSION}"
28-
GO_PACKAGES = cmd parser $(wildcard pkg/*)
28+
GO_PACKAGES = cmd parser cli $(wildcard pkg/*)
2929
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
30-
GOFMT = gofmt -e -l -s
30+
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;
3131
GOTEST = go test --cover --race -v
3232

3333
# The tag of the commit
@@ -96,7 +96,8 @@ setup-gotools:
9696
test: test-style test-unit
9797

9898
test-style:
99-
${DEV_ENV_CMD} sh -c '${GOFMT} ${GO_FILES} ${GO_PACKAGES} && go vet $(repo_path) $(GO_PACKAGES_REPO_PATH)'
99+
${DEV_ENV_CMD} bash -c '${GOFMT}'
100+
${DEV_ENV_CMD} sh -c 'go vet $(repo_path) $(GO_PACKAGES_REPO_PATH)'
100101
@for i in $(addsuffix /...,$(GO_PACKAGES)); do \
101102
${DEV_ENV_CMD} golint $$i; \
102103
done

cli/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cli
22

3+
// Shortcuts is a map of all the shortcuts supported by the CLI
34
var Shortcuts = map[string]string{
45
"create": "apps:create",
56
"destroy": "apps:destroy",

cmd/apps_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ type expandURLCases struct {
2424

2525
func TestExpandUrl(t *testing.T) {
2626
checks := []expandURLCases{
27-
expandURLCases{
27+
{
2828
Input: "test.com",
2929
Expected: "test.com",
3030
},
31-
expandURLCases{
31+
{
3232
Input: "test",
3333
Expected: "test.foo.com",
3434
},

cmd/keys_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,19 @@ type chooseKeyCases struct {
132132

133133
func TestChooseKey(t *testing.T) {
134134
testKeys := []api.KeyCreateRequest{
135-
api.KeyCreateRequest{},
135+
{},
136136
}
137137

138138
checks := []chooseKeyCases{
139-
chooseKeyCases{
139+
{
140140
Reader: strings.NewReader("-1"),
141141
Expected: "-1 is not a valid option",
142142
},
143-
chooseKeyCases{
143+
{
144144
Reader: strings.NewReader("2"),
145145
Expected: "2 is not a valid option",
146146
},
147-
chooseKeyCases{
147+
{
148148
Reader: strings.NewReader("a"),
149149
Expected: "a is not a valid integer",
150150
},

cmd/ps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func parseType(target string, appID string) (string, string) {
133133
psType, psName := "", ""
134134

135135
if strings.Contains(target, "-") {
136-
replaced := strings.Replace(target, appID + "-", "", 1)
136+
replaced := strings.Replace(target, appID+"-", "", 1)
137137
parts := strings.Split(replaced, "-")
138138
// the API requires the type, for now
139139
// regex matches against how Deployment pod name is constructed

cmd/shortcuts_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package cmd
22

33
import (
4-
"testing"
4+
"testing"
55
)
66

7-
87
func TestShortcutsList(t *testing.T) {
98
t.Parallel()
109

11-
expected := `create -> apps:create
10+
expected := `create -> apps:create
1211
destroy -> apps:destroy
1312
info -> apps:info
1413
login -> auth:login
@@ -27,9 +26,9 @@ sharing:list -> perms:list
2726
sharing:remove -> perms:delete
2827
whoami -> auth:whoami
2928
`
30-
actual := sortShortcuts()
31-
if actual != expected {
32-
t.Errorf("Expected %s, Got %s", expected, actual)
33-
}
29+
actual := sortShortcuts()
30+
if actual != expected {
31+
t.Errorf("Expected %s, Got %s", expected, actual)
32+
}
3433

3534
}

0 commit comments

Comments
 (0)