2015-02-28 04:18:04 +01:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTransitiveReductionTransformer(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-trans-reduce-basic")
|
|
|
|
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
|
|
{
|
2017-01-27 04:56:16 +01:00
|
|
|
tf := &ConfigTransformer{Module: 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
|
|
|
{
|
|
|
|
transform := &AttachResourceConfigTransformer{Module: mod}
|
|
|
|
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
|
|
|
|
`
|