2016-11-06 01:58:38 +01:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPlanGraphBuilder_impl(t *testing.T) {
|
|
|
|
var _ GraphBuilder = new(PlanGraphBuilder)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPlanGraphBuilder(t *testing.T) {
|
|
|
|
b := &PlanGraphBuilder{
|
|
|
|
Module: testModule(t, "graph-builder-plan-basic"),
|
|
|
|
Providers: []string{"aws", "openstack"},
|
|
|
|
DisableReduce: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
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(testPlanGraphBuilderStr)
|
|
|
|
if actual != expected {
|
2017-04-20 07:23:52 +02:00
|
|
|
t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual)
|
2016-11-06 01:58:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 18:21:29 +01:00
|
|
|
func TestPlanGraphBuilder_targetModule(t *testing.T) {
|
|
|
|
b := &PlanGraphBuilder{
|
|
|
|
Module: testModule(t, "graph-builder-plan-target-module-provider"),
|
|
|
|
Providers: []string{"null"},
|
|
|
|
Targets: []string{"module.child2"},
|
|
|
|
}
|
|
|
|
|
|
|
|
g, err := b.Build(RootModulePath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Graph: %s", g.String())
|
|
|
|
|
|
|
|
testGraphNotContains(t, g, "module.child1.provider.null")
|
|
|
|
testGraphNotContains(t, g, "module.child1.null_resource.foo")
|
|
|
|
}
|
|
|
|
|
2016-11-06 01:58:38 +01:00
|
|
|
const testPlanGraphBuilderStr = `
|
|
|
|
aws_instance.web
|
|
|
|
aws_security_group.firewall
|
|
|
|
provider.aws
|
|
|
|
var.foo
|
|
|
|
aws_load_balancer.weblb
|
|
|
|
aws_instance.web
|
|
|
|
provider.aws
|
|
|
|
aws_security_group.firewall
|
|
|
|
provider.aws
|
2017-04-20 07:23:52 +02:00
|
|
|
meta.count-boundary (count boundary fixup)
|
|
|
|
aws_instance.web
|
|
|
|
aws_load_balancer.weblb
|
|
|
|
aws_security_group.firewall
|
|
|
|
openstack_floating_ip.random
|
|
|
|
provider.aws
|
|
|
|
provider.openstack
|
|
|
|
var.foo
|
2016-11-06 01:58:38 +01:00
|
|
|
openstack_floating_ip.random
|
|
|
|
provider.openstack
|
|
|
|
provider.aws
|
|
|
|
openstack_floating_ip.random
|
2017-04-12 23:25:15 +02:00
|
|
|
provider.aws (close)
|
|
|
|
aws_instance.web
|
|
|
|
aws_load_balancer.weblb
|
|
|
|
aws_security_group.firewall
|
|
|
|
provider.aws
|
2016-11-06 01:58:38 +01:00
|
|
|
provider.openstack
|
2017-04-12 23:25:15 +02:00
|
|
|
provider.openstack (close)
|
|
|
|
openstack_floating_ip.random
|
|
|
|
provider.openstack
|
|
|
|
root
|
2017-04-20 07:23:52 +02:00
|
|
|
meta.count-boundary (count boundary fixup)
|
2017-04-12 23:25:15 +02:00
|
|
|
provider.aws (close)
|
|
|
|
provider.openstack (close)
|
2016-11-06 01:58:38 +01:00
|
|
|
var.foo
|
|
|
|
`
|