terraform-azure/test/e2e/quickstart_test.go
2023-02-04 20:12:13 +08:00

56 lines
1.1 KiB
Go

package e2e
import (
"github.com/gruntwork-io/terratest/modules/files"
"os"
"path/filepath"
"strings"
"testing"
helper "github.com/Azure/terraform-module-test-helper"
"github.com/gruntwork-io/terratest/modules/terraform"
)
func Test_Quickstarts(t *testing.T) {
input := os.Getenv("CHANGED_FOLDERS")
folders := strings.Split(input, ",")
if input == "" {
var err error
folders, err = allExamples()
if err != nil {
t.Fatalf(err.Error())
}
}
for _, f := range folders {
f = strings.TrimSpace(f)
if filepath.Dir(f) != "quickstart" {
continue
}
rootPath := filepath.Join("..", "..")
path := filepath.Join(rootPath, f)
if !files.IsExistingDir(path) {
continue
}
t.Run(f, func(t *testing.T) {
helper.RunE2ETest(t, rootPath, f, terraform.Options{
Upgrade: true,
}, nil)
})
}
}
func allExamples() ([]string, error) {
examples, err := os.ReadDir("../../quickstart")
if err != nil {
return nil, err
}
var r []string
for _, f := range examples {
if !f.IsDir() {
continue
}
r = append(r, filepath.Join("quickstart", f.Name()))
}
return r, nil
}