File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -48,13 +48,15 @@ func NewBinary(terraformBinary string) *Binary {
48
48
49
49
func (binary * Binary ) BinaryPath () (string , error ) {
50
50
// 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
+ }
54
56
}
55
57
56
58
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 )
58
60
if err != nil {
59
61
return "" , err
60
62
}
Original file line number Diff line number Diff line change @@ -60,6 +60,33 @@ var _ = Describe("BinaryPath", func() {
60
60
Expect (fileSystem .ChtimesCall .Receives .ModTime ).To (Equal (modTime ))
61
61
})
62
62
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
+
63
90
Context ("when there is no my-terraform-binary in box" , func () {
64
91
BeforeEach (func () {
65
92
binary .EmbedData = contentOnlyModTime
You can’t perform that action at this time.
0 commit comments