Skip to content

Commit 397267a

Browse files
fix(fmt): make fmt fail style-test and fix existing formatting errors (#35)
1 parent e686064 commit 397267a

6 files changed

Lines changed: 42 additions & 45 deletions

File tree

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DEV_ENV_CMD := ${DEV_ENV_PREFIX} ${DEV_ENV_IMAGE}
1212
GO_FILES = $(wildcard *.go)
1313
GO_PACKAGES = api apps auth builds certs config domains keys perms ps releases users pkg/time
1414
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
15-
GOFMT = gofmt -e -l -s
15+
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;
1616
GOTEST = go test --cover --race -v
1717

1818
bootstrap:
@@ -29,7 +29,8 @@ setup-gotools:
2929
test: test-style test-unit
3030

3131
test-style:
32-
${DEV_ENV_CMD} sh -c '${GOFMT} ${GO_FILES} ${GO_PACKAGES} && go vet $(repo_path) $(GO_PACKAGES_REPO_PATH)'
32+
${DEV_ENV_CMD} bash -c '${GOFMT}'
33+
${DEV_ENV_CMD} sh -c 'go vet $(repo_path) $(GO_PACKAGES_REPO_PATH)'
3334
@for i in $(addsuffix /...,$(GO_PACKAGES)); do \
3435
${DEV_ENV_CMD} golint $$i; \
3536
done

api/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ TCP Socket Probe: {{or .TCPSocket "N/A"}}`)
7474
if err != nil {
7575
panic(err)
7676
}
77-
err = tmpl.Execute(&doc, h)
78-
if err != nil {
77+
if err := tmpl.Execute(&doc, h); err != nil {
7978
panic(err)
8079
}
8180
return doc.String()

api/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ TCP Socket Probe: N/A`)
2222
}
2323

2424
h.HTTPGet = &HTTPGetProbe{
25-
Path: "/",
26-
Port: 80,
27-
HTTPHeaders: []*KVPair{{ Key: "X-DEIS-IS", Value: "AWESOME" }},
25+
Path: "/",
26+
Port: 80,
27+
HTTPHeaders: []*KVPair{{Key: "X-DEIS-IS", Value: "AWESOME"}},
2828
}
2929

