2020-05-19 18:00:00 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
package envoy
|
|
|
|
|
|
|
|
import (
|
2020-10-19 21:51:38 +00:00
|
|
|
"io/ioutil"
|
2020-05-19 18:00:00 +00:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2020-10-19 21:51:38 +00:00
|
|
|
"sort"
|
|
|
|
"strings"
|
2020-05-19 18:00:00 +00:00
|
|
|
"testing"
|
2020-10-19 21:51:38 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-05-19 18:00:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEnvoy(t *testing.T) {
|
2020-10-19 21:51:38 +00:00
|
|
|
testcases, err := discoverCases()
|
|
|
|
require.NoError(t, err)
|
2020-05-19 18:00:00 +00:00
|
|
|
|
|
|
|
runCmd(t, "suite_setup")
|
|
|
|
defer runCmd(t, "suite_teardown")
|
|
|
|
|
|
|
|
for _, tc := range testcases {
|
|
|
|
t.Run(tc, func(t *testing.T) {
|
2020-06-02 23:24:52 +00:00
|
|
|
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)
|
2020-05-19 18:00:00 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2020-10-19 21:51:38 +00:00
|
|
|
|
|
|
|
// 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 := ioutil.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
|
|
|
|
}
|