Skip to content

Commit 403dafa

Browse files
geekJustin Reagor
authored andcommitted
cleanup test assert.Equal argument order
1 parent 9397e9f commit 403dafa

6 files changed

Lines changed: 86 additions & 86 deletions

File tree

config/services/ips_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ func getLocalhostIfaceName() string {
4646
func TestGetIp(t *testing.T) {
4747

4848
ip, _ := GetIP([]string{lo, "inet"})
49-
assert.Equal(t, ip, "127.0.0.1", "expected to find loopback IP")
49+
assert.Equal(t, "127.0.0.1", ip, "expected to find loopback IP")
5050

5151
ip, err := GetIP([]string{"interface-does-not-exist"})
5252
assert.Error(t, err, "expected interface not found, but instead got an IP")
5353

5454
ip, _ = GetIP([]string{"static:192.168.1.100", lo})
55-
assert.Equal(t, ip, "192.168.1.100", "expected to find static IP")
55+
assert.Equal(t, "192.168.1.100", ip, "expected to find static IP")
5656

5757
// these tests can't pass if the test runner doesn't have a valid inet
5858
// address, so we'll skip these tests in that environment.

config/template/template_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99

1010
func TestParseEnvironment(t *testing.T) {
1111
parsed := parseEnvironment([]string{})
12-
assert.Equal(t, parsed, Environment{})
12+
assert.Equal(t, Environment{}, parsed)
1313

1414
parsed = parseEnvironment([]string{
1515
"VAR1=test",
1616
"VAR2=test2",
1717
})
18-
assert.Equal(t, parsed, Environment{
18+
assert.Equal(t, Environment{
1919
"VAR1": "test",
2020
"VAR2": "test2",
21-
})
21+
}, parsed)
2222
}
2323

2424
func TestTemplate(t *testing.T) {

control/control_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestValidate(t *testing.T) {
6464
Addr: "",
6565
}
6666
if err := srv.Validate(); assert.NotNil(t, err) {
67-
assert.Equal(t, err, ErrMissingAddr, "expected missing addr error")
67+
assert.Equal(t, ErrMissingAddr, err, "expected missing addr error")
6868
}
6969

7070
socketPath := tempSocketPath()

control/endpoints_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,32 @@ func TestPutEnviron(t *testing.T) {
2828

2929
t.Run("POST value", func(t *testing.T) {
3030
status, result := testFunc(t, fmt.Sprintf("{\"%s\": \"updated\"}\n", t.Name()))
31-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
32-
assert.Equal(t, result, "updated", "env var was not updated")
31+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
32+
assert.Equal(t, "updated", result, "env var was not updated")
3333
})
3434

3535
t.Run("POST empty", func(t *testing.T) {
3636
status, result := testFunc(t, fmt.Sprintf("{\"%s\": \"\"}\n", t.Name()))
37-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
38-
assert.Equal(t, result, "", "env var should be cleared")
37+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
38+
assert.Equal(t, "", result, "env var should be cleared")
3939
})
4040

4141
t.Run("POST null", func(t *testing.T) {
4242
status, result := testFunc(t, fmt.Sprintf("{\"%s\": null}\n", t.Name()))
43-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
44-
assert.Equal(t, result, "", "env var should be cleared")
43+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
44+
assert.Equal(t, "", result, "env var should be cleared")
4545
})
4646

4747
t.Run("POST string null", func(t *testing.T) {
4848
status, result := testFunc(t, fmt.Sprintf("{\"%s\": \"null\"}\n", t.Name()))
49-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
50-
assert.Equal(t, result, "null", "env var should not be cleared")
49+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
50+
assert.Equal(t, "null", result, "env var should not be cleared")
5151
})
5252

5353
t.Run("POST bad JSON", func(t *testing.T) {
5454
status, result := testFunc(t, "{{\n")
55-
assert.Equal(t, status, http.StatusUnprocessableEntity, "status was not 422")
56-
assert.Equal(t, result, "original", "env var should not be updated")
55+
assert.Equal(t, http.StatusUnprocessableEntity, status, "status was not 422")
56+
assert.Equal(t, "original", result, "env var should not be updated")
5757
})
5858
}
5959

@@ -76,17 +76,17 @@ func TestPostHandler(t *testing.T) {
7676
func(r *http.Request) (interface{}, int) {
7777
return nil, 200
7878
})
79-
assert.Equal(t, status, 200, "expected HTTP 200 OK")
80-
assert.Equal(t, result, "\n")
79+
assert.Equal(t, 200, status, "expected HTTP 200 OK")
80+
assert.Equal(t, "\n", result)
8181
})
8282

8383
t.Run("POST JSON ok", func(t *testing.T) {
8484
req := httptest.NewRequest("POST", "/v3/foo", nil)
8585
status, result := testFunc(req, func(r *http.Request) (interface{}, int) {
8686
return map[string]string{"key": "val"}, 200
8787
})
88-
assert.Equal(t, status, 200, "expected HTTP 200 OK")
89-
assert.Equal(t, result, "{\"key\":\"val\"}\n",
88+
assert.Equal(t, 200, status, "expected HTTP 200 OK")
89+
assert.Equal(t, "{\"key\":\"val\"}\n", result,
9090
"expected JSON body in reply")
9191
})
9292

@@ -96,8 +96,8 @@ func TestPostHandler(t *testing.T) {
9696
func(r *http.Request) (interface{}, int) {
9797
return nil, 200
9898
})
99-
assert.Equal(t, status, 405, "expected HTTP405 method not allowed")
100-
assert.Equal(t, result, "Method Not Allowed\n")
99+
assert.Equal(t, 405, status, "expected HTTP405 method not allowed")
100+
assert.Equal(t, "Method Not Allowed\n", result)
101101
})
102102
}
103103

