Add draft of step test
This commit is contained in:
parent
2e3086be5a
commit
5eb600bf88
|
@ -15,9 +15,14 @@ import (
|
|||
// unmounting the installation ISO.
|
||||
type stepFinalizeTemplateConfig struct{}
|
||||
|
||||
type templateFinalizer interface {
|
||||
GetVmConfig(*proxmox.VmRef) (map[string]interface{}, error)
|
||||
SetVmConfig(*proxmox.VmRef, map[string]interface{}) (string, error)
|
||||
}
|
||||
|
||||
func (s *stepFinalizeTemplateConfig) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
client := state.Get("proxmoxClient").(*proxmox.Client)
|
||||
client := state.Get("proxmoxClient").(templateFinalizer)
|
||||
c := state.Get("config").(*Config)
|
||||
vmRef := state.Get("vmRef").(*proxmox.VmRef)
|
||||
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package proxmox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type finalizerMock struct {
|
||||
getConfig func() (map[string]interface{}, error)
|
||||
setConfig func(map[string]interface{}) (string, error)
|
||||
}
|
||||
|
||||
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) {
|
||||
return m.setConfig(c)
|
||||
}
|
||||
|
||||
func TestTemplateFinalize(t *testing.T) {
|
||||
finalizer := finalizerMock{
|
||||
getConfig: func() (map[string]interface{}, error) {
|
||||
return map[string]interface{}{
|
||||
"name": "dummy",
|
||||
"description": "Packer ephemeral build VM",
|
||||
"ide2": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
}, nil
|
||||
},
|
||||
setConfig: func(c map[string]interface{}) (string, error) {
|
||||
if c["name"] != "my-template" {
|
||||
t.Errorf("Expected name to be my-template, got %q", c["name"])
|
||||
}
|
||||
if c["description"] != "foo" {
|
||||
t.Errorf("Expected description to be foo, got %q", c["description"])
|
||||
}
|
||||
if c["ide2"] != "none,media=cdrom" {
|
||||
t.Errorf("Expected ide2 to be none,media=cdrom, got %q", c["ide2"])
|
||||
}
|
||||
|
||||
return "", nil
|
||||
},
|
||||
}
|
||||
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packer.TestUi(t))
|
||||
state.Put("config", &Config{
|
||||
TemplateName: "my-template",
|
||||
TemplateDescription: "foo",
|
||||
UnmountISO: true,
|
||||
})
|
||||
state.Put("vmRef", proxmox.NewVmRef(1))
|
||||
state.Put("proxmoxClient", finalizer)
|
||||
|
||||
step := stepFinalizeTemplateConfig{}
|
||||
action := step.Run(context.TODO(), state)
|
||||
if action != multistep.ActionContinue {
|
||||
t.Error("Expected action to be Continue, got Halt")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue