opentofu/terraform/graph_config_node_test.go

104 lines
2.5 KiB
Go
Raw Normal View History

2015-01-21 16:39:16 -06:00
package terraform
import (
2015-02-09 13:20:32 -06:00
"reflect"
2015-02-07 18:19:08 -06:00
"strings"
2015-01-21 16:39:16 -06:00
"testing"
"github.com/hashicorp/terraform/config"
2015-01-22 19:12:32 -06:00
"github.com/hashicorp/terraform/dag"
2015-01-21 16:39:16 -06:00
)
2015-02-07 18:19:08 -06:00
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"},
2015-02-11 19:07:38 -06:00
Module: &config.Module{},
2015-02-07 18:19:08 -06:00
Tree: nil,
}
g, err := node.Expand(&BasicGraphBuilder{
Steps: []GraphTransformer{
&ConfigTransformer{Module: mod},
},
})
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.Subgraph().String())
2015-02-07 18:19:08 -06:00
expected := strings.TrimSpace(testGraphNodeModuleExpandStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestGraphNodeConfigProvider_impl(t *testing.T) {
var _ dag.Vertex = new(GraphNodeConfigProvider)
var _ dag.NamedVertex = new(GraphNodeConfigProvider)
var _ graphNodeConfig = new(GraphNodeConfigProvider)
var _ GraphNodeProvider = new(GraphNodeConfigProvider)
}
func TestGraphNodeConfigProvider_ProviderName(t *testing.T) {
n := &GraphNodeConfigProvider{
Provider: &config.ProviderConfig{Name: "foo"},
}
if v := n.ProviderName(); v != "foo" {
t.Fatalf("bad: %#v", v)
}
}
2015-01-21 16:39:16 -06:00
func TestGraphNodeConfigResource_impl(t *testing.T) {
2015-01-23 17:11:11 -06:00
var _ dag.Vertex = new(GraphNodeConfigResource)
var _ dag.NamedVertex = new(GraphNodeConfigResource)
2015-01-21 16:39:16 -06:00
var _ graphNodeConfig = new(GraphNodeConfigResource)
var _ GraphNodeProviderConsumer = new(GraphNodeConfigResource)
2015-02-09 13:20:32 -06:00
var _ GraphNodeProvisionerConsumer = new(GraphNodeConfigResource)
}
func TestGraphNodeConfigResource_ProvidedBy(t *testing.T) {
n := &GraphNodeConfigResource{
Resource: &config.Resource{Type: "aws_instance"},
}
if v := n.ProvidedBy(); v[0] != "aws" {
t.Fatalf("bad: %#v", v)
}
2015-01-21 16:39:16 -06:00
}
2015-02-07 18:19:08 -06:00
2015-02-09 13:20:32 -06:00
func TestGraphNodeConfigResource_ProvisionedBy(t *testing.T) {
n := &GraphNodeConfigResource{
Resource: &config.Resource{
Type: "aws_instance",
Provisioners: []*config.Provisioner{
&config.Provisioner{Type: "foo"},
&config.Provisioner{Type: "bar"},
},
},
}
expected := []string{"foo", "bar"}
actual := n.ProvisionedBy()
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
2015-02-07 18:19:08 -06:00
const testGraphNodeModuleExpandStr = `
aws_instance.bar
aws_instance.foo
aws_instance.foo
2015-02-11 19:07:38 -06:00
module inputs
module inputs
2015-02-07 18:19:08 -06:00
`