diff --git a/cmd/create_env_test.go b/cmd/create_env_test.go index 787e81bc1..42c233402 100644 --- a/cmd/create_env_test.go +++ b/cmd/create_env_test.go @@ -1,6 +1,7 @@ package cmd_test import ( + "encoding/json" "errors" "fmt" "path/filepath" @@ -1144,6 +1145,22 @@ var _ = Describe("CreateEnvCmd", func() { err = command.Run(fakeStage, defaultCreateEnvOpts) Expect(err).NotTo(HaveOccurred()) }) + + It("constructs and empty array of disks using make, due to odd behavior in golang where empty var []string marshals as null", func() { + err := fs.WriteFileString(deploymentStatePath, ` + { + "disks": null + }`) + Expect(err).ToNot(HaveOccurred()) + + expectDeploy.Do(func(_, _, _, _, _, _ interface{}, diskCIDs []string, _ interface{}) { + jsonMarshalOfDisks, err := json.Marshal(diskCIDs) + Expect(err).ToNot(HaveOccurred()) + Expect(string(jsonMarshalOfDisks)).To(Equal("[]")) + }) + err = command.Run(fakeStage, defaultCreateEnvOpts) + Expect(err).NotTo(HaveOccurred()) + }) }) }) }) diff --git a/cmd/deployment_preparer.go b/cmd/deployment_preparer.go index 31cd1d049..d921c20e4 100644 --- a/cmd/deployment_preparer.go +++ b/cmd/deployment_preparer.go @@ -307,7 +307,7 @@ func (c *DeploymentPreparer) stemcellApiVersion(stemcell bistemcell.ExtractedSte // These disk CIDs get passed all the way to the create_vm cpi call func (c *DeploymentPreparer) extractDiskCIDsFromState(deploymentState biconfig.DeploymentState) []string { - var diskCIDs []string + diskCIDs := make([]string, 0) for _, disk := range deploymentState.Disks { diskCIDs = append(diskCIDs, disk.CID) }