Skip to content

Commit 9cec9dc

Browse files
mdimicelijpalermo
authored andcommitted
add unit tests
1 parent 198c20d commit 9cec9dc

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

terraform/binary_path.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ func NewBinary(terraformBinary string) *Binary {
4848

4949
func (binary *Binary) BinaryPath() (string, error) {
5050
// if user sets a terraform binary use it
51-
exists, err := binary.FS.Exists(binary.TerraformBinary)
52-
if err == nil && exists {
53-
return binary.TerraformBinary, nil
51+
if binary.TerraformBinary != "" {
52+
exists, err := binary.FS.Exists(binary.TerraformBinary)
53+
if err == nil && exists {
54+
return binary.TerraformBinary, nil
55+
}
5456
}
5557

5658
destinationPath := fmt.Sprintf("%s/%s", binary.FS.GetTempDir(os.TempDir()), bblTfBinaryName)
57-
exists, err = binary.FS.Exists(destinationPath)
59+
exists, err := binary.FS.Exists(destinationPath)
5860
if err != nil {
5961
return "", err
6062
}

terraform/binary_path_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ var _ = Describe("BinaryPath", func() {
6060
Expect(fileSystem.ChtimesCall.Receives.ModTime).To(Equal(modTime))
6161
})
6262

63+
Context("when a custom terraform binary path is set", func() {
64+
BeforeEach(func() {
65+
binary.TerraformBinary = "/some/custom/path/bbl-terraform"
66+
})
67+
68+
Context("and the file exists", func() {
69+
BeforeEach(func() {
70+
fileSystem.ExistsCall.Returns.Bool = true
71+
})
72+
73+
It("doesn't rewrite the file", func() {
74+
res, err := binary.BinaryPath()
75+
Expect(err).NotTo(HaveOccurred())
76+
Expect(res).To(Equal("/some/custom/path/bbl-terraform"))
77+
Expect(fileSystem.WriteFileCall.CallCount).To(Equal(0))
78+
})
79+
})
80+
81+
Context("but the file does not exist", func() {
82+
It("uses the embedded binary ", func() {
83+
res, err := binary.BinaryPath()
84+
Expect(err).NotTo(HaveOccurred())
85+
Expect(res).To(Equal("/some/tmp/path/bbl-terraform"))
86+
})
87+
})
88+
})
89+
6390
Context("when there is no my-terraform-binary in box", func() {
6491
BeforeEach(func() {
6592
binary.EmbedData = contentOnlyModTime

0 commit comments

Comments
 (0)