open-consul/test/integration/connect/envoy/main_test.go
Kyle Schochenmaier 2b1e5f69e2
removes ioutil usage everywhere which was deprecated in go1.16 (#15297)
* update go version to 1.18 for api and sdk, go mod tidy
* removes ioutil usage everywhere which was deprecated in go1.16 in favour of io and os packages. Also introduces a lint rule which forbids use of ioutil going forward.
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
2022-11-10 10:26:01 -06:00

74 lines
1.3 KiB
Go

//go:build integration
// +build integration
package envoy
import (
"os"
"os/exec"
"sort"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestEnvoy(t *testing.T) {
testcases, err := discoverCases()
require.NoError(t, err)
runCmd(t, "suite_setup")
defer runCmd(t, "suite_teardown")
for _, tc := range testcases {
t.Run(tc, func(t *testing.T) {
caseDir := "CASE_DIR=" + tc
t.Cleanup(func() {
if t.Failed() {
runCmd(t, "capture_logs", caseDir)
}
runCmd(t, "test_teardown", caseDir)
})
runCmd(t, "run_tests", caseDir)
})
}
}
func runCmd(t *testing.T, c string, env ...string) {
t.Helper()
cmd := exec.Command("./run-tests.sh", c)
cmd.Env = append(os.Environ(), env...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
t.Fatalf("command failed: %v", err)
}
}
// Discover the cases so we pick up both oss and ent copies.
func discoverCases() ([]string, error) {
cwd, err := os.Getwd()
if err != nil {
return nil, err
}
dirs, err := os.ReadDir(cwd)
if err != nil {
return nil, err
}
var out []string
for _, fi := range dirs {
if fi.IsDir() && strings.HasPrefix(fi.Name(), "case-") {
out = append(out, fi.Name())
}
}
sort.Strings(out)
return out, nil
}