Skip to content

Commit

Permalink
Merge pull request #670 from cloudfoundry/pr-fix-null-string-slices
Browse files Browse the repository at this point in the history
Fix create-env bug where an empty slice of disks from the state file results in null being passed to the CPI ask the disks argument
  • Loading branch information
jpalermo authored Oct 31, 2024
2 parents c18f71c + 8b80f9a commit 5357b10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cmd/create_env_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd_test

import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
Expand Down Expand Up @@ -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())
})
})
})
})
2 changes: 1 addition & 1 deletion cmd/deployment_preparer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 5357b10

Please sign in to comment.