forked from cloudfoundry/bosh-bootloader
-
Notifications
You must be signed in to change notification settings - Fork 2
/
terraform_cli.go
51 lines (44 loc) · 1.07 KB
/
terraform_cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package fakes
import (
"io"
)
type TerraformCLI struct {
RunCall struct {
CallCount int
Stub func(stdout io.Writer)
Returns struct {
Errors []error
}
Initialized bool
Receives struct {
Stdout io.Writer
WorkingDirectory string
Args []string
Env []string
}
}
}
func (t *TerraformCLI) RunWithEnv(stdout io.Writer, workingDirectory string, args []string, env []string) error {
t.RunCall.CallCount++
t.RunCall.Receives.Stdout = stdout
t.RunCall.Receives.WorkingDirectory = workingDirectory
t.RunCall.Receives.Args = args
t.RunCall.Receives.Env = env
switch args[0] {
case "version":
if t.RunCall.Stub != nil {
t.RunCall.Stub(stdout)
}
default:
if t.RunCall.Stub != nil {
t.RunCall.Stub(stdout)
}
}
if len(t.RunCall.Returns.Errors) >= t.RunCall.CallCount {
return t.RunCall.Returns.Errors[t.RunCall.CallCount-1]
}
return nil
}
func (t *TerraformCLI) Run(stdout io.Writer, workingDirectory string, args []string) error {
return t.RunWithEnv(stdout, workingDirectory, args, []string{})
}