Use require.EqualError instead of require.Error.

The type signatures of these methods make them easy to mix up. `require.Error()` asserts that there is any non-nil error -- the last parameter is an optional human-readable message to log when the assertion fails. `require.EqualError()` asserts that there is a non-nil error _and_ that when you call `err.Error()`, the string matches the expected value. It also takes an additional optional parameter to specify the log message.

Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
Matt Moyer 2020-07-28 08:47:11 -05:00
parent ebe39c8663
commit 0ee4f0417d

View File

@ -50,7 +50,7 @@ func TestRun(t *testing.T) {
"PLACEHOLDER_NAME_CA_BUNDLE": "b",
}
err := run(envGetter, tokenExchanger, buffer)
require.Error(t, err, "failed to login: environment variable not set: PLACEHOLDER_NAME_TOKEN")
require.EqualError(t, err, "failed to login: environment variable not set: PLACEHOLDER_NAME_TOKEN")
})
it("returns an error when PLACEHOLDER_NAME_CA_BUNDLE is missing", func() {
@ -59,7 +59,7 @@ func TestRun(t *testing.T) {
"PLACEHOLDER_NAME_TOKEN": "b",
}
err := run(envGetter, tokenExchanger, buffer)
require.Error(t, err, "failed to login: environment variable not set: PLACEHOLDER_NAME_CA_BUNDLE")
require.EqualError(t, err, "failed to login: environment variable not set: PLACEHOLDER_NAME_CA_BUNDLE")
})
it("returns an error when PLACEHOLDER_NAME_K8S_API_ENDPOINT is missing", func() {
@ -68,7 +68,7 @@ func TestRun(t *testing.T) {
"PLACEHOLDER_NAME_CA_BUNDLE": "b",
}
err := run(envGetter, tokenExchanger, buffer)
require.Error(t, err, "failed to login: environment variable not set: PLACEHOLDER_NAME_K8S_API_ENDPOINT")
require.EqualError(t, err, "failed to login: environment variable not set: PLACEHOLDER_NAME_K8S_API_ENDPOINT")
})
}, spec.Parallel())
@ -81,7 +81,7 @@ func TestRun(t *testing.T) {
it("returns an error", func() {
err := run(envGetter, tokenExchanger, buffer)
require.Error(t, err, "failed to login: some error")
require.EqualError(t, err, "failed to login: some error")
})
}, spec.Parallel())