forked from hashicorp/terraform-json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan_test.go
64 lines (54 loc) · 1.29 KB
/
plan_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
package tfjson
import (
"encoding/json"
"os"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestPlanValidate(t *testing.T) {
f, err := os.Open("testdata/basic/plan.json")
if err != nil {
t.Fatal(err)
}
defer f.Close()
var plan *Plan
if err := json.NewDecoder(f).Decode(&plan); err != nil {
t.Fatal(err)
}
if err := plan.Validate(); err != nil {
t.Fatal(err)
}
}
func TestPlan_015(t *testing.T) {
f, err := os.Open("testdata/basic/plan-0.15.json")
if err != nil {
t.Fatal(err)
}
defer f.Close()
var plan *Plan
if err := json.NewDecoder(f).Decode(&plan); err != nil {
t.Fatal(err)
}
if err := plan.Validate(); err != nil {
t.Fatal(err)
}
expectedChange := &Change{
Actions: Actions{"create"},
After: map[string]interface{}{"ami": "boop"},
AfterUnknown: map[string]interface{}{"id": true},
BeforeSensitive: false,
AfterSensitive: map[string]interface{}{"ami": true},
}
if diff := cmp.Diff(expectedChange, plan.ResourceChanges[0].Change); diff != "" {
t.Fatalf("unexpected change: %s", diff)
}
expectedVariable := map[string]*ConfigVariable{
"test_var": {
Default: "boop",
Sensitive: true,
},
}
if diff := cmp.Diff(expectedVariable, plan.Config.RootModule.Variables); diff != "" {
t.Fatalf("unexpected variables: %s", diff)
}
}