Skip to content

Commit 68ea20e

Browse files
committedMar 13, 2019
Adding an acceptance test covering the examples
1 parent 33c2270 commit 68ea20e

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
 

‎examples/examples_test.go

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)
Please sign in to comment.