-
Notifications
You must be signed in to change notification settings - Fork 108
/
destroy_test.go
65 lines (56 loc) · 1.48 KB
/
destroy_test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package tfexec
import (
"context"
"testing"
"github.com/hashicorp/terraform-exec/tfexec/internal/testutil"
)
func TestDestroyCmd(t *testing.T) {
td := t.TempDir()
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
// empty env, to avoid environ mismatch in testing
tf.SetEnv(map[string]string{})
t.Run("defaults", func(t *testing.T) {
destroyCmd, err := tf.destroyCmd(context.Background())
if err != nil {
t.Fatal(err)
}
assertCmd(t, []string{
"destroy",
"-no-color",
"-auto-approve",
"-input=false",
"-lock-timeout=0s",
"-lock=true",
"-parallelism=10",
"-refresh=true",
}, nil, destroyCmd)
})
t.Run("override all defaults", func(t *testing.T) {
destroyCmd, err := tf.destroyCmd(context.Background(), Backup("testbackup"), LockTimeout("200s"), State("teststate"), StateOut("teststateout"), VarFile("testvarfile"), Lock(false), Parallelism(99), Refresh(false), Target("target1"), Target("target2"), Var("var1=foo"), Var("var2=bar"), Dir("destroydir"))
if err != nil {
t.Fatal(err)
}
assertCmd(t, []string{
"destroy",
"-no-color",
"-auto-approve",
"-input=false",
"-backup=testbackup",
"-lock-timeout=200s",
"-state=teststate",
"-state-out=teststateout",
"-var-file=testvarfile",
"-lock=false",
"-parallelism=99",
"-refresh=false",
"-target=target1",
"-target=target2",
"-var", "var1=foo",
"-var", "var2=bar",
"destroydir",
}, nil, destroyCmd)
})
}