add tests for get from tar subdir

Test that we can get a subdirectory from a tarball (or any other
"packed" source that we support).

The 'tar-subdir-to-parent' test highlights a regression where the
subdirectory module references a module in its parent directory. This
breaks the intended use ofr the subdirectory and the implementation in
go-getter. We need to fix this in terraform, and possible plan warnings
and deprecations for this type of source.
This commit is contained in:
James Bardin 2017-09-21 13:06:47 -05:00
parent f846beecbc
commit 38569c8508
5 changed files with 44 additions and 27 deletions

Binary file not shown.

View File

@ -0,0 +1,3 @@
module "foo" {
source = "./foo.tgz//sub"
}

View File

@ -0,0 +1,4 @@
module "foo" {
// the module in sub references sibling module baz via "../baz"
source = "./foo.tgz//sub"
}

View File

@ -209,40 +209,50 @@ func TestTreeLoad_parentRef(t *testing.T) {
} }
func TestTreeLoad_subdir(t *testing.T) { func TestTreeLoad_subdir(t *testing.T) {
storage := testStorage(t) fixtures := []string{
tree := NewTree("", testConfig(t, "basic-subdir")) "basic-subdir",
"basic-tar-subdir",
if tree.Loaded() { "tar-sbudir-to-parent",
t.Fatal("should not be loaded")
} }
// This should error because we haven't gotten things yet for _, tc := range fixtures {
if err := tree.Load(storage, GetModeNone); err == nil { t.Run(tc, func(t *testing.T) {
t.Fatal("should error") storage := testStorage(t)
} tree := NewTree("", testConfig(t, tc))
if tree.Loaded() { if tree.Loaded() {
t.Fatal("should not be loaded") t.Fatal("should not be loaded")
} }
// This should get things // This should error because we haven't gotten things yet
if err := tree.Load(storage, GetModeGet); err != nil { if err := tree.Load(storage, GetModeNone); err == nil {
t.Fatalf("err: %s", err) t.Fatal("should error")
} }
if !tree.Loaded() { if tree.Loaded() {
t.Fatal("should be loaded") t.Fatal("should not be loaded")
} }
// This should no longer error // This should get things
if err := tree.Load(storage, GetModeNone); err != nil { if err := tree.Load(storage, GetModeGet); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
actual := strings.TrimSpace(tree.String()) if !tree.Loaded() {
expected := strings.TrimSpace(treeLoadSubdirStr) t.Fatal("should be loaded")
if actual != expected { }
t.Fatalf("bad: \n\n%s", actual)
// 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(treeLoadSubdirStr)
if actual != expected {
t.Fatalf("bad: \n\n%s", actual)
}
})
} }
} }