packer_test: check for a panic during execution

When a command is run, it is the expectation that no test should make
Packer panic. If it did, something is wrong and Packer should be fixed
so it doesn't panic anymore in that situation.

The way we did the check before was adding a PanicCheck after the
command ran, so we could make sure of that during `Assert`.

However, since we introduced the possibility to have multiple runs,
having this addition as part of the run loop meant that the PanicCheck
would be run as many times as there were runs.

While this worked, this implied that we'd do the same check multiple
times on a single command output, which is not optimal.

Instead, this commit moves the check to within the `Run` function, this
way for each run of the command we do the check once, and then we can
assert the results of the command on what output it produced.
nywilken.document-tmpdir
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 36e43e30ee
commit 13c52124de

@ -138,6 +138,12 @@ func (pc *packerCommand) Run() (string, string, error) {
pc.err = cmd.Run()
// Check that the command didn't panic, and if it did, we can immediately error
panicErr := PanicCheck{}.Check(pc.stdout.String(), pc.stderr.String(), pc.err)
if panicErr != nil {
pc.t.Fatalf("Packer panicked during execution: %s", panicErr)
}
return pc.stdout.String(), pc.stderr.String(), pc.err
}
@ -147,8 +153,6 @@ func (pc *packerCommand) Assert(checks ...Checker) {
attempt++
stdout, stderr, err := pc.Run()
checks = append(checks, PanicCheck{})
for _, check := range checks {
checkErr := check.Check(stdout, stderr, err)
if checkErr != nil {

Loading…
Cancel
Save