opentofu/terraform/plan_test.go

74 lines
1.3 KiB
Go
Raw Normal View History

package terraform
import (
"bytes"
"reflect"
"testing"
)
func TestReadWritePlan(t *testing.T) {
plan := &Plan{
Config: testConfig(t, "new-good"),
Diff: &Diff{
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,
},
},
},
},
},
},
},
State: &State{
2014-09-16 17:09:40 -05:00
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"foo": &ResourceState{
Primary: &InstanceState{
ID: "bar",
},
},
},
},
},
},
Vars: map[string]string{
"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-08-05 00:04:48 -05:00
println(reflect.DeepEqual(actual.Config.Resources, plan.Config.Resources))
if !reflect.DeepEqual(actual, plan) {
t.Fatalf("bad: %#v", actual)
}
}