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