2014-06-20 19:33:26 +02:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2014-09-24 23:56:48 +02:00
|
|
|
"strings"
|
2014-06-20 19:33:26 +02:00
|
|
|
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReadWritePlan(t *testing.T) {
|
|
|
|
plan := &Plan{
|
2014-09-24 23:56:48 +02:00
|
|
|
Module: testModule(t, "new-good"),
|
2014-06-20 19:33:26 +02:00
|
|
|
Diff: &Diff{
|
2014-09-23 20:43:21 +02:00
|
|
|
Modules: []*ModuleDiff{
|
|
|
|
&ModuleDiff{
|
|
|
|
Path: rootModulePath,
|
|
|
|
Resources: map[string]*InstanceDiff{
|
|
|
|
"nodeA": &InstanceDiff{
|
|
|
|
Attributes: map[string]*ResourceAttrDiff{
|
|
|
|
"foo": &ResourceAttrDiff{
|
|
|
|
Old: "foo",
|
|
|
|
New: "bar",
|
|
|
|
},
|
|
|
|
"bar": &ResourceAttrDiff{
|
|
|
|
Old: "foo",
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
"longfoo": &ResourceAttrDiff{
|
|
|
|
Old: "foo",
|
|
|
|
New: "bar",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
},
|
2017-01-31 20:50:37 +01:00
|
|
|
|
|
|
|
Meta: map[string]interface{}{
|
|
|
|
"foo": []interface{}{1, 2, 3},
|
|
|
|
},
|
2014-06-20 19:33:26 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
State: &State{
|
2014-09-17 00:09:40 +02:00
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: rootModulePath,
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"foo": &ResourceState{
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-06-20 19:33:26 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-07-18 19:52:10 +02:00
|
|
|
Vars: map[string]interface{}{
|
2014-06-20 19:33:26 +02:00
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := WritePlan(plan, buf); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual, err := ReadPlan(buf)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2014-09-24 23:56:48 +02:00
|
|
|
actualStr := strings.TrimSpace(actual.String())
|
|
|
|
expectedStr := strings.TrimSpace(plan.String())
|
|
|
|
if actualStr != expectedStr {
|
|
|
|
t.Fatalf("bad:\n\n%s\n\nexpected:\n\n%s", actualStr, expectedStr)
|
2014-06-20 19:33:26 +02:00
|
|
|
}
|
|
|
|
}
|