common: add DumpCommand check to packerCommand

In addition to dumping the results of a command, we also now dump the
command itself, so we know exactly which command was invoked to produce
the result we got.
packer_test_dump_commands
Lucas Bajolet 1 year ago
parent 3289540c90
commit 7e1ddca0ec

@ -195,6 +195,20 @@ func (d dump) Check(stdout, stderr string, err error) error {
return nil
}
func DumpCommand(t *testing.T, command string) Checker {
return &dumpCommand{t, command}
}
type dumpCommand struct {
t *testing.T
command string
}
func (d dumpCommand) Check(_, _ string, _ error) error {
d.t.Logf("ran command %s", d.command)
return nil
}
type PanicCheck struct{}
func (_ PanicCheck) Check(stdout, stderr string, _ error) error {

@ -135,6 +135,17 @@ func (pc *packerCommand) Dump() *packerCommand {
return pc
}
func (pc *packerCommand) commandString() string {
buf := &strings.Builder{}
fmt.Fprintf(buf, "%q", pc.packerPath)
for _, arg := range pc.args {
fmt.Fprintf(buf, " %q", arg)
}
return buf.String()
}
// Run executes the packer command with the args/env requested and returns the
// output streams (stdout, stderr)
//
@ -194,6 +205,7 @@ func (pc *packerCommand) Output() (string, string, error) {
func (pc *packerCommand) Assert(checks ...check.Checker) {
if pc.dump {
tmpChecks := []check.Checker{
check.DumpCommand(pc.t, pc.commandString()),
check.Dump(pc.t),
}

Loading…
Cancel
Save