Skip to content

Commit

Permalink
Moved tests cases into examples directory
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomimatichin committed Mar 16, 2021
1 parent a923bc3 commit 655214c
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.terraform.lock.hcl
.terraform/
terraform.tfstate
terraform.tfstate.backup
crash.log
terraform.rc
fake_registry
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions tests/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func runTest(testName string, destroy bool) bool {
}

func readExpectedOutputs(testName string) (map[string]string, error) {
expectedBytes, err := ioutil.ReadFile(path.Join("tests", testName, "expected_outputs.json"))
expectedBytes, err := ioutil.ReadFile(path.Join("examples", testName, "expected_outputs.json"))
if err != nil {
log.Println("Test folder for ", testName, " does not contain expected_outputs.json", err)
return nil, err
Expand Down Expand Up @@ -125,14 +125,14 @@ func bytesOfJsonToStringMap(data []byte) (map[string]string, error) {
func terraformDestory(testName string) {
log.Println("Running destroy to clean up in", testName)
destroy := exec.Command("terraform", "destroy", "-auto-approve")
destroy.Dir = "tests/" + testName
destroy.Dir = "examples/" + testName
destroy.CombinedOutput()
log.Println("Done running terraform destroy in", testName)
}

func terraformCommand(testName string, arg ...string) ([]byte, error) {
cmd := exec.Command("terraform", arg...)
cmd.Dir = "tests/" + testName
cmd.Dir = "examples/" + testName
log.Println("Running terraform ", arg, " in ", testName)
outputBytes, err := cmd.CombinedOutput()
output := string(outputBytes)
Expand Down Expand Up @@ -162,16 +162,16 @@ func testNamesFromCommandLineArguments() []string {
testNames := []string{}
if len(os.Args) > 1 {
for _, testName := range os.Args[1:] {
if strings.HasPrefix(testName, "tests/") {
testName = testName[len("tests/"):]
if strings.HasPrefix(testName, "examples/") {
testName = testName[len("examples/"):]
}
if strings.HasSuffix(testName, "/") {
testName = testName[:len(testName)-1]
}
testNames = append(testNames, testName)
}
} else {
allFilesUnderTests, err := ioutil.ReadDir("tests")
allFilesUnderTests, err := ioutil.ReadDir("examples")
if err != nil {
log.Fatalln("Unable to list 'tests' folder", err)
}
Expand Down

0 comments on commit 655214c

Please sign in to comment.