2013-08-30 20:03:55 -04:00
|
|
|
package packer
|
|
|
|
|
2019-03-22 09:50:33 -04:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2013-08-30 20:03:55 -04:00
|
|
|
// MockHook is an implementation of Hook that can be used for tests.
|
|
|
|
type MockHook struct {
|
2013-08-31 02:10:16 -04:00
|
|
|
RunFunc func() error
|
|
|
|
|
2013-08-30 20:03:55 -04:00
|
|
|
RunCalled bool
|
|
|
|
RunComm Communicator
|
|
|
|
RunData interface{}
|
|
|
|
RunName string
|
|
|
|
RunUi Ui
|
|
|
|
CancelCalled bool
|
|
|
|
}
|
|
|
|
|
2019-03-22 09:50:33 -04:00
|
|
|
func (t *MockHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error {
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
select {
|
|
|
|
case <-time.After(2 * time.Minute):
|
|
|
|
case <-ctx.Done():
|
|
|
|
t.CancelCalled = true
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
return t.RunFunc()
|
2013-08-30 20:03:55 -04:00
|
|
|
}
|