2016-09-13 19:56:37 +02:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestApplyGraphBuilder_impl(t *testing.T) {
|
|
|
|
var _ GraphBuilder = new(ApplyGraphBuilder)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApplyGraphBuilder(t *testing.T) {
|
|
|
|
diff := &Diff{
|
|
|
|
Modules: []*ModuleDiff{
|
|
|
|
&ModuleDiff{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*InstanceDiff{
|
|
|
|
// Verify noop doesn't show up in graph
|
|
|
|
"aws_instance.noop": &InstanceDiff{},
|
|
|
|
|
|
|
|
"aws_instance.create": &InstanceDiff{
|
|
|
|
Attributes: map[string]*ResourceAttrDiff{
|
|
|
|
"name": &ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-09-16 03:30:11 +02:00
|
|
|
|
|
|
|
"aws_instance.other": &InstanceDiff{
|
|
|
|
Attributes: map[string]*ResourceAttrDiff{
|
|
|
|
"name": &ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-09-13 19:56:37 +02:00
|
|
|
},
|
|
|
|
},
|
2016-09-14 23:43:14 +02:00
|
|
|
|
|
|
|
&ModuleDiff{
|
|
|
|
Path: []string{"root", "child"},
|
|
|
|
Resources: map[string]*InstanceDiff{
|
|
|
|
"aws_instance.create": &InstanceDiff{
|
|
|
|
Attributes: map[string]*ResourceAttrDiff{
|
|
|
|
"name": &ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-09-13 19:56:37 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
b := &ApplyGraphBuilder{
|
2016-09-15 18:32:37 +02:00
|
|
|
Module: testModule(t, "graph-builder-apply-basic"),
|
|
|
|
Diff: diff,
|
|
|
|
Providers: []string{"aws"},
|
|
|
|
Provisioners: []string{"exec"},
|
2016-09-13 19:56:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g, err := b.Build(RootModulePath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(g.Path, RootModulePath) {
|
|
|
|
t.Fatalf("bad: %#v", g.Path)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testApplyGraphBuilderStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testApplyGraphBuilderStr = `
|
|
|
|
aws_instance.create
|
2016-09-14 02:11:34 +02:00
|
|
|
provider.aws
|
2016-09-16 03:30:11 +02:00
|
|
|
aws_instance.other
|
|
|
|
aws_instance.create
|
|
|
|
provider.aws
|
2016-09-14 23:43:14 +02:00
|
|
|
module.child.aws_instance.create
|
|
|
|
module.child.provider.aws
|
2016-09-15 18:32:37 +02:00
|
|
|
provisioner.exec
|
2016-09-14 23:43:14 +02:00
|
|
|
module.child.provider.aws
|
|
|
|
provider.aws
|
2016-09-14 02:11:34 +02:00
|
|
|
provider.aws
|
2016-09-15 18:32:37 +02:00
|
|
|
provisioner.exec
|
2016-09-14 23:43:14 +02:00
|
|
|
root
|
2016-09-16 03:30:11 +02:00
|
|
|
aws_instance.other
|
2016-09-14 23:43:14 +02:00
|
|
|
module.child.aws_instance.create
|
2016-09-13 19:56:37 +02:00
|
|
|
`
|