From cae6deb35146f536cbcd632e8f356918a8ac7e88 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 8 Feb 2015 13:01:49 -0800 Subject: [PATCH] terraform: more tests --- terraform/graph_builder.go | 1 - terraform/graph_builder_test.go | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/terraform/graph_builder.go b/terraform/graph_builder.go index 75e3afbe2..435883009 100644 --- a/terraform/graph_builder.go +++ b/terraform/graph_builder.go @@ -19,7 +19,6 @@ type BasicGraphBuilder struct { Steps []GraphTransformer } -// TODO(mitchellh): test func (b *BasicGraphBuilder) Build(path []string) (*Graph, error) { g := &Graph{Path: path} for _, step := range b.Steps { diff --git a/terraform/graph_builder_test.go b/terraform/graph_builder_test.go index f9da79e28..1dc8dfde2 100644 --- a/terraform/graph_builder_test.go +++ b/terraform/graph_builder_test.go @@ -1,10 +1,54 @@ package terraform import ( + "reflect" "strings" "testing" + + "github.com/hashicorp/terraform/dag" ) +func TestBasicGraphBuilder_impl(t *testing.T) { + var _ GraphBuilder = new(BasicGraphBuilder) +} + +func TestBasicGraphBuilder(t *testing.T) { + b := &BasicGraphBuilder{ + Steps: []GraphTransformer{ + &testBasicGraphBuilderTransform{1}, + }, + } + + g, err := b.Build(RootModulePath) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !reflect.DeepEqual(g.Path, RootModulePath) { + t.Fatalf("bad: %#v", g.Path) + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testBasicGraphBuilderStr) + if actual != expected { + t.Fatalf("bad: %s", actual) + } +} + +func TestBasicGraphBuilder_validate(t *testing.T) { + b := &BasicGraphBuilder{ + Steps: []GraphTransformer{ + &testBasicGraphBuilderTransform{1}, + &testBasicGraphBuilderTransform{2}, + }, + } + + _, err := b.Build(RootModulePath) + if err == nil { + t.Fatal("should error") + } +} + func TestBuiltinGraphBuilder_impl(t *testing.T) { var _ GraphBuilder = new(BuiltinGraphBuilder) } @@ -47,6 +91,19 @@ func TestBuiltinGraphBuilder_modules(t *testing.T) { } } +type testBasicGraphBuilderTransform struct { + V dag.Vertex +} + +func (t *testBasicGraphBuilderTransform) Transform(g *Graph) error { + g.Add(t.V) + return nil +} + +const testBasicGraphBuilderStr = ` +1 +` + const testBuiltinGraphBuilderBasicStr = ` aws_instance.db provider.aws