Skip to content

Commit

Permalink
Passing unit & integration tests
Browse files Browse the repository at this point in the history
* creating .bosh-micro.json

[#73562448]

Signed-off-by: Phan Le <ple@pivotallabs.com>
  • Loading branch information
maximilien authored and Phan Le committed Jul 29, 2014
1 parent 876a6ed commit 837f9bc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
16 changes: 14 additions & 2 deletions cmd/deployment_cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
Expand All @@ -10,9 +11,13 @@ import (
)

const (
BOSH_MICRO_FILENAME = ".bosh_micro"
BOSH_MICRO_FILENAME = ".bosh_micro.json"
)

type deploymentFileJson struct {
Deployment string `json:"deployment"`
}

type deploymentCmd struct {
args []string
}
Expand Down Expand Up @@ -43,7 +48,14 @@ func (f *deploymentCmd) Run(args []string) error {
}

boshMicroPath := path.Join(usr.HomeDir, BOSH_MICRO_FILENAME)
err = ioutil.WriteFile(boshMicroPath, []byte(manifestFilePath), os.ModePerm)

jsonContentStruct := &deploymentFileJson{Deployment: manifestFilePath}
jsonContent, err := json.MarshalIndent(jsonContentStruct, "", " ")
if err != nil {
return errors.New("Could not marshal JSON content %s")
}

err = ioutil.WriteFile(boshMicroPath, jsonContent, os.ModePerm)
if err != nil {
return errors.New(fmt.Sprintf("Could not write to file %s", boshMicroPath))
}
Expand Down
43 changes: 34 additions & 9 deletions cmd/deployment_cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd_test

import (
"fmt"
"io/ioutil"
"os"
"os/user"
Expand Down Expand Up @@ -37,16 +38,40 @@ var _ = Describe("DeploymentCmd", func() {
Expect(err).NotTo(HaveOccurred())
})

It("stores the manifest file path to a hidden file at the home dir", func() {
err := command.Run(args)
Expect(err).ToNot(HaveOccurred())
usr, err := user.Current()
Expect(err).ToNot(HaveOccurred())
Context("storing the file", func() {
var expectedFilePath string
var expectedJsonContent string

BeforeEach(func() {
usr, err := user.Current()
Expect(err).ToNot(HaveOccurred())

expectedFilePath = path.Join(usr.HomeDir, ".bosh_micro.json")
expectedJsonContent = fmt.Sprintf(`
{
"deployment" : "%s"
}
`, manifestPath)
})

It("stores the manifest file path to a hidden file at the home dir", func() {
err := command.Run(args)
Expect(err).ToNot(HaveOccurred())

actualFileContent, err := ioutil.ReadFile(expectedFilePath)
Expect(err).NotTo(HaveOccurred())
Expect(string(actualFileContent)).To(ContainSubstring(manifestPath))
})

It("store the file in json format", func() {
err := command.Run(args)
Expect(err).ToNot(HaveOccurred())

actualFileContent, err := ioutil.ReadFile(expectedFilePath)
Expect(err).NotTo(HaveOccurred())
Expect(string(actualFileContent)).To(MatchJSON(expectedJsonContent))
})

expectedFilePath := path.Join(usr.HomeDir, ".bosh_micro")
expectedFileContent, err := ioutil.ReadFile(expectedFilePath)
Expect(err).NotTo(HaveOccurred())
Expect(string(expectedFileContent)).To(ContainSubstring(manifestPath))
})
})

Expand Down

0 comments on commit 837f9bc

Please sign in to comment.