-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 #516 from gruntwork-io/cache-dir
Change how Terragrunt downloads remote Terraform configurations
- Loading branch information
Showing
7 changed files
with
133 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ vendor | |
*.tfstate | ||
*.tfstate.backup | ||
*.out | ||
.terragrunt-cache |
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
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"github.com/gruntwork-io/terragrunt/options" | ||
"github.com/gruntwork-io/terragrunt/util" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAlreadyHaveLatestCodeLocalFilePath(t *testing.T) { | ||
|
@@ -158,6 +159,54 @@ func TestDownloadTerraformSourceIfNecessaryRemoteUrlOverrideSource(t *testing.T) | |
testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, true, "# Hello, World") | ||
} | ||
|
||
func TestSplitSourceUrl(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
name string | ||
sourceUrl string | ||
expectedRootRepo string | ||
expectedModulePath string | ||
}{ | ||
{"root-path-only-no-double-slash", "/foo", "/", "foo"}, | ||
{"parent-path-one-child-no-double-slash", "/foo/bar", "/foo", "bar"}, | ||
{"parent-path-multiple-children-no-double-slash", "/foo/bar/baz/blah", "/foo/bar/baz", "blah"}, | ||
{"relative-path-no-children-no-double-slash", "../foo", "..", "foo"}, | ||
{"relative-path-one-child-no-double-slash", "../foo/bar", "../foo", "bar"}, | ||
{"relative-path-multiple-children-no-double-slash", "../foo/bar/baz/blah", "../foo/bar/baz", "blah"}, | ||
{"root-path-only-with-double-slash", "/foo//", "/foo", ""}, | ||
{"parent-path-one-child-with-double-slash", "/foo//bar", "/foo", "bar"}, | ||
{"parent-path-multiple-children-with-double-slash", "/foo/bar//baz/blah", "/foo/bar", "baz/blah"}, | ||
{"relative-path-no-children-with-double-slash", "..//foo", "..", "foo"}, | ||
{"relative-path-one-child-with-double-slash", "../foo//bar", "../foo", "bar"}, | ||
{"relative-path-multiple-children-with-double-slash", "../foo/bar//baz/blah", "../foo/bar", "baz/blah"}, | ||
{"parent-url-one-child-no-double-slash", "ssh://[email protected]:foo/modules.git/foo", "ssh://[email protected]:foo/modules.git", "foo"}, | ||
{"parent-url-multiple-children-no-double-slash", "ssh://[email protected]:foo/modules.git/foo/bar/baz/blah", "ssh://[email protected]:foo/modules.git/foo/bar/baz", "blah"}, | ||
{"parent-url-one-child-with-double-slash", "ssh://[email protected]:foo/modules.git//foo", "ssh://[email protected]:foo/modules.git", "foo"}, | ||
{"parent-url-multiple-children-with-double-slash", "ssh://[email protected]:foo/modules.git//foo/bar/baz/blah", "ssh://[email protected]:foo/modules.git", "foo/bar/baz/blah"}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
// Save a local copy in scope so all the tests don't run the final item in the loop | ||
testCase := testCase | ||
t.Run(testCase.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
sourceUrl, err := url.Parse(testCase.sourceUrl) | ||
require.NoError(t, err) | ||
|
||
terragruntOptions, err := options.NewTerragruntOptionsForTest("testing") | ||
require.NoError(t, err) | ||
|
||
actualRootRepo, actualModulePath, err := splitSourceUrl(sourceUrl, terragruntOptions) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, testCase.expectedRootRepo, actualRootRepo.String()) | ||
assert.Equal(t, testCase.expectedModulePath, actualModulePath) | ||
}) | ||
} | ||
} | ||
|
||
func testDownloadTerraformSourceIfNecessary(t *testing.T, canonicalUrl string, downloadDir string, sourceUpdate bool, expectedFileContents string) { | ||
terraformSource := &TerraformSource{ | ||
CanonicalSourceURL: parseUrl(t, canonicalUrl), | ||
|
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