From 0ee4f0417dd26deb898970be43ade7e22d20fceb Mon Sep 17 00:00:00 2001 From: Matt Moyer Date: Tue, 28 Jul 2020 08:47:11 -0500 Subject: [PATCH] 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 --- cmd/placeholder-name/main_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/placeholder-name/main_test.go b/cmd/placeholder-name/main_test.go index 30adbe51..5a5eae33 100644 --- a/cmd/placeholder-name/main_test.go +++ b/cmd/placeholder-name/main_test.go @@ -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())