From bd4aaac71a1607ec0b40096d44fab043e1a6a1bb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 26 Mar 2015 09:11:32 -0700 Subject: [PATCH] config/module: failing unit test for GH-1232 --- .../module/test-fixtures/basic-parent/a/a.tf | 3 ++ .../module/test-fixtures/basic-parent/c/c.tf | 1 + .../module/test-fixtures/basic-parent/main.tf | 3 ++ config/module/tree_test.go | 38 +++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 config/module/test-fixtures/basic-parent/a/a.tf create mode 100644 config/module/test-fixtures/basic-parent/c/c.tf create mode 100644 config/module/test-fixtures/basic-parent/main.tf diff --git a/config/module/test-fixtures/basic-parent/a/a.tf b/config/module/test-fixtures/basic-parent/a/a.tf new file mode 100644 index 0000000000..b9b44f4640 --- /dev/null +++ b/config/module/test-fixtures/basic-parent/a/a.tf @@ -0,0 +1,3 @@ +module "b" { + source = "../c" +} diff --git a/config/module/test-fixtures/basic-parent/c/c.tf b/config/module/test-fixtures/basic-parent/c/c.tf new file mode 100644 index 0000000000..fec56017dc --- /dev/null +++ b/config/module/test-fixtures/basic-parent/c/c.tf @@ -0,0 +1 @@ +# Hello diff --git a/config/module/test-fixtures/basic-parent/main.tf b/config/module/test-fixtures/basic-parent/main.tf new file mode 100644 index 0000000000..2326ee22ac --- /dev/null +++ b/config/module/test-fixtures/basic-parent/main.tf @@ -0,0 +1,3 @@ +module "a" { + source = "./a" +} diff --git a/config/module/tree_test.go b/config/module/tree_test.go index d8a7535225..2e4a82eec5 100644 --- a/config/module/tree_test.go +++ b/config/module/tree_test.go @@ -94,6 +94,44 @@ func TestTreeLoad_duplicate(t *testing.T) { } } +func TestTreeLoad_parentRef(t *testing.T) { + storage := testStorage(t) + tree := NewTree("", testConfig(t, "basic-parent")) + + if tree.Loaded() { + t.Fatal("should not be loaded") + } + + // This should error because we haven't gotten things yet + if err := tree.Load(storage, GetModeNone); err == nil { + t.Fatal("should error") + } + + if tree.Loaded() { + t.Fatal("should not be loaded") + } + + // This should get things + if err := tree.Load(storage, GetModeGet); err != nil { + t.Fatalf("err: %s", err) + } + + if !tree.Loaded() { + t.Fatal("should be loaded") + } + + // This should no longer error + if err := tree.Load(storage, GetModeNone); err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(tree.String()) + expected := strings.TrimSpace(treeLoadStr) + if actual != expected { + t.Fatalf("bad: \n\n%s", actual) + } +} + func TestTreeLoad_subdir(t *testing.T) { storage := testStorage(t) tree := NewTree("", testConfig(t, "basic-subdir"))