Skip empty example (#270)
* skip empty examples that contain no tf files * refactor code
This commit is contained in:
parent
161494719e
commit
72c7e787ec
@ -1,15 +1,17 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"github.com/gruntwork-io/terratest/modules/files"
|
||||
"github.com/gruntwork-io/terratest/modules/packer"
|
||||
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
|
||||
"github.com/stretchr/testify/require"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gruntwork-io/terratest/modules/files"
|
||||
"github.com/gruntwork-io/terratest/modules/packer"
|
||||
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
helper "github.com/Azure/terraform-module-test-helper"
|
||||
"github.com/gruntwork-io/terratest/modules/terraform"
|
||||
)
|
||||
@ -35,14 +37,11 @@ func Test_Quickstarts(t *testing.T) {
|
||||
folders = removeDuplicates(folders)
|
||||
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) {
|
||||
if skip(rootPath, f) {
|
||||
continue
|
||||
}
|
||||
|
||||
test, ok := speicalTests[f]
|
||||
if !ok {
|
||||
test = func(t *testing.T) {
|
||||
@ -63,14 +62,35 @@ func allExamples() ([]string, error) {
|
||||
}
|
||||
var r []string
|
||||
for _, f := range examples {
|
||||
if !f.IsDir() {
|
||||
continue
|
||||
}
|
||||
r = append(r, filepath.Join("quickstart", f.Name()))
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func skip(rootPath string, f string) bool {
|
||||
f = filepath.Join(rootPath, f)
|
||||
if !files.IsExistingDir(f) {
|
||||
return true
|
||||
}
|
||||
if !strings.HasSuffix(filepath.Dir(f), fmt.Sprintf("%squickstart", string(os.PathSeparator))) {
|
||||
return true
|
||||
}
|
||||
return !containsTerraformFile(f)
|
||||
}
|
||||
|
||||
func containsTerraformFile(f string) bool {
|
||||
dir, err := os.ReadDir(f)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, entry := range dir {
|
||||
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".tf") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func test201VmssPackerJumpbox(t *testing.T) {
|
||||
examplePath := filepath.Join("..", "..", "quickstart", "201-vmss-packer-jumpbox")
|
||||
examplePath = test_structure.CopyTerraformFolderToTemp(t, examplePath, "")
|
||||
|
Loading…
x
Reference in New Issue
Block a user