Skip to content

Commit f196489

Browse files
Update to add test ensuring remote modules are cached
1 parent d4fedda commit f196489

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

parse_test.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import (
1919
)
2020

2121
func setupParser(t *testing.T, options ...*ParserOptions) *Parser {
22-
os.Setenv("SHIPYARD_CONFIG", "/User/yamcha/.shipyard")
22+
home := os.Getenv("HOME")
23+
os.Setenv("HOME", t.TempDir())
2324

2425
t.Cleanup(func() {
25-
os.Unsetenv("SHIPYARD_CONFIG")
26+
os.Setenv("HOME", home)
2627
})
2728

2829
o := DefaultOptions()
@@ -385,6 +386,25 @@ func TestParseModuleCreatesResources(t *testing.T) {
385386

386387
}
387388

389+
func TestParseModuleDoesNotCacheLocalFiles(t *testing.T) {
390+
absoluteFolderPath, err := filepath.Abs("./test_fixtures/modules/modules.hcl")
391+
if err != nil {
392+
t.Fatal(err)
393+
}
394+
395+
p := setupParser(t)
396+
397+
c, err := p.ParseFile(absoluteFolderPath)
398+
require.NoError(t, err)
399+
require.NotNil(t, c)
400+
401+
// the remote module should be cached
402+
require.DirExists(t, filepath.Join(p.options.ModuleCache, "github.com_jumppad-labs_hclconfig_test_fixtures_single"))
403+
404+
// the local module should not be cached
405+
require.NoDirExists(t, filepath.Join(p.options.ModuleCache, "single"))
406+
}
407+
388408
func TestParseModuleCreatesOutputs(t *testing.T) {
389409
absoluteFolderPath, err := filepath.Abs("./test_fixtures/modules/modules.hcl")
390410
if err != nil {

test_fixtures/modules/modules.hcl

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ module "consul_2" {
3333
}
3434
}
3535

36+
// ensure that this module is from a remote source
3637
module "consul_3" {
3738
// all resources in this module will only be created after all the
3839
// resources in 'consul_1' have been created.
3940
depends_on = ["module.consul_1"]
40-
source = "../single"
41+
source = "github.com/jumppad-labs/hclconfig/test_fixtures//single"
4142
}
4243

4344
output "object" {

0 commit comments

Comments
 (0)