From 2f754c38f8cd61d58d8e9dd3284a854c00b8a3f1 Mon Sep 17 00:00:00 2001 From: Calle Pettersson Date: Thu, 14 Mar 2019 22:32:59 +0100 Subject: [PATCH] Add validation of interface implementation for both proxmox.Client and mocks --- builder/proxmox/step_convert_to_template.go | 2 ++ builder/proxmox/step_convert_to_template_test.go | 2 ++ builder/proxmox/step_finalize_template_config.go | 4 +++- builder/proxmox/step_finalize_template_config_test.go | 4 +++- builder/proxmox/step_start_vm.go | 2 ++ builder/proxmox/step_start_vm_test.go | 4 ++-- builder/proxmox/step_type_boot_command.go | 2 ++ builder/proxmox/step_type_boot_command_test.go | 2 ++ 8 files changed, 18 insertions(+), 4 deletions(-) diff --git a/builder/proxmox/step_convert_to_template.go b/builder/proxmox/step_convert_to_template.go index 9e514f3d6..712badd81 100644 --- a/builder/proxmox/step_convert_to_template.go +++ b/builder/proxmox/step_convert_to_template.go @@ -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) diff --git a/builder/proxmox/step_convert_to_template_test.go b/builder/proxmox/step_convert_to_template_test.go index 7df852627..a7f472e3a 100644 --- a/builder/proxmox/step_convert_to_template_test.go +++ b/builder/proxmox/step_convert_to_template_test.go @@ -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 diff --git a/builder/proxmox/step_finalize_template_config.go b/builder/proxmox/step_finalize_template_config.go index c6de188ef..df90fc9f8 100644 --- a/builder/proxmox/step_finalize_template_config.go +++ b/builder/proxmox/step_finalize_template_config.go @@ -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) diff --git a/builder/proxmox/step_finalize_template_config_test.go b/builder/proxmox/step_finalize_template_config_test.go index 58de6c966..501dddef2 100644 --- a/builder/proxmox/step_finalize_template_config_test.go +++ b/builder/proxmox/step_finalize_template_config_test.go @@ -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 diff --git a/builder/proxmox/step_start_vm.go b/builder/proxmox/step_start_vm.go index c65b8c968..779394023 100644 --- a/builder/proxmox/step_start_vm.go +++ b/builder/proxmox/step_start_vm.go @@ -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 diff --git a/builder/proxmox/step_start_vm_test.go b/builder/proxmox/step_start_vm_test.go index 70f0aa37b..cb19670f5 100644 --- a/builder/proxmox/step_start_vm_test.go +++ b/builder/proxmox/step_start_vm_test.go @@ -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 diff --git a/builder/proxmox/step_type_boot_command.go b/builder/proxmox/step_type_boot_command.go index 1967b09ca..2e87cb7e5 100644 --- a/builder/proxmox/step_type_boot_command.go +++ b/builder/proxmox/step_type_boot_command.go @@ -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) diff --git a/builder/proxmox/step_type_boot_command_test.go b/builder/proxmox/step_type_boot_command_test.go index efe8b4c4c..b2f285c04 100644 --- a/builder/proxmox/step_type_boot_command_test.go +++ b/builder/proxmox/step_type_boot_command_test.go @@ -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