2015-05-01 20:09:23 +02:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFlattenTransformer(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-flatten")
|
|
|
|
|
|
|
|
var b BasicGraphBuilder
|
|
|
|
b = BasicGraphBuilder{
|
|
|
|
Steps: []GraphTransformer{
|
|
|
|
&ConfigTransformer{Module: mod},
|
|
|
|
&VertexTransformer{
|
|
|
|
Transforms: []GraphVertexTransformer{
|
|
|
|
&ExpandTransform{
|
|
|
|
Builder: &b,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&FlattenTransformer{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
g, err := b.Build(rootModulePath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformFlattenStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 20:45:42 +02:00
|
|
|
func TestFlattenTransformer_withProxy(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-flatten")
|
|
|
|
|
|
|
|
var b BasicGraphBuilder
|
|
|
|
b = BasicGraphBuilder{
|
|
|
|
Steps: []GraphTransformer{
|
|
|
|
&ConfigTransformer{Module: mod},
|
|
|
|
&VertexTransformer{
|
|
|
|
Transforms: []GraphVertexTransformer{
|
|
|
|
&ExpandTransform{
|
|
|
|
Builder: &b,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&FlattenTransformer{},
|
|
|
|
&ProxyTransformer{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
g, err := b.Build(rootModulePath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformFlattenProxyStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 20:09:23 +02:00
|
|
|
const testTransformFlattenStr = `
|
|
|
|
aws_instance.parent
|
2015-05-01 20:26:58 +02:00
|
|
|
aws_instance.parent-output
|
|
|
|
module.child.output.output
|
2015-05-01 20:09:23 +02:00
|
|
|
module.child.aws_instance.child
|
|
|
|
module.child.var.var
|
2015-05-01 20:26:58 +02:00
|
|
|
module.child.output.output
|
|
|
|
module.child.aws_instance.child
|
2015-05-02 03:26:35 +02:00
|
|
|
module.child.plan-destroy
|
2015-05-01 20:09:23 +02:00
|
|
|
module.child.var.var
|
|
|
|
aws_instance.parent
|
|
|
|
`
|
2015-05-01 20:45:42 +02:00
|
|
|
|
|
|
|
const testTransformFlattenProxyStr = `
|
|
|
|
aws_instance.parent
|
|
|
|
aws_instance.parent-output
|
|
|
|
module.child.aws_instance.child
|
|
|
|
module.child.output.output
|
|
|
|
module.child.aws_instance.child
|
|
|
|
aws_instance.parent
|
|
|
|
module.child.var.var
|
|
|
|
module.child.output.output
|
|
|
|
module.child.aws_instance.child
|
2015-05-02 03:26:35 +02:00
|
|
|
module.child.plan-destroy
|
2015-05-01 20:45:42 +02:00
|
|
|
module.child.var.var
|
|
|
|
aws_instance.parent
|
|
|
|
`
|