Add validation of interface implementation for both proxmox.Client and mocks

This commit is contained in:
Calle Pettersson 2019-03-14 22:32:59 +01:00 committed by Megan Marsh
parent c4ce295f67
commit 2f754c38f8
8 changed files with 18 additions and 4 deletions

View File

@ -20,6 +20,8 @@ type templateConverter interface {
CreateTemplate(*proxmox.VmRef) error
}
var _ templateConverter = &proxmox.Client{}
func (s *stepConvertToTemplate) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
client := state.Get("proxmoxClient").(templateConverter)

View File

@ -22,6 +22,8 @@ func (m converterMock) CreateTemplate(r *proxmox.VmRef) error {
return m.createTemplate(r)
}
var _ templateConverter = converterMock{}
func TestConvertToTemplate(t *testing.T) {
cs := []struct {
name string

View File

@ -17,9 +17,11 @@ type stepFinalizeTemplateConfig struct{}
type templateFinalizer interface {
GetVmConfig(*proxmox.VmRef) (map[string]interface{}, error)
SetVmConfig(*proxmox.VmRef, map[string]interface{}) (string, error)
SetVmConfig(*proxmox.VmRef, map[string]interface{}) (interface{}, error)
}
var _ templateFinalizer = &proxmox.Client{}
func (s *stepFinalizeTemplateConfig) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
client := state.Get("proxmoxClient").(templateFinalizer)

View File

@ -18,10 +18,12 @@ type finalizerMock struct {
func (m finalizerMock) GetVmConfig(*proxmox.VmRef) (map[string]interface{}, error) {
return m.getConfig()
}
func (m finalizerMock) SetVmConfig(vmref *proxmox.VmRef, c map[string]interface{}) (string, error) {
func (m finalizerMock) SetVmConfig(vmref *proxmox.VmRef, c map[string]interface{}) (interface{}, error) {
return m.setConfig(c)
}
var _ templateFinalizer = finalizerMock{}
func TestTemplateFinalize(t *testing.T) {
cs := []struct {
name string

View File

@ -114,6 +114,8 @@ type startedVMCleaner interface {
DeleteVm(*proxmox.VmRef) (string, error)
}
var _ startedVMCleaner = &proxmox.Client{}
func (s *stepStartVM) Cleanup(state multistep.StateBag) {
vmRefUntyped, ok := state.GetOk("vmRef")
// If not ok, we probably errored out before creating the VM

View File

@ -14,8 +14,6 @@ type startedVMCleanerMock struct {
deleteVm func() (string, error)
}
var _ startedVMCleaner = &startedVMCleanerMock{}
func (m startedVMCleanerMock) StopVm(*proxmox.VmRef) (string, error) {
return m.stopVm()
}
@ -23,6 +21,8 @@ func (m startedVMCleanerMock) DeleteVm(*proxmox.VmRef) (string, error) {
return m.deleteVm()
}
var _ startedVMCleaner = &startedVMCleanerMock{}
func TestCleanupStartVM(t *testing.T) {
cs := []struct {
name string

View File

@ -32,6 +32,8 @@ type commandTyper interface {
MonitorCmd(*proxmox.VmRef, string) (map[string]interface{}, error)
}
var _ commandTyper = &proxmox.Client{}
func (s *stepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
c := state.Get("config").(*Config)

View File

@ -20,6 +20,8 @@ func (m commandTyperMock) MonitorCmd(ref *proxmox.VmRef, cmd string) (map[string
return m.monitorCmd(ref, cmd)
}
var _ commandTyper = commandTyperMock{}
func TestTypeBootCommand(t *testing.T) {
cs := []struct {
name string