mirror of
https://github.com/hashicorp/packer.git
synced 2026-10-11 08:51:40 -04:00
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.
This commit is contained in:
@@ -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),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user