2013-08-31 02:21:15 -04:00
|
|
|
package packer
|
|
|
|
|
2019-03-22 09:50:33 -04:00
|
|
|
import (
|
|
|
|
"context"
|
2019-12-17 05:25:56 -05:00
|
|
|
|
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2019-03-22 09:50:33 -04:00
|
|
|
)
|
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
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (tp *MockProvisioner) ConfigSpec() hcldec.ObjectSpec { return tp.FlatMapstructure().HCL2Spec() }
|
|
|
|
|
|
|
|
func (tp *MockProvisioner) FlatConfig() interface{} { return tp.FlatMapstructure() }
|
|
|
|
|
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-12-12 13:59:44 -05:00
|
|
|
func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) 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"
|
|
|
|
}
|