2013-08-30 23:21:15 -07:00
|
|
|
package packer
|
|
|
|
|
2019-03-22 14:50:33 +01:00
|
|
|
import (
|
|
|
|
"context"
|
2019-12-17 11:25:56 +01:00
|
|
|
|
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2020-11-19 11:54:31 -08:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2019-03-22 14:50:33 +01:00
|
|
|
)
|
2019-03-19 18:11:19 +01:00
|
|
|
|
2013-08-30 23:21:15 -07:00
|
|
|
// MockProvisioner is an implementation of Provisioner that can be
|
|
|
|
// used for tests.
|
|
|
|
type MockProvisioner struct {
|
2019-03-27 12:29:09 +01:00
|
|
|
ProvFunc func(context.Context) error
|
2013-08-30 23:39:29 -07:00
|
|
|
|
2013-12-20 21:36:41 -08:00
|
|
|
PrepCalled bool
|
|
|
|
PrepConfigs []interface{}
|
|
|
|
ProvCalled bool
|
2020-04-16 11:58:54 +02:00
|
|
|
ProvRetried bool
|
2013-12-20 21:36:41 -08:00
|
|
|
ProvCommunicator Communicator
|
2020-11-19 11:54:31 -08:00
|
|
|
ProvUi packersdk.Ui
|
2013-08-30 23:21:15 -07:00
|
|
|
}
|
|
|
|
|
2019-12-17 11:25:56 +01:00
|
|
|
func (tp *MockProvisioner) ConfigSpec() hcldec.ObjectSpec { return tp.FlatMapstructure().HCL2Spec() }
|
|
|
|
|
|
|
|
func (tp *MockProvisioner) FlatConfig() interface{} { return tp.FlatMapstructure() }
|
|
|
|
|
2013-08-30 23:21:15 -07:00
|
|
|
func (t *MockProvisioner) Prepare(configs ...interface{}) error {
|
2018-09-10 16:48:42 -07:00
|
|
|
t.PrepCalled = true
|
|
|
|
t.PrepConfigs = configs
|
2013-08-30 23:21:15 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 11:54:31 -08:00
|
|
|
func (t *MockProvisioner) Provision(ctx context.Context, ui packersdk.Ui, comm Communicator, generatedData map[string]interface{}) error {
|
2020-04-16 11:58:54 +02:00
|
|
|
if t.ProvCalled {
|
|
|
|
t.ProvRetried = true
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-08-30 23:21:15 -07:00
|
|
|
t.ProvCalled = true
|
2013-12-20 21:36:41 -08:00
|
|
|
t.ProvCommunicator = comm
|
2013-08-30 23:21:15 -07:00
|
|
|
t.ProvUi = ui
|
2013-08-30 23:39:29 -07:00
|
|
|
|
|
|
|
if t.ProvFunc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-27 12:29:09 +01:00
|
|
|
return t.ProvFunc(ctx)
|
2013-08-30 23:21:15 -07:00
|
|
|
}
|
|
|
|
|
2018-12-07 16:23:03 +00:00
|
|
|
func (t *MockProvisioner) Communicator() Communicator {
|
|
|
|
return t.ProvCommunicator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *MockProvisioner) ElevatedUser() string {
|
|
|
|
return "user"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *MockProvisioner) ElevatedPassword() string {
|
|
|
|
return "password"
|
|
|
|
}
|