2013-08-31 02:21:15 -04:00
|
|
|
package packer
|
|
|
|
|
2019-03-19 13:11:19 -04:00
|
|
|
import "context"
|
|
|
|
|
2013-08-31 02:21:15 -04:00
|
|
|
// MockProvisioner is an implementation of Provisioner that can be
|
|
|
|
// used for tests.
|
|
|
|
type MockProvisioner struct {
|
2013-08-31 02:39:29 -04:00
|
|
|
ProvFunc func() error
|
|
|
|
|
2013-12-21 00:36:41 -05:00
|
|
|
PrepCalled bool
|
|
|
|
PrepConfigs []interface{}
|
|
|
|
ProvCalled bool
|
|
|
|
ProvCommunicator Communicator
|
|
|
|
ProvUi Ui
|
|
|
|
CancelCalled bool
|
2013-08-31 02:21:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *MockProvisioner) Prepare(configs ...interface{}) error {
|
2018-09-10 19:48:42 -04:00
|
|
|
t.PrepCalled = true
|
|
|
|
t.PrepConfigs = configs
|
2013-08-31 02:21:15 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-19 13:11:19 -04:00
|
|
|
func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator) error {
|
2013-08-31 02:21:15 -04:00
|
|
|
t.ProvCalled = true
|
2013-12-21 00:36:41 -05:00
|
|
|
t.ProvCommunicator = comm
|
2013-08-31 02:21:15 -04:00
|
|
|
t.ProvUi = ui
|
2013-08-31 02:39:29 -04:00
|
|
|
|
|
|
|
if t.ProvFunc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return t.ProvFunc()
|
2013-08-31 02:21:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *MockProvisioner) Cancel() {
|
|
|
|
t.CancelCalled = true
|
|
|
|
}
|
2018-12-07 11:23:03 -05:00
|
|
|
|
|
|
|
func (t *MockProvisioner) Communicator() Communicator {
|
|
|
|
return t.ProvCommunicator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *MockProvisioner) ElevatedUser() string {
|
|
|
|
return "user"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *MockProvisioner) ElevatedPassword() string {
|
|
|
|
return "password"
|
|
|
|
}
|