From 7e9a653da7d565a51ee11e20c83e7b6f016fbd7c Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 21 May 2018 15:26:57 -0700 Subject: [PATCH] use testify instead of homegrown string compare --- .../shell-local/post-processor_test.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/post-processor/shell-local/post-processor_test.go b/post-processor/shell-local/post-processor_test.go index ee7e27d70..515704f9d 100644 --- a/post-processor/shell-local/post-processor_test.go +++ b/post-processor/shell-local/post-processor_test.go @@ -4,10 +4,10 @@ import ( "io/ioutil" "os" "runtime" - "strings" "testing" "github.com/hashicorp/packer/packer" + "github.com/stretchr/testify/assert" ) func TestPostProcessor_ImplementsPostProcessor(t *testing.T) { @@ -116,9 +116,8 @@ func TestPostProcessorPrepare_ExecuteCommand(t *testing.T) { if err != nil { t.Fatalf("should handle backwards compatibility: %s", err) } - if strings.Compare(strings.Join(p.config.ExecuteCommand, " "), strings.Join(expected, " ")) != 0 { - t.Fatalf("Did not get expected execute_command: expected: %#v; received %#v", expected, p.config.ExecuteCommand) - } + assert.Equal(t, p.config.ExecuteCommand, expected, + "Did not get expected execute_command: expected: %#v; received %#v", expected, p.config.ExecuteCommand) // Check that passing a list will work p = new(PostProcessor) @@ -129,9 +128,8 @@ func TestPostProcessorPrepare_ExecuteCommand(t *testing.T) { t.Fatalf("should handle backwards compatibility: %s", err) } expected = []string{"foo", "bar"} - if strings.Compare(strings.Join(p.config.ExecuteCommand, " "), strings.Join(expected, " ")) != 0 { - t.Fatalf("Did not get expected execute_command: expected: %#v; received %#v", expected, p.config.ExecuteCommand) - } + assert.Equal(t, p.config.ExecuteCommand, expected, + "Did not get expected execute_command: expected: %#v; received %#v", expected, p.config.ExecuteCommand) // Check that default is as expected raws = testConfig() @@ -139,13 +137,12 @@ func TestPostProcessorPrepare_ExecuteCommand(t *testing.T) { p = new(PostProcessor) p.Configure(raws) if runtime.GOOS != "windows" { - expected = []string{"/bin/sh", "-c", "{{.Vars}}", "{{.Script}}"} + expected = []string{"/bin/sh", "-c", "{{.Vars}} {{.Script}}"} } else { expected = []string{"cmd", "/V", "/C", "{{.Vars}}", "call", "{{.Script}}"} } - if strings.Compare(strings.Join(p.config.ExecuteCommand, " "), strings.Join(expected, " ")) != 0 { - t.Fatalf("Did not get expected default: expected: %#v; received %#v", expected, p.config.ExecuteCommand) - } + assert.Equal(t, p.config.ExecuteCommand, expected, + "Did not get expected default: expected: %#v; received %#v", expected, p.config.ExecuteCommand) } func TestPostProcessorPrepare_ScriptAndInline(t *testing.T) {