Skip to content

Commit

Permalink
fix ci
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 89c7277 commit c481798
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 29 deletions.
16 changes: 16 additions & 0 deletions Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,30 @@ include tools/lint.mk
.PHONY: gateway-conformance-test
gateway-conformance-test:

# higress-conformance-test-prepare prepares the environment for higress conformance tests.
.PHONY: higress-conformance-test-prepare
higress-conformance-test-prepare: $(tools/kind) delete-cluster create-cluster docker-build kube-load-image install-dev

# higress-conformance-test runs ingress api conformance tests.
.PHONY: higress-conformance-test
higress-conformance-test: $(tools/kind) delete-cluster create-cluster docker-build kube-load-image install-dev run-higress-e2e-test delete-cluster

# higress-conformance-test-clean cleans the environment for higress conformance tests.
.PHONY: higress-conformance-test-clean
higress-conformance-test-clean: $(tools/kind) delete-cluster

# higress-wasmplugin-test-prepare prepares the environment for higress wasmplugin tests.
.PHONY: higress-wasmplugin-test-prepare
higress-wasmplugin-test-prepare: $(tools/kind) delete-cluster create-cluster docker-build kube-load-image install-dev-wasmplugin

# higress-wasmplugin-test runs ingress wasmplugin tests.
.PHONY: higress-wasmplugin-test
higress-wasmplugin-test: $(tools/kind) delete-cluster create-cluster docker-build kube-load-image install-dev-wasmplugin run-higress-e2e-test-wasmplugin delete-cluster

# higress-wasmplugin-test-clean cleans the environment for higress wasmplugin tests.
.PHONY: higress-wasmplugin-test-clean
higress-wasmplugin-test-clean: $(tools/kind) delete-cluster

# create-cluster creates a kube cluster with kind.
.PHONY: create-cluster
create-cluster: $(tools/kind)
Expand Down
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")
)
2 changes: 1 addition & 1 deletion test/e2e/conformance/utils/kubernetes/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (a Applier) MustDelete(t *testing.T, c client.Client, timeoutConfig config.
// }
// }

t.Logf("🏗 Deleting %s %s %s", uObj.GetName(), uObj.GetKind(), uObj.GetNamespace())
t.Logf("🚮 Deleting %s %s %s", uObj.GetName(), uObj.GetKind(), uObj.GetNamespace())
err = c.Delete(ctx, uObj)
require.NoErrorf(t, err, "error delete resource")
}
Expand Down
22 changes: 12 additions & 10 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 Down Expand Up @@ -139,14 +134,14 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T) {
t.Logf("📦 Test Setup: 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")
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)

t.Logf("📦 Test Setup: Ensuring Pods from base manifests are ready")
namespaces := []string{
Expand All @@ -159,16 +154,23 @@ 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))
suite.Applier.IngressClass = suite.IngressClassName
for _, test := range tests {
t.Run(test.ShortName, func(t *testing.T) {
test.Run(t, suite)
})
}
}

// Cleanup ensures that all resources created by the test suite are cleaned up.
func (suite *ConformanceTestSuite) Cleanup(t *testing.T) {
t.Logf("🧹 Test Cleanup: Ensuring all resources are cleaned up")
suite.Applier.MustDelete(t, suite.Client, suite.TimeoutConfig, "base/manifests.yaml")
}

func globalConformanceTestsListInfo(tests []ConformanceTest) string {
var cases string
for index, test := range tests {
Expand Down
66 changes: 60 additions & 6 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ package test

import (
"flag"
"github.com/alibaba/higress/test/e2e/conformance/tests"
"testing"

"github.com/stretchr/testify/require"
v1 "k8s.io/api/networking/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"

"github.com/alibaba/higress/test/e2e/conformance/tests"
"github.com/alibaba/higress/test/e2e/conformance/utils/flags"
"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,9 @@ 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,
Expand All @@ -55,5 +54,60 @@ func TestHigressConformanceTests(t *testing.T) {
})

cSuite.Setup(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,
WasmPluginType: *flags.WasmPluginType,
},
GatewayAddress: "localhost",
EnableAllSupportedFeatures: true,
IsEnvoyConfigTest: *flags.IsEnvoyConfigTest,
})

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.Cleanup(t)
}

0 comments on commit c481798

Please sign in to comment.