From c0695b065791f966b5182d1e4b4b3449e5963942 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 27 Jan 2015 22:00:56 -0800 Subject: [PATCH] terraform: tests that some other graph nodes implement the interfaces --- terraform/graph_config_node_test.go | 29 +++++++++++++++++++++++++++++ terraform/transform_orphan.go | 4 ++++ terraform/transform_orphan_test.go | 15 +++++++++++++++ terraform/transform_tainted.go | 4 ++++ terraform/transform_tainted_test.go | 15 +++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/terraform/graph_config_node_test.go b/terraform/graph_config_node_test.go index bf54dfca4..40894f5da 100644 --- a/terraform/graph_config_node_test.go +++ b/terraform/graph_config_node_test.go @@ -3,11 +3,40 @@ package terraform import ( "testing" + "github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/dag" ) +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) + } +} + func TestGraphNodeConfigResource_impl(t *testing.T) { var _ dag.Vertex = new(GraphNodeConfigResource) var _ dag.NamedVertex = new(GraphNodeConfigResource) var _ graphNodeConfig = new(GraphNodeConfigResource) + var _ GraphNodeProviderConsumer = new(GraphNodeConfigResource) +} + +func TestGraphNodeConfigResource_ProvidedBy(t *testing.T) { + n := &GraphNodeConfigResource{ + Resource: &config.Resource{Type: "aws_instance"}, + } + + if v := n.ProvidedBy(); v != "aws" { + t.Fatalf("bad: %#v", v) + } } diff --git a/terraform/transform_orphan.go b/terraform/transform_orphan.go index 945d22df3..970063d29 100644 --- a/terraform/transform_orphan.go +++ b/terraform/transform_orphan.go @@ -105,6 +105,10 @@ func (n *graphNodeOrphanResource) Name() string { return fmt.Sprintf("%s (orphan)", n.ResourceName) } +func (n *graphNodeOrphanResource) ProvidedBy() string { + return resourceProvider(n.ResourceName) +} + func (n *graphNodeOrphanResource) dependableName() string { return n.ResourceName } diff --git a/terraform/transform_orphan_test.go b/terraform/transform_orphan_test.go index fa4409e72..76809a4d7 100644 --- a/terraform/transform_orphan_test.go +++ b/terraform/transform_orphan_test.go @@ -3,6 +3,8 @@ package terraform import ( "strings" "testing" + + "github.com/hashicorp/terraform/dag" ) func TestOrphanTransformer(t *testing.T) { @@ -259,6 +261,19 @@ func TestOrphanTransformer_resourceDepends(t *testing.T) { } } +func TestGraphNodeOrphanResource_impl(t *testing.T) { + var _ dag.Vertex = new(graphNodeOrphanResource) + var _ dag.NamedVertex = new(graphNodeOrphanResource) + var _ GraphNodeProviderConsumer = new(graphNodeOrphanResource) +} + +func TestGraphNodeOrphanResource_ProvidedBy(t *testing.T) { + n := &graphNodeOrphanResource{ResourceName: "aws_instance.foo"} + if v := n.ProvidedBy(); v != "aws" { + t.Fatalf("bad: %#v", v) + } +} + const testTransformOrphanBasicStr = ` aws_instance.db (orphan) aws_instance.web diff --git a/terraform/transform_tainted.go b/terraform/transform_tainted.go index a7fe920df..0655f7cc2 100644 --- a/terraform/transform_tainted.go +++ b/terraform/transform_tainted.go @@ -56,3 +56,7 @@ func (n *graphNodeTaintedResource) DependentOn() []string { func (n *graphNodeTaintedResource) Name() string { return fmt.Sprintf("%s (tainted #%d)", n.ResourceName, n.Index+1) } + +func (n *graphNodeTaintedResource) ProvidedBy() string { + return resourceProvider(n.ResourceName) +} diff --git a/terraform/transform_tainted_test.go b/terraform/transform_tainted_test.go index d8a5e72b6..39d4f8261 100644 --- a/terraform/transform_tainted_test.go +++ b/terraform/transform_tainted_test.go @@ -3,6 +3,8 @@ package terraform import ( "strings" "testing" + + "github.com/hashicorp/terraform/dag" ) func TestTaintedTransformer(t *testing.T) { @@ -43,6 +45,19 @@ func TestTaintedTransformer(t *testing.T) { } } +func TestGraphNodeTaintedResource_impl(t *testing.T) { + var _ dag.Vertex = new(graphNodeTaintedResource) + var _ dag.NamedVertex = new(graphNodeTaintedResource) + var _ GraphNodeProviderConsumer = new(graphNodeTaintedResource) +} + +func TestGraphNodeTaintedResource_ProvidedBy(t *testing.T) { + n := &graphNodeTaintedResource{ResourceName: "aws_instance.foo"} + if v := n.ProvidedBy(); v != "aws" { + t.Fatalf("bad: %#v", v) + } +} + const testTransformTaintedBasicStr = ` aws_instance.web aws_instance.web (tainted #1)