From cfe37057bddd91b6e9fad24940db3e25e2104e1b Mon Sep 17 00:00:00 2001 From: Paul Meyer Date: Wed, 25 Mar 2020 20:26:33 +0000 Subject: [PATCH] Use const for statebag key --- builder/azure/chroot/const.go | 5 +++++ builder/azure/chroot/step_attach_disk.go | 4 ++-- builder/azure/chroot/step_attach_disk_test.go | 2 +- builder/azure/chroot/step_create_image.go | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 builder/azure/chroot/const.go diff --git a/builder/azure/chroot/const.go b/builder/azure/chroot/const.go new file mode 100644 index 000000000..62658233f --- /dev/null +++ b/builder/azure/chroot/const.go @@ -0,0 +1,5 @@ +package chroot + +const ( + stateBagKey_OSDiskResourceID = "os_disk_resource_id" +) diff --git a/builder/azure/chroot/step_attach_disk.go b/builder/azure/chroot/step_attach_disk.go index 286c01af1..83c633133 100644 --- a/builder/azure/chroot/step_attach_disk.go +++ b/builder/azure/chroot/step_attach_disk.go @@ -20,7 +20,7 @@ type StepAttachDisk struct { func (s *StepAttachDisk) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { azcli := state.Get("azureclient").(client.AzureClientSet) ui := state.Get("ui").(packer.Ui) - diskResourceID := state.Get("os_disk_resource_id").(string) + diskResourceID := state.Get(stateBagKey_OSDiskResourceID).(string) ui.Say(fmt.Sprintf("Attaching disk '%s'", diskResourceID)) @@ -67,7 +67,7 @@ func (s *StepAttachDisk) CleanupFunc(state multistep.StateBag) error { if s.attached { azcli := state.Get("azureclient").(client.AzureClientSet) ui := state.Get("ui").(packer.Ui) - diskResourceID := state.Get("os_disk_resource_id").(string) + diskResourceID := state.Get(stateBagKey_OSDiskResourceID).(string) ui.Say(fmt.Sprintf("Detaching disk '%s'", diskResourceID)) diff --git a/builder/azure/chroot/step_attach_disk_test.go b/builder/azure/chroot/step_attach_disk_test.go index f6749211e..87531b278 100644 --- a/builder/azure/chroot/step_attach_disk_test.go +++ b/builder/azure/chroot/step_attach_disk_test.go @@ -78,7 +78,7 @@ func TestStepAttachDisk_Run(t *testing.T) { state := new(multistep.BasicStateBag) state.Put("azureclient", &client.AzureClientSetMock{}) state.Put("ui", ui) - state.Put("os_disk_resource_id", "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/disks/disk1") + state.Put(stateBagKey_OSDiskResourceID, "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/disks/disk1") got := s.Run(context.TODO(), state) if !reflect.DeepEqual(got, tt.want) { diff --git a/builder/azure/chroot/step_create_image.go b/builder/azure/chroot/step_create_image.go index 6463a3e25..2d08e5280 100644 --- a/builder/azure/chroot/step_create_image.go +++ b/builder/azure/chroot/step_create_image.go @@ -28,7 +28,7 @@ type StepCreateImage struct { func (s *StepCreateImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { azcli := state.Get("azureclient").(client.AzureClientSet) ui := state.Get("ui").(packer.Ui) - diskResourceID := state.Get("os_disk_resource_id").(string) + diskResourceID := state.Get(stateBagKey_OSDiskResourceID).(string) ui.Say(fmt.Sprintf("Creating image %s\n using %s for os disk.", s.ImageResourceID,