@@ -123,21 +123,21 @@ func TestPostMetric(t *testing.T) {
123123
body := "{{\n"
124124
expected := map[events.Event]int{}
125125
status := testFunc(t, expected, body)
126-
assert.Equal(t, status, http.StatusUnprocessableEntity, "status was not 422")
126+
assert.Equal(t, http.StatusUnprocessableEntity, status, "status was not 422")
127127
})
128128
t.Run("POST value", func(t *testing.T) {
129129
body := "{\"mymetric\": 1.0}"
130130
expected := map[events.Event]int{{events.Metric, "mymetric|1"}: 1}
131131
status := testFunc(t, expected, body)
132-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
132+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
133133
})
134134
t.Run("POST multi-metric", func(t *testing.T) {
135135
body := "{\"mymetric\": 1.5, \"myothermetric\": 2}"
136136
status := testFunc(t, map[events.Event]int{
137137
{events.Metric, "mymetric|1.5"}: 1,
138138
{events.Metric, "myothermetric|2"}: 1,
139139
}, body)
140-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
140+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
141141
})
142142
}
143143

@@ -164,13 +164,13 @@ func TestPostEnableMaintenanceMode(t *testing.T) {
164164
req, _ := http.NewRequest("POST", "/v3/maintenance/enable", strings.NewReader(body))
165165
expected := map[events.Event]int{events.GlobalEnterMaintenance: 1}
166166
status := testFunc(t, expected, req)
167-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
167+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
168168
})
169169
t.Run("POST disable", func(t *testing.T) {
170170
req, _ := http.NewRequest("POST", "/v3/maintenance/enable", nil)
171171
expected := map[events.Event]int{events.GlobalEnterMaintenance: 1}
172172
status := testFunc(t, expected, req)
173-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
173+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
174174
})
175175
}
176176

@@ -197,13 +197,13 @@ func TestPostDisableMaintenanceMode(t *testing.T) {
197197
req, _ := http.NewRequest("POST", "/v3/maintenance/disable", strings.NewReader(body))
198198
expected := map[events.Event]int{events.GlobalExitMaintenance: 1}
199199
status := testFunc(t, expected, req)
200-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
200+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
201201
})
202202
t.Run("POST disable", func(t *testing.T) {
203203
req, _ := http.NewRequest("POST", "/v3/maintenance/disable", nil)
204204
expected := map[events.Event]int{events.GlobalExitMaintenance: 1}
205205
status := testFunc(t, expected, req)
206-
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
206+
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
207207
})
208208
}
209209

@@ -214,5 +214,5 @@ func TestGetPing(t *testing.T) {
214214
resp := w.Result()
215215
defer resp.Body.Close()
216216
status := resp.StatusCode
217-
assert.Equal(t, status, 200, "expected HTTP 200 OK")
217+
assert.Equal(t, 200, status, "expected HTTP 200 OK")
218218
}

0 commit comments

Comments
 (0)