From fb810162522a1bd805c7e6a46cb0609bafd95912 Mon Sep 17 00:00:00 2001 From: Calvin Leung Huang Date: Thu, 5 Apr 2018 20:43:29 -0400 Subject: [PATCH] Fix output-related tests (#4288) * Fix command tests * More test fixes * Use backticks to escape quoted strings * More test fixes * Fix mismatched error output failures * Fix mismatched error output failures --- api/ssh_agent.go | 2 +- api/ssh_agent_test.go | 4 ++-- command/config/config_test.go | 2 +- command/config_test.go | 2 +- command/policy_fmt_test.go | 6 +++--- command/server/config_test.go | 12 ++++++------ vault/logical_system_test.go | 10 +++++----- vault/mount_test.go | 2 +- vault/policy_store_test.go | 4 ++-- vault/policy_test.go | 10 +++++----- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/api/ssh_agent.go b/api/ssh_agent.go index c4e59a471..0a0e8ddd5 100644 --- a/api/ssh_agent.go +++ b/api/ssh_agent.go @@ -171,7 +171,7 @@ func ParseSSHHelperConfig(contents string) (*SSHHelperConfig, error) { } if c.VaultAddr == "" { - return nil, fmt.Errorf("missing config 'vault_addr'") + return nil, fmt.Errorf(`missing config "vault_addr"`) } return &c, nil } diff --git a/api/ssh_agent_test.go b/api/ssh_agent_test.go index dfef4b84a..3ca5fdf2b 100644 --- a/api/ssh_agent_test.go +++ b/api/ssh_agent_test.go @@ -73,7 +73,7 @@ func TestParseSSHHelperConfig_missingVaultAddr(t *testing.T) { t.Fatal("expected error") } - if !strings.Contains(err.Error(), "ssh_helper: missing config 'vault_addr'") { + if !strings.Contains(err.Error(), `missing config "vault_addr"`) { t.Errorf("bad error: %s", err) } } @@ -87,7 +87,7 @@ nope = "bad" t.Fatal("expected error") } - if !strings.Contains(err.Error(), "ssh_helper: invalid key 'nope' on line 3") { + if !strings.Contains(err.Error(), `ssh_helper: invalid key "nope" on line 3`) { t.Errorf("bad error: %s", err) } } diff --git a/command/config/config_test.go b/command/config/config_test.go index 7ef38e4f5..b5d41361e 100644 --- a/command/config/config_test.go +++ b/command/config/config_test.go @@ -43,7 +43,7 @@ nope = "true" t.Fatal("expected error") } - if !strings.Contains(err.Error(), "invalid key 'nope' on line 3") { + if !strings.Contains(err.Error(), `invalid key "nope" on line 3`) { t.Errorf("bad error: %s", err.Error()) } } diff --git a/command/config_test.go b/command/config_test.go index edbf5579c..0ed34992f 100644 --- a/command/config_test.go +++ b/command/config_test.go @@ -43,7 +43,7 @@ nope = "true" t.Fatal("expected error") } - if !strings.Contains(err.Error(), "invalid key 'nope' on line 3") { + if !strings.Contains(err.Error(), `invalid key "nope" on line 3`) { t.Errorf("bad error: %s", err.Error()) } } diff --git a/command/policy_fmt_test.go b/command/policy_fmt_test.go index 53a99e15a..2ae92ff69 100644 --- a/command/policy_fmt_test.go +++ b/command/policy_fmt_test.go @@ -148,7 +148,7 @@ path "secret" { } stderr := ui.ErrorWriter.String() - expected := "Failed to parse policy" + expected := "failed to parse policy" if !strings.Contains(stderr, expected) { t.Errorf("expected %q to include %q", stderr, expected) } @@ -183,7 +183,7 @@ path "secret" { } stderr := ui.ErrorWriter.String() - expected := "Failed to parse policy" + expected := "failed to parse policy" if !strings.Contains(stderr, expected) { t.Errorf("expected %q to include %q", stderr, expected) } @@ -218,7 +218,7 @@ path "secret" { } stderr := ui.ErrorWriter.String() - expected := "Failed to parse policy" + expected := "failed to parse policy" if !strings.Contains(stderr, expected) { t.Errorf("expected %q to include %q", stderr, expected) } diff --git a/command/server/config_test.go b/command/server/config_test.go index e1bc2442b..829322450 100644 --- a/command/server/config_test.go +++ b/command/server/config_test.go @@ -395,11 +395,11 @@ nope = "yes" t.Fatal("expected error") } - if !strings.Contains(err.Error(), "invalid key 'bad' on line 2") { + if !strings.Contains(err.Error(), `invalid key "bad" on line 2`) { t.Errorf("bad error: %q", err) } - if !strings.Contains(err.Error(), "invalid key 'nope' on line 3") { + if !strings.Contains(err.Error(), `invalid key "nope" on line 3`) { t.Errorf("bad error: %q", err) } } @@ -419,11 +419,11 @@ listener "tcp" { t.Fatal("expected error") } - if !strings.Contains(err.Error(), "listeners.tcp: invalid key 'bad' on line 3") { + if !strings.Contains(err.Error(), `listeners.tcp: invalid key "bad" on line 3`) { t.Errorf("bad error: %q", err) } - if !strings.Contains(err.Error(), "listeners.tcp: invalid key 'nope' on line 4") { + if !strings.Contains(err.Error(), `listeners.tcp: invalid key "nope" on line 4`) { t.Errorf("bad error: %q", err) } } @@ -443,11 +443,11 @@ telemetry { t.Fatal("expected error") } - if !strings.Contains(err.Error(), "telemetry: invalid key 'bad' on line 3") { + if !strings.Contains(err.Error(), `telemetry: invalid key "bad" on line 3`) { t.Errorf("bad error: %q", err) } - if !strings.Contains(err.Error(), "telemetry: invalid key 'nope' on line 4") { + if !strings.Contains(err.Error(), `telemetry: invalid key "nope" on line 4`) { t.Errorf("bad error: %q", err) } } diff --git a/vault/logical_system_test.go b/vault/logical_system_test.go index b622bfb78..1028c47e0 100644 --- a/vault/logical_system_test.go +++ b/vault/logical_system_test.go @@ -331,7 +331,7 @@ func TestSystemBackend_mount_invalid(t *testing.T) { if err != logical.ErrInvalidRequest { t.Fatalf("err: %v", err) } - if resp.Data["error"] != "unknown backend type: nope" { + if resp.Data["error"] != `unknown backend type: "nope"` { t.Fatalf("bad: %v", resp) } } @@ -653,7 +653,7 @@ func TestSystemBackend_remount_invalid(t *testing.T) { if err != logical.ErrInvalidRequest { t.Fatalf("err: %v", err) } - if resp.Data["error"] != "no matching mount at 'unknown/'" { + if resp.Data["error"] != `no matching mount at "unknown/"` { t.Fatalf("bad: %v", resp) } } @@ -668,7 +668,7 @@ func TestSystemBackend_remount_system(t *testing.T) { if err != logical.ErrInvalidRequest { t.Fatalf("err: %v", err) } - if resp.Data["error"] != "cannot remount 'sys/'" { + if resp.Data["error"] != `cannot remount "sys/"` { t.Fatalf("bad: %v", resp) } } @@ -1493,7 +1493,7 @@ func TestSystemBackend_enableAuth_invalid(t *testing.T) { if err != logical.ErrInvalidRequest { t.Fatalf("err: %v", err) } - if resp.Data["error"] != "unknown backend type: nope" { + if resp.Data["error"] != `unknown backend type: "nope"` { t.Fatalf("bad: %v", resp) } } @@ -1710,7 +1710,7 @@ func TestSystemBackend_enableAudit_invalid(t *testing.T) { if err != logical.ErrInvalidRequest { t.Fatalf("err: %v", err) } - if resp.Data["error"] != "unknown backend type: nope" { + if resp.Data["error"] != `unknown backend type: "nope"` { t.Fatalf("bad: %v", resp) } } diff --git a/vault/mount_test.go b/vault/mount_test.go index fc0432fa4..87a0f9ed2 100644 --- a/vault/mount_test.go +++ b/vault/mount_test.go @@ -449,7 +449,7 @@ func TestCore_Remount_Cleanup(t *testing.T) { func TestCore_Remount_Protected(t *testing.T) { c, _, _ := TestCoreUnsealed(t) err := c.remount(context.Background(), "sys", "foo") - if err.Error() != "cannot remount 'sys/'" { + if err.Error() != `cannot remount "sys/"` { t.Fatalf("err: %v", err) } } diff --git a/vault/policy_store_test.go b/vault/policy_store_test.go index 24798e26a..68b96baa2 100644 --- a/vault/policy_store_test.go +++ b/vault/policy_store_test.go @@ -43,13 +43,13 @@ func TestPolicyStore_Root(t *testing.T) { // Set should fail err = ps.SetPolicy(context.Background(), p) - if err.Error() != "cannot update root policy" { + if err.Error() != `cannot update "root" policy` { t.Fatalf("err: %v", err) } // Delete should fail err = ps.DeletePolicy(context.Background(), "root", PolicyTypeACL) - if err.Error() != "cannot delete root policy" { + if err.Error() != `cannot delete "root" policy` { t.Fatalf("err: %v", err) } } diff --git a/vault/policy_test.go b/vault/policy_test.go index ce516486a..ba40af3df 100644 --- a/vault/policy_test.go +++ b/vault/policy_test.go @@ -259,11 +259,11 @@ nope = "yes" t.Fatalf("expected error") } - if !strings.Contains(err.Error(), "invalid key 'bad' on line 2") { + if !strings.Contains(err.Error(), `invalid key "bad" on line 2`) { t.Errorf("bad error: %q", err) } - if !strings.Contains(err.Error(), "invalid key 'nope' on line 3") { + if !strings.Contains(err.Error(), `invalid key "nope" on line 3`) { t.Errorf("bad error: %q", err) } } @@ -279,7 +279,7 @@ path "/" { t.Fatalf("expected error") } - if !strings.Contains(err.Error(), "invalid key 'capabilites' on line 3") { + if !strings.Contains(err.Error(), `invalid key "capabilites" on line 3`) { t.Errorf("bad error: %s", err) } } @@ -294,7 +294,7 @@ path "/" { t.Fatalf("expected error") } - if !strings.Contains(err.Error(), `path "/": invalid policy 'banana'`) { + if !strings.Contains(err.Error(), `path "/": invalid policy "banana"`) { t.Errorf("bad error: %s", err) } } @@ -326,7 +326,7 @@ path "/" { t.Fatalf("expected error") } - if !strings.Contains(err.Error(), `path "/": invalid capability 'banana'`) { + if !strings.Contains(err.Error(), `path "/": invalid capability "banana"`) { t.Errorf("bad error: %s", err) } }