test: add generic gadget for testing

When writing tests, one may need to write a one-off checker for a
packer command that ran, without having to completely implement the
Checker interface.

This commit introduces a generic CustomChecker implementation (i.e. a
function) that can be one-off implemented by developers if their test
doesn't fit the existing gadgets, and the need is not generic/reusable
enough to justify introducing a new gadget for other users.
pull/13032/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 829b942206
commit 75e4a47686

@ -132,3 +132,20 @@ func (_ PanicCheck) Check(stdout, stderr string, _ error) error {
}
return nil
}
// CustomCheck is meant to be a one-off checker with a user-provided function.
//
// Use this if none of the existing checkers match your use case, and it is not
// reusable/generic enough for use in other tests.
type CustomCheck struct {
name string
checkFunc func(stdout, stderr string, err error) error
}
func (c CustomCheck) Check(stdout, stderr string, err error) error {
return c.checkFunc(stdout, stderr, err)
}
func (c CustomCheck) Name() string {
return fmt.Sprintf("custom check - %s", c.name)
}

Loading…
Cancel
Save