github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/plan_test.go (about) 1 package terraform 2 3 import ( 4 "bytes" 5 "strings" 6 7 "testing" 8 ) 9 10 func TestReadWritePlan(t *testing.T) { 11 plan := &Plan{ 12 Module: testModule(t, "new-good"), 13 Diff: &Diff{ 14 Modules: []*ModuleDiff{ 15 &ModuleDiff{ 16 Path: rootModulePath, 17 Resources: map[string]*InstanceDiff{ 18 "nodeA": &InstanceDiff{ 19 Attributes: map[string]*ResourceAttrDiff{ 20 "foo": &ResourceAttrDiff{ 21 Old: "foo", 22 New: "bar", 23 }, 24 "bar": &ResourceAttrDiff{ 25 Old: "foo", 26 NewComputed: true, 27 }, 28 "longfoo": &ResourceAttrDiff{ 29 Old: "foo", 30 New: "bar", 31 RequiresNew: true, 32 }, 33 }, 34 }, 35 }, 36 }, 37 }, 38 }, 39 State: &State{ 40 Modules: []*ModuleState{ 41 &ModuleState{ 42 Path: rootModulePath, 43 Resources: map[string]*ResourceState{ 44 "foo": &ResourceState{ 45 Primary: &InstanceState{ 46 ID: "bar", 47 }, 48 }, 49 }, 50 }, 51 }, 52 }, 53 Vars: map[string]string{ 54 "foo": "bar", 55 }, 56 } 57 58 buf := new(bytes.Buffer) 59 if err := WritePlan(plan, buf); err != nil { 60 t.Fatalf("err: %s", err) 61 } 62 63 actual, err := ReadPlan(buf) 64 if err != nil { 65 t.Fatalf("err: %s", err) 66 } 67 68 actualStr := strings.TrimSpace(actual.String()) 69 expectedStr := strings.TrimSpace(plan.String()) 70 if actualStr != expectedStr { 71 t.Fatalf("bad:\n\n%s\n\nexpected:\n\n%s", actualStr, expectedStr) 72 } 73 }