3030
expected = strings.TrimSpace(`Initial Delay (seconds): 0

errors_test.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,218 +48,218 @@ type errorTest struct {
4848

4949
func TestErrors(t *testing.T) {
5050
tests := []errorTest{
51-
errorTest{
51+
{
5252
res: &http.Response{
5353
StatusCode: 200,
5454
Body: readCloser(""),
5555
},
5656
expected: nil,
5757
},
58-
errorTest{
58+
{
5959
res: &http.Response{
6060
StatusCode: 201,
6161
Body: readCloser(""),
6262
},
6363
expected: nil,
6464
},
65-
errorTest{
65+
{
6666
res: &http.Response{
6767
StatusCode: 400,
6868
Body: readCloser(`{"username":["This field is required."]}`),
6969
},
7070
expected: ErrInvalidUsername,
7171
},
72-
errorTest{
72+
{
7373
res: &http.Response{
7474
StatusCode: 400,
7575
Body: readCloser(`{"username":["Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters."]}`),
7676
},
7777
expected: ErrInvalidUsername,
7878
},
79-
errorTest{
79+
{
8080
res: &http.Response{
8181
StatusCode: 400,
8282
Body: readCloser(`{"username":["A user with that username already exists."]}`),
8383
},
8484
expected: ErrDuplicateUsername,
8585
},
86-
errorTest{
86+
{
8787
res: &http.Response{
8888
StatusCode: 400,
8989
Body: readCloser(`{"password":["This field is required."]}`),
9090
},
9191
expected: ErrMissingPassword,
9292
},
93-
errorTest{
93+
{
9494
res: &http.Response{
9595
StatusCode: 400,
9696
Body: readCloser(`{"non_field_errors":["Unable to log in with provided credentials."]}`),
9797
},
9898
expected: ErrLogin,
9999
},
100-
errorTest{
100+
{
101101
res: &http.Response{
102102
StatusCode: 400,
103103
Body: readCloser(`{"id":["App name can only contain a-z (lowercase), 0-9 and hyphens","Enter a valid \"slug\" consisting of letters, numbers, underscores or hyphens."]}`),
104104
},
105105
expected: ErrInvalidAppName,
106106
},
107-
errorTest{
107+
{
108108
res: &http.Response{
109109
StatusCode: 400,
110110
Body: readCloser(`{"id":["App with this id already exists."]}`),
111111
},
112112
expected: ErrDuplicateApp,
113113
},
114-
errorTest{
114+
{
115115
res: &http.Response{
116116
StatusCode: 400,
117117
Body: readCloser(`{"certificate": ["This field is required."]}`),
118118
},
119119
expected: ErrInvalidCertificate,
120120
},
121-
errorTest{
121+
{
122122
res: &http.Response{
123123
StatusCode: 400,
124124
Body: readCloser(`{"certificate":["Could not load certificate: [('PEM routines', 'PEM_read_bio', 'no start line')]"]}`),
125125
},
126126
expected: ErrInvalidCertificate,
127127
},
128-
errorTest{
128+
{
129129
res: &http.Response{
130130
StatusCode: 400,
131131
Body: readCloser(`{"key": ["This field is required."]}`),
132132
},
133133
expected: ErrMissingKey,
134134
},
135-
errorTest{
135+
{
136136
res: &http.Response{
137137
StatusCode: 400,
138138
Body: readCloser(`{"public":["Key contains invalid base64 chars"]}`),
139139
},
140140
expected: ErrMissingKey,
141141
},
142-
errorTest{
142+
{
143143
res: &http.Response{
144144
StatusCode: 400,
145145
Body: readCloser(`{"public":["This field is required."]}`),
146146
},
147147
expected: ErrMissingKey,
148148
},
149-
errorTest{
149+
{
150150
res: &http.Response{
151151
StatusCode: 400,
152152
Body: readCloser(`{"name": ["This field is required."]}`),
153153
},
154154
expected: ErrInvalidName,
155155
},
156-
errorTest{
156+
{
157157
res: &http.Response{
158158
StatusCode: 400,
159159
Body: readCloser(`{"name":["Can only contain a-z (lowercase), 0-9 and hyphens"]}`),
160160
},
161161
expected: ErrInvalidName,
162162
},
163-
errorTest{
163+
{
164164
res: &http.Response{
165165
StatusCode: 400,
166166
Body: readCloser(`{"detail":"Container type foo does not exist in application"}`),
167167
},
168168
expected: ErrPodNotFound,
169169
},
170-
errorTest{
170+
{
171171
res: &http.Response{
172172
StatusCode: 400,
173173
Body: readCloser(`{"domain":["Hostname does not look valid."]}`),
174174
},
175175
expected: ErrInvalidDomain,
176176
},
177-
errorTest{
177+
{
178178
res: &http.Response{
179179
StatusCode: 400,
180180
Body: readCloser(`{"image":["This field is required."]}`),
181181
},
182182
expected: ErrInvalidImage,
183183
},
184-
errorTest{
184+
{
185185
res: &http.Response{
186186
StatusCode: 400,
187187
Body: readCloser(`{"detail":"version cannot be below 0"}`),
188188
},
189189
expected: ErrInvalidVersion,
190190
},
191-
errorTest{
191+
{
192192
res: &http.Response{
193193
StatusCode: 400,
194194
Body: readCloser(`{"id":["This field is required."]}`),
195195
},
196196
expected: ErrMissingID,
197197
},
198-
errorTest{
198+
{
199199
res: &http.Response{
200200
StatusCode: 400,
201201
Body: readCloser(`{"email":["Enter a valid email address."]}`),
202202
},
203203
expected: ErrInvalidEmail,
204204
},
205-
errorTest{
205+
{
206206
res: &http.Response{
207207
StatusCode: 400,
208208
Body: readCloser(`{"detail":"No nodes matched the provided labels: foo=bar"}`),
209209
},
210210
expected: ErrTagNotFound,
211211
},
212-
errorTest{
212+
{
213213
res: &http.Response{
214214
StatusCode: 401,
215215
Body: readCloser(""),
216216
},
217217
expected: ErrUnauthorized,
218218
},
219-
errorTest{
219+
{
220220
res: &http.Response{
221221
StatusCode: 403,
222222
Body: readCloser(""),
223223
},
224224
expected: ErrForbidden,
225225
},
226-
errorTest{
226+
{
227227
res: &http.Response{
228228
StatusCode: 404,
229229
Body: readCloser(""),
230230
},
231231
expected: ErrNotFound,
232232
},
233-
errorTest{
233+
{
234234
res: &http.Response{
235235
StatusCode: 405,
236236
Body: readCloser(""),
237237
},
238238
expected: ErrMethodNotAllowed,
239239
},
240-
errorTest{
240+
{
241241
res: &http.Response{
242242
StatusCode: 409,
243243
Body: readCloser(""),
244244
},
245245
expected: ErrConflict,
246246
},
247-
errorTest{
247+
{
248248
res: &http.Response{
249249
StatusCode: 422,
250250
Body: readCloser(""),
251251
},
252252
expected: ErrUnprocessable,
253253
},
254-
errorTest{
254+
{
255255
res: &http.Response{
256256
StatusCode: 500,
257257
Body: readCloser(""),
258258
},
259259
expected: ErrServerError,
260260
},
261261
// ensure unknown errors at least look pretty
262-
errorTest{
262+
{
263263
res: &http.Response{
264264
StatusCode: 400,
265265
Body: readCloser(`{"detail":"unknown error"}`),

pkg/time/time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "time"
55
// DeisDatetimeFormat is the standard date/time representation used in Deis.
66
const DeisDatetimeFormat = "2006-01-02T15:04:05MST"
77

8-
// Different format to deal with the pyopenssl formatting
8+
// PyOpenSSLTimeDateTimeFormat is a different date format to deal with the pyopenssl formatting
99
// http://www.pyopenssl.org/en/stable/api/crypto.html#OpenSSL.crypto.X509.get_notAfter
1010
const PyOpenSSLTimeDateTimeFormat = "2006-01-02T15:04:05"
1111

pkg/time/time_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package time
22

3-
import (
4-
"fmt"
5-
"testing"
6-
)
3+
import "testing"
74

85
func TestUnMarshalText(t *testing.T) {
96
dummyTime := Time{}
@@ -19,7 +16,7 @@ func TestUnMarshalText(t *testing.T) {
1916
t.Error("expected " + goodTime + " to be marshal-able.")
2017
}
2118
if dummyTime.Year() != 2006 {
22-
t.Error(fmt.Sprintf("expected year to be 2006; got %d.", dummyTime.Year()))
19+
t.Errorf("expected year to be 2006; got %d.", dummyTime.Year())
2320
}
2421
}
2522

@@ -34,7 +31,7 @@ func TestUnMarshalText(t *testing.T) {
3431
t.Error("expected " + goodTime + " to be marshal-able.")
3532
}
3633
if dummyTime.Year() != 2007 {
37-
t.Error(fmt.Sprintf("expected year to be 2007; got %d.", dummyTime.Year()))
34+
t.Errorf("expected year to be 2007; got %d.", dummyTime.Year())
3835
}
3936
}
4037

0 commit comments

Comments
 (0)