|
| 1 | +package examples |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log" |
| 6 | + "os" |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/tombuildsstuff/terraform-configuration-tester/locator" |
| 11 | + "github.com/tombuildsstuff/terraform-configuration-tester/runner" |
| 12 | +) |
| 13 | + |
| 14 | +func TestRunExamples(t *testing.T) { |
| 15 | + if os.Getenv("TF_EXAMPLE_TEST") == "" { |
| 16 | + log.Printf("`TF_EXAMPLE_TEST` is not set - skipping") |
| 17 | + t.Skip() |
| 18 | + } |
| 19 | + |
| 20 | + examplesDirectory := "./" |
| 21 | + directories := locator.DiscoverExamples(examplesDirectory) |
| 22 | + |
| 23 | + input := runner.TestRunInput{ |
| 24 | + // TODO: from Environment Variables in the future |
| 25 | + ProviderVersion: "1.23.0", |
| 26 | + ProviderName: "azurerm", |
| 27 | + TerraformVersion: "0.11.13", |
| 28 | + AvailableVariables: []runner.AvailableVariable{ |
| 29 | + { |
| 30 | + Name: "prefix", |
| 31 | + Generate: true, |
| 32 | + }, |
| 33 | + { |
| 34 | + Name: "location", |
| 35 | + EnvKeyName: "ARM_LOCATION", |
| 36 | + }, |
| 37 | + { |
| 38 | + Name: "alt_location", |
| 39 | + EnvKeyName: "ARM_LOCATION_ALT", |
| 40 | + }, |
| 41 | + { |
| 42 | + Name: "kubernetes_client_id", |
| 43 | + EnvKeyName: "ARM_CLIENT_ID", |
| 44 | + }, |
| 45 | + { |
| 46 | + Name: "kubernetes_client_secret", |
| 47 | + EnvKeyName: "ARM_CLIENT_SECRET", |
| 48 | + }, |
| 49 | + }, |
| 50 | + } |
| 51 | + |
| 52 | + for _, directoryPath := range directories { |
| 53 | + shortDirName := strings.Replace(directoryPath, examplesDirectory, "", -1) |
| 54 | + testName := fmt.Sprintf("examples/%s", shortDirName) |
| 55 | + t.Run(testName, func(t *testing.T) { |
| 56 | + if err := input.Run(directoryPath); err != nil { |
| 57 | + t.Fatalf("Error running %q: %s", shortDirName, err) |
| 58 | + } |
| 59 | + }) |
| 60 | + } |
| 61 | +} |
0 commit comments