diff --git a/command/command_test.go b/command/command_test.go index d931d7708..a4505c611 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -22,13 +22,6 @@ func fatalCommand(t *testing.T, m Meta) { err.String()) } -func outputCommand(t *testing.T, m Meta) (string, string) { - ui := m.Ui.(*packersdk.BasicUi) - out := ui.Writer.(*bytes.Buffer) - err := ui.ErrorWriter.(*bytes.Buffer) - return out.String(), err.String() -} - func testFixtureContent(n ...string) string { path := filepath.Join(append([]string{fixturesDir}, n...)...) b, err := ioutil.ReadFile(path) diff --git a/command/test_utils.go b/command/test_utils.go index ab901bef9..9ad5f6111 100644 --- a/command/test_utils.go +++ b/command/test_utils.go @@ -32,6 +32,14 @@ func TestMetaFile(t *testing.T) Meta { } } +// GetStdoutAndErrFromTestMeta extracts stdout/stderr from a Meta created by TestMetaFile +func GetStdoutAndErrFromTestMeta(t *testing.T, m Meta) (string, string) { + ui := m.Ui.(*packersdk.BasicUi) + out := ui.Writer.(*bytes.Buffer) + err := ui.ErrorWriter.(*bytes.Buffer) + return out.String(), err.String() +} + // testCoreConfigBuilder creates a packer CoreConfig that has a file builder // available. This allows us to test a builder that writes files to disk. func testCoreConfigBuilder(t *testing.T) *packer.CoreConfig { diff --git a/command/validate_test.go b/command/validate_test.go index 051b9c3ee..eb63d7306 100644 --- a/command/validate_test.go +++ b/command/validate_test.go @@ -137,7 +137,7 @@ func TestValidateCommandBadVersion(t *testing.T) { t.Errorf("Expected exit code 1") } - stdout, stderr := outputCommand(t, c.Meta) + stdout, stderr := GetStdoutAndErrFromTestMeta(t, c.Meta) expected := `Error: This template requires Packer version 101.0.0 or higher; using 100.0.0