From 76787d4dd0827568e879fcf291049a1d3c5e002a Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 21 Dec 2020 18:11:19 -0500 Subject: [PATCH] Fix error checking There were two identical if lines, remove one and use a switch/case so the compiler can catch this problem. --- agent/config/runtime_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index deacdfb37a..6457f2afd9 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -4923,16 +4923,12 @@ func testConfig(t *testing.T, tests []testCase, dataDir string) { } actual, err := b.BuildAndValidate() - if err == nil && tt.err != "" { - t.Fatalf("got no error want %q", tt.err) - } - if err != nil && tt.err == "" { - t.Fatalf("got error %s want nil", err) - } - if err == nil && tt.err != "" { + switch { + case err == nil && tt.err != "": t.Fatalf("got nil want error to contain %q", tt.err) - } - if err != nil && tt.err != "" && !strings.Contains(err.Error(), tt.err) { + case err != nil && tt.err == "": + t.Fatalf("got error %s want nil", err) + case err != nil && tt.err != "" && !strings.Contains(err.Error(), tt.err): t.Fatalf("error %q does not contain %q", err.Error(), tt.err) } if tt.err != "" {