Files
Packer-Cn/packer/provisioner_mock.go
T

60 lines
1.2 KiB
Go
Raw Normal View History

2013-08-30 23:21:15 -07:00
package packer
import (
"context"
2019-12-17 11:25:56 +01:00
"github.com/hashicorp/hcl/v2/hcldec"
)
2013-08-30 23:21:15 -07:00
// MockProvisioner is an implementation of Provisioner that can be
// used for tests.
type MockProvisioner struct {
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
ProvRetried bool
2013-12-20 21:36:41 -08:00
ProvCommunicator Communicator
ProvUi 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 {
t.PrepCalled = true
t.PrepConfigs = configs
2013-08-30 23:21:15 -07:00
return nil
}
func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error {
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
}
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"
}