mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-27 10:14:01 -04:00
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.
This commit is contained in:
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user