-
Notifications
You must be signed in to change notification settings - Fork 107
/
import_test.go
71 lines (62 loc) · 1.38 KB
/
import_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
66
67
68
69
70
71
package tfexec
import (
"context"
"testing"
"github.com/hashicorp/terraform-exec/tfexec/internal/testutil"
)
func TestImportCmd(t *testing.T) {
td := t.TempDir()
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
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) {
importCmd, err := tf.importCmd(context.Background(), "my-addr", "my-id")
if err != nil {
t.Fatal(err)
}
assertCmd(t, []string{
"import",
"-no-color",
"-input=false",
"-lock-timeout=0s",
"-lock=true",
"my-addr",
"my-id",
}, nil, importCmd)
})
t.Run("override all defaults", func(t *testing.T) {
importCmd, err := tf.importCmd(context.Background(), "my-addr2", "my-id2",
Backup("testbackup"),
LockTimeout("200s"),
State("teststate"),
StateOut("teststateout"),
VarFile("testvarfile"),
Lock(false),
Var("var1=foo"),
Var("var2=bar"),
AllowMissingConfig(true),
)
if err != nil {
t.Fatal(err)
}
assertCmd(t, []string{
"import",
"-no-color",
"-input=false",
"-backup=testbackup",
"-lock-timeout=200s",
"-state=teststate",
"-state-out=teststateout",
"-var-file=testvarfile",
"-lock=false",
"-allow-missing-config",
"-var", "var1=foo",
"-var", "var2=bar",
"my-addr2",
"my-id2",
}, nil, importCmd)
})
}