packer-cn/packer/hook_mock.go

42 lines
673 B
Go
Raw Normal View History

2013-08-30 20:03:55 -04:00
package packer
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
}
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
}