-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16487 from hashicorp/jbardin/from-module
init -from-module
- Loading branch information
Showing
3 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,49 @@ | ||
package module | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestGetModule(t *testing.T) { | ||
server := mockRegistry() | ||
defer server.Close() | ||
disco := testDisco(server) | ||
|
||
td, err := ioutil.TempDir("", "tf") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(td) | ||
storage := NewStorage(td, disco, nil) | ||
|
||
// this module exists in a test fixture, and is known by the mockRegistry | ||
// relative to our cwd. | ||
err = storage.GetModule(filepath.Join(td, "foo"), "registry/local/sub") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// list everything to make sure nothing else got unpacked in here | ||
ls, err := ioutil.ReadDir(td) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var names []string | ||
for _, info := range ls { | ||
names = append(names, info.Name()) | ||
} | ||
|
||
if !(len(names) == 1 && names[0] == "foo") { | ||
t.Fatalf("expected only directory 'foo', found entries %q", names) | ||
} | ||
|
||
_, err = os.Stat(filepath.Join(td, "foo", "main.tf")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
} |