-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
37 lines (31 loc) · 1.41 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package helpers
import (
"fmt"
"os"
"path/filepath"
"testing"
"github.com/gruntwork-io/terratest/modules/files"
"github.com/gruntwork-io/terratest/modules/terraform"
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/assert"
)
func DefaultOptions(t *testing.T, terraformOptions *terraform.Options) *terraform.Options {
// Check if a variable file with the name of the current test exists and use it
currentTestVarFile := filepath.Join("variables", fmt.Sprintf("%s.tfvars", t.Name()))
if files.FileExists(currentTestVarFile) {
terraformOptions.VarFiles = append(terraformOptions.VarFiles, filepath.Join("test", currentTestVarFile))
}
// By default, our terraform module is in the git repository root and our tests in the 'test' directory
// Therefore, the we set the TerraformDir to ".." if none is specified explicitly
if terraformOptions.TerraformDir == "" {
path, err := os.Getwd()
if err != nil {
assert.FailNow(t, "Could not get current working directory, aborting test")
}
terraformOptions.TerraformDir = filepath.Join(path, "../")
}
// This enables parallel testing by ensuring that every TerraformDir lives in its own temporary path
tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, terraformOptions.TerraformDir, ".")
terraformOptions.TerraformDir = tempTestFolder
return terraform.WithDefaultRetryableErrors(t, terraformOptions)
}