Skip to content

Commit

Permalink
e2e test opt
Browse files Browse the repository at this point in the history
Signed-off-by: sjcsjc123 <[email protected]>
  • Loading branch information
sjcsjc123 committed Jan 2, 2024
1 parent d5092f3 commit 048db2d
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 36 deletions.
2 changes: 1 addition & 1 deletion test/e2e/conformance/tests/go-wasm-sni-misdirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var WasmPluginsSniMisdirect = suite.ConformanceTest{
cliCertOut, cliKeyOut := cert.MustGenerateCertWithCA(t, cert.ClientCertType, caCert, caKey, nil)
fooSecret := kubernetes.ConstructTLSSecret("higress-conformance-infra", "foo-secret", svcCertOut.Bytes(), svcKeyOut.Bytes())
fooSecretCACert := kubernetes.ConstructCASecret("higress-conformance-infra", "foo-secret-cacert", caCertOut.Bytes())
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{fooSecret, fooSecretCACert}, suite.Cleanup)
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{fooSecret, fooSecretCACert}, true)

testcases := []http.Assertion{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var HTTPRouteDownstreamEncryption = suite.ConformanceTest{
cliCertOut, cliKeyOut := cert.MustGenerateCertWithCA(t, cert.ClientCertType, caCert, caKey, nil)
fooSecret := kubernetes.ConstructTLSSecret("higress-conformance-infra", "foo-secret", svcCertOut.Bytes(), svcKeyOut.Bytes())
fooSecretCACert := kubernetes.ConstructCASecret("higress-conformance-infra", "foo-secret-cacert", caCertOut.Bytes())
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{fooSecret, fooSecretCACert}, suite.Cleanup)
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{fooSecret, fooSecretCACert}, true)

testcases := []http.Assertion{
{
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/conformance/tests/httproute-https-without-sni.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var HTTPHttpsWithoutSni = suite.ConformanceTest{
_, _, caCert, caKey := cert.MustGenerateCaCert(t)
svcCertOut, svcKeyOut := cert.MustGenerateCertWithCA(t, cert.ServerCertType, caCert, caKey, []string{"foo.com"})
fooSecret := kubernetes.ConstructTLSSecret("higress-conformance-infra", "foo-secret", svcCertOut.Bytes(), svcKeyOut.Bytes())
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{fooSecret}, suite.Cleanup)
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{fooSecret}, true)

testcases := []http.Assertion{
{
Expand Down
17 changes: 8 additions & 9 deletions test/e2e/conformance/utils/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import (
)

var (
IngressClassName = flag.String("ingress-class", "higress", "Name of IngressClass to use for tests")
ShowDebug = flag.Bool("debug", false, "Whether to print debug logs")
CleanupBaseResources = flag.Bool("cleanup-base-resources", true, "Whether to cleanup base test resources after the run")
SupportedFeatures = flag.String("supported-features", "", "Supported features included in conformance tests suites")
ExemptFeatures = flag.String("exempt-features", "", "Exempt Features excluded from conformance tests suites")
IsWasmPluginTest = flag.Bool("isWasmPluginTest", false, "Determine if run wasm plugin conformance test")
WasmPluginType = flag.String("wasmPluginType", "GO", "Define wasm plugin type, currently supports GO, CPP")
WasmPluginName = flag.String("wasmPluginName", "", "Define wasm plugin name")
IsEnvoyConfigTest = flag.Bool("isEnvoyConfigTest", false, "Determine if run envoy config conformance test")
IngressClassName = flag.String("ingress-class", "higress", "Name of IngressClass to use for tests")
ShowDebug = flag.Bool("debug", false, "Whether to print debug logs")
SupportedFeatures = flag.String("supported-features", "", "Supported features included in conformance tests suites")
ExemptFeatures = flag.String("exempt-features", "", "Exempt Features excluded from conformance tests suites")
IsWasmPluginTest = flag.Bool("isWasmPluginTest", false, "Determine if run wasm plugin conformance test")
WasmPluginType = flag.String("wasmPluginType", "GO", "Define wasm plugin type, currently supports GO, CPP")
WasmPluginName = flag.String("wasmPluginName", "", "Define wasm plugin name")
IsEnvoyConfigTest = flag.Bool("isEnvoyConfigTest", false, "Determine if run envoy config conformance test")
)
39 changes: 20 additions & 19 deletions test/e2e/conformance/utils/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type ConformanceTestSuite struct {
GatewayAddress string
IngressClassName string
Debug bool
Cleanup bool
BaseManifests []string
Applier kubernetes.Applier
SkipTests sets.Set
Expand All @@ -56,10 +55,7 @@ type Options struct {
// Options for wasm extended features
WASMOptions

// CleanupBaseResources indicates whether or not the base test
// resources such as Gateways should be cleaned up after the run.
CleanupBaseResources bool
TimeoutConfig config.TimeoutConfig
TimeoutConfig config.TimeoutConfig

// IsEnvoyConfigTest indicates whether or not the test is for envoy config
IsEnvoyConfigTest bool
Expand Down Expand Up @@ -105,7 +101,6 @@ func New(s Options) *ConformanceTestSuite {
RoundTripper: roundTripper,
IngressClassName: s.IngressClassName,
Debug: s.Debug,
Cleanup: s.CleanupBaseResources,
BaseManifests: s.BaseManifests,
SupportedFeatures: s.SupportedFeatures,
GatewayAddress: s.GatewayAddress,
Expand All @@ -126,28 +121,28 @@ func New(s Options) *ConformanceTestSuite {
}
}

suite.Applier.IngressClass = suite.IngressClassName

return suite
}

// Setup ensures the base resources required for conformance tests are installed
// in the cluster. It also ensures that all relevant resources are ready.
func (suite *ConformanceTestSuite) Setup(t *testing.T) {
t.Logf("📦 Test Setup: Ensuring IngressClass has been accepted")

suite.Applier.IngressClass = suite.IngressClassName

t.Logf("📦 Test Setup: Applying base manifests")
func (suite *ConformanceTestSuite) Prepare(t *testing.T) {
t.Logf("📦 Test Prepare: Applying base manifests")

for _, baseManifest := range suite.BaseManifests {
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, baseManifest, suite.Cleanup)
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, baseManifest, false)
}

t.Logf("📦 Test Setup: Applying programmatic resources")
t.Logf("📦 Test Prepare: Applying programmatic resources")
secret := kubernetes.MustCreateSelfSignedCertSecret(t, "higress-conformance-web-backend", "certificate", []string{"*"})
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{secret}, suite.Cleanup)
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{secret}, false)
secret = kubernetes.MustCreateSelfSignedCertSecret(t, "higress-conformance-infra", "tls-validity-checks-certificate", []string{"*"})
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{secret}, suite.Cleanup)
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{secret}, false)
}

