This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean flag added with destinations support (#14)
* Implemention of Clean flag --------- Co-authored-by: Rafal Przybyla <[email protected]> Co-authored-by: Nathaniel Ritholtz <[email protected]>
- Loading branch information
1 parent
60d1a08
commit 080cfbb
Showing
31 changed files
with
13,737 additions
and
179 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
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 |
---|---|---|
|
@@ -63,6 +63,18 @@ func TestTerraformWithTerrafilePath(t *testing.T) { | |
} { | ||
assert.Contains(t, testcli.Stdout(), output) | ||
} | ||
|
||
// Assert output does not contain the following | ||
for _, output := range []string{ | ||
"[*] Removing artifacts from ./vendor/modules", | ||
"[*] Removing artifacts from testdata/networking/vendor/modules", | ||
"[*] Removing artifacts from testdata/some-other-stack/vendor/modules", | ||
"[*] Removing artifacts from testdata/iam/vendor/modules", | ||
"[*] Removing artifacts from testdata/onboarding/vendor/modules", | ||
} { | ||
assert.NotContains(t, testcli.Stdout(), output) | ||
} | ||
|
||
// Assert folder exist with default destination | ||
for _, moduleName := range []string{ | ||
"tf-aws-vpc", | ||
|
@@ -174,6 +186,81 @@ func TestTerraformWithTerrafilePath(t *testing.T) { | |
} | ||
} | ||
|
||
func TestTerraformWithTerrafileClean(t *testing.T) { | ||
folder, back := setup(t) | ||
defer back() | ||
|
||
// Run original Terrafile with path | ||
testcli.Run(terrafileBinaryPath, "-f", fmt.Sprint(folder, "/Terrafile")) | ||
|
||
defer println(testcli.Stdout()) | ||
defer println(testcli.Stderr()) | ||
|
||
defer func() { | ||
assert.NoError(t, os.RemoveAll("testdata/")) | ||
}() | ||
|
||
// Create Terrafile2.yaml | ||
createTerrafile2(t, folder) | ||
|
||
// Run terrafile with path to Terrafile2 and clean flag | ||
testcli.Run(terrafileBinaryPath, "-f", fmt.Sprint(folder, "/Terrafile2"), "-c") | ||
|
||
// Print out output of second run | ||
defer println(testcli.Stdout()) | ||
defer println(testcli.Stderr()) | ||
|
||
if !testcli.Success() { | ||
t.Fatalf("Expected to succeed, but failed: %q with message: %q", testcli.Error(), testcli.Stderr()) | ||
} | ||
|
||
// Assert output | ||
for _, output := range []string{ | ||
"[*] Removing artifacts from ./vendor/modules", | ||
"[*] Removing artifacts from testdata/networking/vendor/modules", | ||
"[*] Removing artifacts from testdata/some-other-stack/vendor/modules", | ||
"[*] Removing artifacts from testdata/iam/vendor/modules", | ||
"[*] Removing artifacts from testdata/onboarding/vendor/modules", | ||
} { | ||
assert.Contains(t, testcli.Stdout(), output) | ||
} | ||
|
||
// Assert files exist with default destination | ||
for _, moduleName := range []string{ | ||
"tf-aws-vpc/main.tf", | ||
} { | ||
assert.FileExists(t, path.Join(workingDirectory, "vendor/modules", moduleName)) | ||
} | ||
|
||
// Assert files does not exist with default destination | ||
for _, moduleName := range []string{ | ||
"tf-aws-vpc-experimental/main.tf", | ||
} { | ||
assert.NoFileExists(t, path.Join(workingDirectory, "vendor/modules", moduleName)) | ||
} | ||
|
||
// Assert files exist with non-default destinations | ||
for _, moduleName := range []string{ | ||
"testdata/networking/vendor/modules/tf-aws-vpn-gateway/main.tf", | ||
|
||
// terraform-aws-modules/terraform-aws-iam doesn't have main.tf, as it represents set of modules | ||
// However, some terraform-aws-modules/terraform-aws-iam/modules have, e.g.: | ||
"testdata/iam/vendor/modules/tf-aws-iam/modules/iam-account/main.tf", | ||
"testdata/onboarding/vendor/modules/tf-aws-s3-bucket/main.tf", | ||
"testdata/some-other-stack/vendor/modules/tf-aws-vpn-gateway/main.tf", | ||
} { | ||
assert.FileExists(t, path.Join(workingDirectory, moduleName)) | ||
} | ||
|
||
// Assert files do not exist with non-default destinations | ||
for _, moduleName := range []string{ | ||
"testdata/networking/vendor/modules/tf-aws-s3-bucket/main.tf", | ||
"testdata/some-other-stack/vendor/modules/tf-aws-s3-bucket/main.tf", | ||
} { | ||
assert.NoFileExists(t, path.Join(workingDirectory, moduleName)) | ||
} | ||
} | ||
|
||
func setup(t *testing.T) (current string, back func()) { | ||
folder, err := os.MkdirTemp("", "") | ||
assert.NoError(t, err) | ||
|
@@ -214,3 +301,27 @@ tf-aws-s3-bucket: | |
` | ||
createFile(t, path.Join(folder, "Terrafile"), yaml) | ||
} | ||
|
||
func createTerrafile2(t *testing.T, folder string) { | ||
var yaml = `tf-aws-vpc: | ||
source: "[email protected]:terraform-aws-modules/terraform-aws-vpc" | ||
version: "v1.46.0" | ||
tf-aws-vpn-gateway: | ||
source: "[email protected]:terraform-aws-modules/terraform-aws-vpn-gateway" | ||
version: "v3.2.0" | ||
destinations: | ||
- testdata/networking | ||
- testdata/some-other-stack | ||
tf-aws-iam: | ||
source: "[email protected]:terraform-aws-modules/terraform-aws-iam" | ||
version: "v5.11.1" | ||
destinations: | ||
- testdata/iam | ||
tf-aws-s3-bucket: | ||
source: "[email protected]:terraform-aws-modules/terraform-aws-s3-bucket" | ||
version: "v3.6.1" | ||
destinations: | ||
- testdata/onboarding | ||
` | ||
createFile(t, path.Join(folder, "Terrafile2"), yaml) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.