Skip to content

Commit

Permalink
cleanup test assert.Equal argument order
Browse files Browse the repository at this point in the history
  • Loading branch information
geek authored and jwreagor committed Sep 20, 2017
1 parent 9397e9f commit 403dafa
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 86 deletions.
4 changes: 2 additions & 2 deletions config/services/ips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func getLocalhostIfaceName() string {
func TestGetIp(t *testing.T) {

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

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

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

// these tests can't pass if the test runner doesn't have a valid inet
// address, so we'll skip these tests in that environment.
Expand Down
6 changes: 3 additions & 3 deletions config/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (

func TestParseEnvironment(t *testing.T) {
parsed := parseEnvironment([]string{})
assert.Equal(t, parsed, Environment{})
assert.Equal(t, Environment{}, parsed)

parsed = parseEnvironment([]string{
"VAR1=test",
"VAR2=test2",
})
assert.Equal(t, parsed, Environment{
assert.Equal(t, Environment{
"VAR1": "test",
"VAR2": "test2",
})
}, parsed)
}

func TestTemplate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestValidate(t *testing.T) {
Addr: "",
}
if err := srv.Validate(); assert.NotNil(t, err) {
assert.Equal(t, err, ErrMissingAddr, "expected missing addr error")
assert.Equal(t, ErrMissingAddr, err, "expected missing addr error")
}

socketPath := tempSocketPath()
Expand Down
48 changes: 24 additions & 24 deletions control/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ func TestPutEnviron(t *testing.T) {

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

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

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

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

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

Expand All @@ -76,17 +76,17 @@ func TestPostHandler(t *testing.T) {
func(r *http.Request) (interface{}, int) {
return nil, 200
})
assert.Equal(t, status, 200, "expected HTTP 200 OK")
assert.Equal(t, result, "\n")
assert.Equal(t, 200, status, "expected HTTP 200 OK")
assert.Equal(t, "\n", result)
})

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

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

Expand All @@ -123,21 +123,21 @@ func TestPostMetric(t *testing.T) {
body := "{{\n"
expected := map[events.Event]int{}
status := testFunc(t, expected, body)
assert.Equal(t, status, http.StatusUnprocessableEntity, "status was not 422")
assert.Equal(t, http.StatusUnprocessableEntity, status, "status was not 422")
})
t.Run("POST value", func(t *testing.T) {
body := "{\"mymetric\": 1.0}"
expected := map[events.Event]int{{events.Metric, "mymetric|1"}: 1}
status := testFunc(t, expected, body)
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
})
t.Run("POST multi-metric", func(t *testing.T) {
body := "{\"mymetric\": 1.5, \"myothermetric\": 2}"
status := testFunc(t, map[events.Event]int{
{events.Metric, "mymetric|1.5"}: 1,
{events.Metric, "myothermetric|2"}: 1,
}, body)
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
})
}

Expand All @@ -164,13 +164,13 @@ func TestPostEnableMaintenanceMode(t *testing.T) {
req, _ := http.NewRequest("POST", "/v3/maintenance/enable", strings.NewReader(body))
expected := map[events.Event]int{events.GlobalEnterMaintenance: 1}
status := testFunc(t, expected, req)
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
})
t.Run("POST disable", func(t *testing.T) {
req, _ := http.NewRequest("POST", "/v3/maintenance/enable", nil)
expected := map[events.Event]int{events.GlobalEnterMaintenance: 1}
status := testFunc(t, expected, req)
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
})
}

Expand All @@ -197,13 +197,13 @@ func TestPostDisableMaintenanceMode(t *testing.T) {
req, _ := http.NewRequest("POST", "/v3/maintenance/disable", strings.NewReader(body))
expected := map[events.Event]int{events.GlobalExitMaintenance: 1}
status := testFunc(t, expected, req)
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
})
t.Run("POST disable", func(t *testing.T) {
req, _ := http.NewRequest("POST", "/v3/maintenance/disable", nil)
expected := map[events.Event]int{events.GlobalExitMaintenance: 1}
status := testFunc(t, expected, req)
assert.Equal(t, status, http.StatusOK, "status was not 200OK")
assert.Equal(t, http.StatusOK, status, "status was not 200OK")
})
}

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

0 comments on commit 403dafa

Please sign in to comment.