mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -06:00
d2001275dc
This is REALLY heavy and would be really hard to maintain any sort of compatibility with, but it is what we're going to do during dev initially (if we don't ship with it) in order to just get stuff working.
61 lines
1.0 KiB
Go
61 lines
1.0 KiB
Go
package terraform
|
|
|
|
import (
|
|
"bytes"
|
|
"reflect"
|
|
|
|
"testing"
|
|
)
|
|
|
|
func TestReadWritePlan(t *testing.T) {
|
|
tf := testTerraform(t, "new-good")
|
|
plan := &Plan{
|
|
Config: tf.config,
|
|
Diff: &Diff{
|
|
Resources: map[string]*ResourceDiff{
|
|
"nodeA": &ResourceDiff{
|
|
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{
|
|
Resources: map[string]*ResourceState{
|
|
"foo": &ResourceState{
|
|
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)
|
|
}
|
|
|
|
if !reflect.DeepEqual(actual, plan) {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
}
|