2015-02-28 04:18:04 +01:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2018-05-05 04:24:06 +02:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
2015-02-28 04:18:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTransitiveReductionTransformer(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-trans-reduce-basic")
|
|
|
|
|
2018-05-05 04:24:06 +02:00
|
|
|
g := Graph{Path: addrs.RootModuleInstance}
|
2015-02-28 04:18:04 +01:00
|
|
|
{
|
2018-05-05 04:24:06 +02:00
|
|
|
tf := &ConfigTransformer{Config: mod}
|
2015-02-28 04:18:04 +01:00
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 04:56:16 +01:00
|
|
|
{
|
2018-05-05 04:24:06 +02:00
|
|
|
transform := &AttachResourceConfigTransformer{Config: mod}
|
2017-01-27 04:56:16 +01:00
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
transform := &ReferenceTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-28 04:18:04 +01:00
|
|
|
{
|
|
|
|
transform := &TransitiveReductionTransformer{}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformTransReduceBasicStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testTransformTransReduceBasicStr = `
|
|
|
|
aws_instance.A
|
|
|
|
aws_instance.B
|
|
|
|
aws_instance.A
|
|
|
|
aws_instance.C
|
|
|
|
aws_instance.B
|
|
|
|
`
|