2013-08-31 02:21:15 -04:00
|
|
|
package packer
|
|
|
|
|
2019-03-22 09:50:33 -04:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
2019-03-19 13:11:19 -04:00
|
|
|
|
2013-08-31 02:21:15 -04:00
|
|
|
// MockProvisioner is an implementation of Provisioner that can be
|
|
|
|
// used for tests.
|
|
|
|
type MockProvisioner struct {
|
2019-03-27 07:29:09 -04:00
|
|
|
ProvFunc func(context.Context) error
|
2013-08-31 02:39:29 -04:00
|
|
|
|
2013-12-21 00:36:41 -05:00
|
|
|
PrepCalled bool
|
|
|
|
PrepConfigs []interface{}
|
|
|
|
ProvCalled bool
|
|
|
|
ProvCommunicator Communicator
|
|
|
|
ProvUi Ui
|
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
|
|
|
|
}
|
|
|
|
|
2019-03-27 07:29:09 -04:00
|
|
|
return t.ProvFunc(ctx)
|
2013-08-31 02:21:15 -04:00
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
}
|