opentofu/terraform/graph_config_node_module_test.go

81 lines
1.7 KiB
Go
Raw Normal View History

2015-04-30 21:23:52 -05:00
package terraform
import (
"strings"
"testing"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/dag"
)
func TestGraphNodeConfigModule_impl(t *testing.T) {
var _ dag.Vertex = new(GraphNodeConfigModule)
var _ dag.NamedVertex = new(GraphNodeConfigModule)
var _ graphNodeConfig = new(GraphNodeConfigModule)
var _ GraphNodeExpandable = new(GraphNodeConfigModule)
}
func TestGraphNodeConfigModuleExpand(t *testing.T) {
mod := testModule(t, "graph-node-module-expand")
node := &GraphNodeConfigModule{
Path: []string{RootModuleName, "child"},
Module: &config.Module{},
Tree: nil,
}
g, err := node.Expand(&BasicGraphBuilder{
Steps: []GraphTransformer{
2016-11-05 18:26:12 -05:00
&ConfigTransformerOld{Module: mod},
2015-04-30 21:23:52 -05:00
},
})
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.Subgraph().(*Graph).String())
2015-04-30 21:23:52 -05:00
expected := strings.TrimSpace(testGraphNodeModuleExpandStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
2015-04-30 22:46:54 -05:00
func TestGraphNodeConfigModuleExpandFlatten(t *testing.T) {
mod := testModule(t, "graph-node-module-flatten")
node := &GraphNodeConfigModule{
Path: []string{RootModuleName, "child"},
Module: &config.Module{},
Tree: nil,
}
g, err := node.Expand(&BasicGraphBuilder{
Steps: []GraphTransformer{
2016-11-05 18:26:12 -05:00
&ConfigTransformerOld{Module: mod},
2015-04-30 22:46:54 -05:00
},
})
if err != nil {
t.Fatalf("err: %s", err)
}
2015-05-01 17:18:40 -05:00
fg := g.(GraphNodeFlatGraph)
2015-04-30 22:46:54 -05:00
actual := strings.TrimSpace(fg.FlattenGraph().String())
expected := strings.TrimSpace(testGraphNodeModuleExpandFlattenStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
const testGraphNodeModuleExpandStr = `
aws_instance.bar
aws_instance.foo
aws_instance.foo
plan-destroy
2015-04-30 22:46:54 -05:00
`
const testGraphNodeModuleExpandFlattenStr = `
2015-05-01 17:18:40 -05:00
aws_instance.foo
plan-destroy
2015-04-30 22:46:54 -05:00
`