Skip to content

Commit

Permalink
fix httpendpoint tests cleanup and checks
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Troshin <[email protected]>
  • Loading branch information
antontroshin committed Feb 28, 2025
1 parent 1874fcf commit 601701d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
19 changes: 12 additions & 7 deletions tests/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
}
Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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.
Expand Down
39 changes: 17 additions & 22 deletions tests/e2e/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
{
Expand All @@ -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"},
},
},
{
Expand All @@ -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"},
},
},
{
Expand Down Expand Up @@ -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)},
}...)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 601701d

Please sign in to comment.