From 601701dd26a55fc03c33d0af830c58ace6019ddb Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Thu, 27 Feb 2025 19:55:32 -0600 Subject: [PATCH] fix httpendpoint tests cleanup and checks Signed-off-by: Anton Troshin --- tests/e2e/common/common.go | 19 +++++++++------ tests/e2e/upgrade/upgrade_test.go | 39 ++++++++++++++----------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/e2e/common/common.go b/tests/e2e/common/common.go index 6c07efff8..7d05a4a03 100644 --- a/tests/e2e/common/common.go +++ b/tests/e2e/common/common.go @@ -213,7 +213,7 @@ func GetTestsOnInstall(details VersionDetails, opts TestOptions) []TestCase { {"clusterroles exist " + details.RuntimeVersion, ClusterRolesTest(details, opts)}, {"clusterrolebindings exist " + details.RuntimeVersion, ClusterRoleBindingsTest(details, opts)}, {"apply and check components exist " + details.RuntimeVersion, ComponentsTestOnInstallUpgrade(opts)}, - {"apply and check httpendpoints exist " + details.RuntimeVersion, HTTPEndpointsTestOnInstallUpgrade(opts)}, + {"apply and check httpendpoints exist " + details.RuntimeVersion, HTTPEndpointsTestOnInstallUpgrade(opts, TestOptions{})}, {"check mtls " + details.RuntimeVersion, MTLSTestOnInstallUpgrade(opts)}, {"status check " + details.RuntimeVersion, StatusTestOnInstallUpgrade(details, opts)}, } @@ -341,10 +341,10 @@ func ComponentsTestOnInstallUpgrade(opts TestOptions) func(t *testing.T) { } } -func HTTPEndpointsTestOnInstallUpgrade(opts TestOptions) func(t *testing.T) { +func HTTPEndpointsTestOnInstallUpgrade(installOpts TestOptions, upgradeOpts TestOptions) func(t *testing.T) { return func(t *testing.T) { // if dapr is installed with httpendpoints. - if opts.ApplyHTTPEndpointChanges { + if installOpts.ApplyHTTPEndpointChanges { // apply any changes to the httpendpoint. t.Log("apply httpendpoint changes") output, err := spawn.Command("kubectl", "apply", "-f", "../testdata/namespace.yaml") @@ -353,12 +353,17 @@ func HTTPEndpointsTestOnInstallUpgrade(opts TestOptions) func(t *testing.T) { output, err = spawn.Command("kubectl", "apply", "-f", "../testdata/httpendpoint.yaml") t.Log(output) require.NoError(t, err, "expected no error on kubectl apply") - require.Equal(t, "httpendpoints.dapr.io/httpendpoint created\nhttpendpoints.dapr.io/httpendpoint created\n", output, "expected output to match") - httpEndpointOutputCheck(t, output) + + if installOpts.ApplyHTTPEndpointChanges && upgradeOpts.ApplyHTTPEndpointChanges { + require.Equal(t, "httpendpoint.dapr.io/httpendpoint unchanged\n", output, "expected output to match") + } else { + require.Equal(t, "httpendpoint.dapr.io/httpendpoint created\n", output, "expected output to match") + } t.Log("check applied httpendpoint exists") - _, err = spawn.Command("kubectl", "get", "httpendpoint") + output, err = spawn.Command("kubectl", "get", "httpendpoint") require.NoError(t, err, "expected no error on calling to retrieve httpendpoints") + httpEndpointOutputCheck(t, output) } } } @@ -984,7 +989,7 @@ func componentOutputCheck(t *testing.T, opts TestOptions, output string) { return } - lines = strings.Split(output, "\n")[2:] // remove header and warning message. + lines = lines[2:] // remove header and warning message. if opts.DevEnabled { // default, test statestore. diff --git a/tests/e2e/upgrade/upgrade_test.go b/tests/e2e/upgrade/upgrade_test.go index ff67267f4..58b714c6c 100644 --- a/tests/e2e/upgrade/upgrade_test.go +++ b/tests/e2e/upgrade/upgrade_test.go @@ -44,7 +44,7 @@ var supportedUpgradePaths = []upgradePath{ DashboardVersion: "0.15.0", ClusterRoles: []string{"dapr-dashboard", "dapr-injector", "dapr-operator-admin", "dapr-placement", "dapr-sentry"}, ClusterRoleBindings: []string{"dapr-operator-admin", "dapr-dashboard", "dapr-injector", "dapr-placement", "dapr-sentry"}, - CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io"}, + CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io", "httpendpoints.dapr.io"}, }, }, { @@ -53,14 +53,14 @@ var supportedUpgradePaths = []upgradePath{ DashboardVersion: "0.14.0", ClusterRoles: []string{"dapr-dashboard", "dapr-injector", "dapr-operator-admin", "dapr-placement", "dapr-sentry"}, ClusterRoleBindings: []string{"dapr-operator-admin", "dapr-dashboard", "dapr-injector", "dapr-placement", "dapr-sentry"}, - CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io"}, + CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io", "httpendpoints.dapr.io"}, }, next: common.VersionDetails{ RuntimeVersion: "1.14.4", DashboardVersion: "0.14.0", ClusterRoles: []string{"dapr-dashboard", "dapr-injector", "dapr-operator-admin", "dapr-placement", "dapr-sentry"}, ClusterRoleBindings: []string{"dapr-operator-admin", "dapr-dashboard", "dapr-injector", "dapr-placement", "dapr-sentry"}, - CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io"}, + CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io", "httpendpoints.dapr.io"}, }, }, { @@ -69,14 +69,14 @@ var supportedUpgradePaths = []upgradePath{ DashboardVersion: "0.14.0", ClusterRoles: []string{"dapr-dashboard", "dapr-injector", "dapr-operator-admin", "dapr-placement", "dapr-sentry"}, ClusterRoleBindings: []string{"dapr-operator-admin", "dapr-dashboard", "dapr-injector", "dapr-placement", "dapr-sentry"}, - CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io"}, + CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io", "httpendpoints.dapr.io"}, }, next: common.VersionDetails{ RuntimeVersion: "1.15.0", DashboardVersion: "0.14.0", ClusterRoles: []string{"dapr-dashboard", "dapr-injector", "dapr-operator-admin", "dapr-placement", "dapr-sentry"}, ClusterRoleBindings: []string{"dapr-operator-admin", "dapr-dashboard", "dapr-injector", "dapr-placement", "dapr-sentry"}, - CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io"}, + CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io", "httpendpoints.dapr.io"}, }, }, { @@ -160,7 +160,7 @@ func getTestsOnUpgrade(p upgradePath, installOpts, upgradeOpts common.TestOption {Name: "clusterroles exist " + details.RuntimeVersion, Callable: common.ClusterRolesTest(details, upgradeOpts)}, {Name: "clusterrolebindings exist " + details.RuntimeVersion, Callable: common.ClusterRoleBindingsTest(details, upgradeOpts)}, {Name: "previously applied components exist " + details.RuntimeVersion, Callable: common.ComponentsTestOnInstallUpgrade(upgradeOpts)}, - {Name: "previously applied http endpoints exist " + details.RuntimeVersion, Callable: common.HTTPEndpointsTestOnInstallUpgrade(upgradeOpts)}, + {Name: "previously applied http endpoints exist " + details.RuntimeVersion, Callable: common.HTTPEndpointsTestOnInstallUpgrade(installOpts, upgradeOpts)}, {Name: "check mtls " + details.RuntimeVersion, Callable: common.MTLSTestOnInstallUpgrade(upgradeOpts)}, {Name: "status check " + details.RuntimeVersion, Callable: common.StatusTestOnInstallUpgrade(details, upgradeOpts)}, }...) @@ -188,14 +188,13 @@ func getTestsOnUpgrade(p upgradePath, installOpts, upgradeOpts common.TestOption func TestUpgradePathNonHAModeMTLSDisabled(t *testing.T) { // Ensure a clean environment. common.EnsureUninstall(false, false) // does not wait for pod deletion. + for _, p := range supportedUpgradePaths { t.Run(fmt.Sprintf("setup v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { t.Run(deleteCRDs+p.previous.RuntimeVersion, common.DeleteCRD(p.previous.CustomResourceDefs)) t.Run(deleteCRDs+p.next.RuntimeVersion, common.DeleteCRD(p.next.CustomResourceDefs)) }) - } - for _, p := range supportedUpgradePaths { t.Run(fmt.Sprintf("v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { installOpts := common.TestOptions{ HAEnabled: false, @@ -233,14 +232,13 @@ func TestUpgradePathNonHAModeMTLSDisabled(t *testing.T) { func TestUpgradePathNonHAModeMTLSEnabled(t *testing.T) { // Ensure a clean environment. common.EnsureUninstall(false, false) // does not wait for pod deletion. + for _, p := range supportedUpgradePaths { t.Run(fmt.Sprintf("setup v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { t.Run(deleteCRDs+p.previous.RuntimeVersion, common.DeleteCRD(p.previous.CustomResourceDefs)) t.Run(deleteCRDs+p.next.RuntimeVersion, common.DeleteCRD(p.next.CustomResourceDefs)) }) - } - for _, p := range supportedUpgradePaths { t.Run(fmt.Sprintf("v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { installOpts := common.TestOptions{ HAEnabled: false, @@ -278,14 +276,12 @@ func TestUpgradePathNonHAModeMTLSEnabled(t *testing.T) { func TestUpgradePathHAModeMTLSDisabled(t *testing.T) { // Ensure a clean environment. common.EnsureUninstall(false, false) // does not wait for pod deletion. + for _, p := range supportedUpgradePaths { t.Run(fmt.Sprintf("setup v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { t.Run(deleteCRDs+p.previous.RuntimeVersion, common.DeleteCRD(p.previous.CustomResourceDefs)) t.Run(deleteCRDs+p.next.RuntimeVersion, common.DeleteCRD(p.next.CustomResourceDefs)) }) - } - - for _, p := range supportedUpgradePaths { t.Run(fmt.Sprintf("v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { installOpts := common.TestOptions{ HAEnabled: true, @@ -323,14 +319,13 @@ func TestUpgradePathHAModeMTLSDisabled(t *testing.T) { func TestUpgradePathHAModeMTLSEnabled(t *testing.T) { // Ensure a clean environment. common.EnsureUninstall(false, false) // does not wait for pod deletion. + for _, p := range supportedUpgradePaths { t.Run(fmt.Sprintf("setup v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { t.Run(deleteCRDs+p.previous.RuntimeVersion, common.DeleteCRD(p.previous.CustomResourceDefs)) t.Run(deleteCRDs+p.next.RuntimeVersion, common.DeleteCRD(p.next.CustomResourceDefs)) }) - } - for _, p := range supportedUpgradePaths { t.Run(fmt.Sprintf("v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { installOpts := common.TestOptions{ HAEnabled: true, @@ -370,12 +365,6 @@ func TestUpgradePathHAModeMTLSEnabled(t *testing.T) { func TestUpgradeWithHTTPEndpoint(t *testing.T) { // Ensure a clean environment. common.EnsureUninstall(false, false) // does not wait for pod deletion. - for _, p := range supportedUpgradePaths { - t.Run(fmt.Sprintf("setup v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { - t.Run(deleteCRDs+p.previous.RuntimeVersion, common.DeleteCRD(p.previous.CustomResourceDefs)) - t.Run(deleteCRDs+p.next.RuntimeVersion, common.DeleteCRD(p.next.CustomResourceDefs)) - }) - } for _, p := range supportedUpgradePaths { ver, err := semver.NewVersion(p.previous.RuntimeVersion) @@ -387,11 +376,17 @@ func TestUpgradeWithHTTPEndpoint(t *testing.T) { if ver.Major() != 1 || ver.Minor() < 11 { return } + + t.Run(fmt.Sprintf("setup v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { + t.Run(deleteCRDs+p.previous.RuntimeVersion, common.DeleteCRD(p.previous.CustomResourceDefs)) + t.Run(deleteCRDs+p.next.RuntimeVersion, common.DeleteCRD(p.next.CustomResourceDefs)) + }) + t.Run(fmt.Sprintf("v%s to v%s", p.previous.RuntimeVersion, p.next.RuntimeVersion), func(t *testing.T) { installOpts := common.TestOptions{ HAEnabled: true, MTLSEnabled: true, - ApplyComponentChanges: false, + ApplyComponentChanges: true, ApplyHTTPEndpointChanges: true, CheckResourceExists: map[common.Resource]bool{ common.CustomResourceDefs: true,