2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build integration
|
2020-05-19 18:00:00 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
package envoy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2022-11-10 16:26:01 +00:00
|
|
|
dirs, err := os.ReadDir(cwd)
|
2020-10-19 21:51:38 +00:00
|
|
|
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
|
|
|
|
}
|