github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/command/command_test.go (about) 1 package command 2 3 import ( 4 "bytes" 5 "path/filepath" 6 "testing" 7 8 "github.com/hashicorp/packer/packer" 9 ) 10 11 const fixturesDir = "./test-fixtures" 12 13 func fatalCommand(t *testing.T, m Meta) { 14 ui := m.Ui.(*packer.BasicUi) 15 out := ui.Writer.(*bytes.Buffer) 16 err := ui.ErrorWriter.(*bytes.Buffer) 17 t.Fatalf( 18 "Bad exit code.\n\nStdout:\n\n%s\n\nStderr:\n\n%s", 19 out.String(), 20 err.String()) 21 } 22 23 func outputCommand(t *testing.T, m Meta) (string, string) { 24 ui := m.Ui.(*packer.BasicUi) 25 out := ui.Writer.(*bytes.Buffer) 26 err := ui.ErrorWriter.(*bytes.Buffer) 27 return out.String(), err.String() 28 } 29 30 func testFixture(n string) string { 31 return filepath.Join(fixturesDir, n) 32 } 33 34 func testMeta(t *testing.T) Meta { 35 var out, err bytes.Buffer 36 37 return Meta{ 38 CoreConfig: packer.TestCoreConfig(t), 39 Ui: &packer.BasicUi{ 40 Writer: &out, 41 ErrorWriter: &err, 42 }, 43 } 44 }