// Setup ensures the base resources required for conformance tests are installed
// in the cluster. It also ensures that all relevant resources are ready.
func (suite *ConformanceTestSuite) Setup(t *testing.T) {
t.Logf("📦 Test Setup: Ensuring Pods from base manifests are ready")
namespaces := []string{
"higress-conformance-infra",
Expand All @@ -159,7 +154,7 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T) {
t.Logf("🌱 Supported Features: %+v", suite.SupportedFeatures.UnsortedList())
}

// RunWithTests runs the provided set of conformance tests.
// Run runs the provided set of conformance tests.
func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) {
t.Logf("🚀 Start Running %d Test Cases: \n\n%s", len(tests), globalConformanceTestsListInfo(tests))
for _, test := range tests {
Expand All @@ -169,6 +164,12 @@ func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) {
}
}

func (suite *ConformanceTestSuite) Clean(t *testing.T) {
for _, baseManifest := range suite.BaseManifests {
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, baseManifest, true)
}
}

func globalConformanceTestsListInfo(tests []ConformanceTest) string {
var cases string
for index, test := range tests {
Expand Down
65 changes: 60 additions & 5 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/alibaba/higress/test/e2e/conformance/utils/suite"
)

func TestHigressConformanceTests(t *testing.T) {
func TestPrepareHigressConformanceTests(t *testing.T) {
flag.Parse()

cfg, err := config.GetConfig()
Expand All @@ -40,10 +40,37 @@ func TestHigressConformanceTests(t *testing.T) {
require.NoError(t, v1.AddToScheme(client.Scheme()))

cSuite := suite.New(suite.Options{
Client: client,
IngressClassName: *flags.IngressClassName,
Debug: *flags.ShowDebug,
CleanupBaseResources: *flags.CleanupBaseResources,
Client: client,
IngressClassName: *flags.IngressClassName,
Debug: *flags.ShowDebug,
WASMOptions: suite.WASMOptions{
IsWasmPluginTest: *flags.IsWasmPluginTest,
WasmPluginName: *flags.WasmPluginName,
WasmPluginType: *flags.WasmPluginType,
},
GatewayAddress: "localhost",
EnableAllSupportedFeatures: true,
IsEnvoyConfigTest: *flags.IsEnvoyConfigTest,
})

cSuite.Prepare(t)
}

func TestRunHigressConformanceTests(t *testing.T) {
flag.Parse()

cfg, err := config.GetConfig()
require.NoError(t, err)

client, err := client.New(cfg, client.Options{})
require.NoError(t, err)

require.NoError(t, v1.AddToScheme(client.Scheme()))

cSuite := suite.New(suite.Options{
Client: client,
IngressClassName: *flags.IngressClassName,
Debug: *flags.ShowDebug,
WASMOptions: suite.WASMOptions{
IsWasmPluginTest: *flags.IsWasmPluginTest,
WasmPluginName: *flags.WasmPluginName,
Expand All @@ -57,3 +84,31 @@ func TestHigressConformanceTests(t *testing.T) {
cSuite.Setup(t)
cSuite.Run(t, tests.ConformanceTests)
}

func TestCleanHigressConformanceTests(t *testing.T) {
flag.Parse()

cfg, err := config.GetConfig()
require.NoError(t, err)

client, err := client.New(cfg, client.Options{})
require.NoError(t, err)

require.NoError(t, v1.AddToScheme(client.Scheme()))

cSuite := suite.New(suite.Options{
Client: client,
IngressClassName: *flags.IngressClassName,
Debug: *flags.ShowDebug,
WASMOptions: suite.WASMOptions{
IsWasmPluginTest: *flags.IsWasmPluginTest,
WasmPluginName: *flags.WasmPluginName,
WasmPluginType: *flags.WasmPluginType,
},
GatewayAddress: "localhost",
EnableAllSupportedFeatures: true,
IsEnvoyConfigTest: *flags.IsEnvoyConfigTest,
})

cSuite.Clean(t)
}

0 comments on commit 048db2d

Please sign in to comment.