2013-08-30 20:03:55 -04:00
|
|
|
package packer
|
|
|
|
|
2019-03-22 09:50:33 -04:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2013-08-30 20:03:55 -04:00
|
|
|
// MockHook is an implementation of Hook that can be used for tests.
|
|
|
|
type MockHook struct {
|
2019-03-27 07:29:09 -04:00
|
|
|
RunFunc func(context.Context) error
|
2013-08-31 02:10:16 -04:00
|
|
|
|
2019-03-27 07:29:09 -04:00
|
|
|
RunCalled bool
|
|
|
|
RunComm Communicator
|
|
|
|
RunData interface{}
|
|
|
|
RunName string
|
|
|
|
RunUi Ui
|
2013-08-30 20:03:55 -04:00
|
|
|
}
|
|
|
|
|
2019-03-22 09:50:33 -04:00
|
|
|
func (t *MockHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error {
|
|
|
|
|
2013-08-30 20:03:55 -04:00
|
|
|
t.RunCalled = true
|
|
|
|
t.RunComm = comm
|
|
|
|
t.RunData = data
|
|
|
|
t.RunName = name
|
|
|
|
t.RunUi = ui
|
2013-08-31 02:10:16 -04:00
|
|
|
|
|
|
|
if t.RunFunc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-27 07:29:09 -04:00
|
|
|
return t.RunFunc(ctx)
|
2013-08-30 20:03:55 -04:00
|
|
|
}
|