Skip to content

Commit

Permalink
move env version load into common
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Troshin <anton@diagrid.io>
  • Loading branch information
antontroshin committed Nov 6, 2024
1 parent a02c81f commit 39e8c8c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
24 changes: 23 additions & 1 deletion tests/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const (
devZipkinReleaseName = "dapr-dev-zipkin"
)

var VersionWithScheduler = semver.MustParse("1.14.0")
var (
VersionWithScheduler = semver.MustParse("1.14.0-rc.1")
CurrentVersionDetails VersionDetails
)

type VersionDetails struct {
RuntimeVersion string
Expand Down Expand Up @@ -1269,3 +1272,22 @@ func exportCurrentCertificate(daprPath string) error {
}
return nil
}

func EnsureEnvVersionSet(t *testing.T, useDaprLatestVersion bool) VersionDetails {
currentRuntimeVersion, currentDashboardVersion := GetVersionsFromEnv(t, useDaprLatestVersion)

vd := VersionDetails{
RuntimeVersion: currentRuntimeVersion,
DashboardVersion: currentDashboardVersion,
CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io", "httpendpoints.dapr.io"},
ImageVariant: "",
UseDaprLatestVersion: useDaprLatestVersion,
}

version := semver.MustParse(currentRuntimeVersion)
if version.GreaterThan(VersionWithScheduler) {
CurrentVersionDetails.HasScheduler = true
}

return vd
}
34 changes: 8 additions & 26 deletions tests/e2e/kubernetes/clean_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import (
)

var (
currentRuntimeVersion string
currentDashboardVersion string
currentVersionDetails common.VersionDetails
clusterRoles1_9_X = []string{"dapr-operator-admin", "dashboard-reader"}
clusterRoleBindings1_9_X = []string{"dapr-operator", "dapr-role-tokenreview-binding", "dashboard-reader-global"}
clusterRoles1_10_X = []string{"dapr-dashboard", "dapr-injector", "dapr-operator-admin", "dapr-placement", "dapr-sentry"}
Expand All @@ -36,30 +33,15 @@ var (
// ensureCleanEnv function needs to be called in every Test function.
// sets necessary variable values and uninstalls any previously installed `dapr`.
func ensureCleanEnv(t *testing.T, useDaprLatestVersion bool) {
ensureEnvVersionSet(t, useDaprLatestVersion)
// Ensure a clean environment
common.EnsureUninstall(true, true) // does not wait for pod deletion
}
common.EnsureEnvVersionSet(t, useDaprLatestVersion)

func ensureEnvVersionSet(t *testing.T, useDaprLatestVersion bool) {
currentRuntimeVersion, currentDashboardVersion = common.GetVersionsFromEnv(t, useDaprLatestVersion)

currentVersionDetails = common.VersionDetails{
RuntimeVersion: currentRuntimeVersion,
DashboardVersion: currentDashboardVersion,
CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io", "resiliencies.dapr.io", "httpendpoints.dapr.io"},
ImageVariant: "",
UseDaprLatestVersion: useDaprLatestVersion,
}
if strings.HasPrefix(currentRuntimeVersion, "1.9.") {
currentVersionDetails.ClusterRoles = clusterRoles1_9_X
currentVersionDetails.ClusterRoleBindings = clusterRoleBindings1_9_X
if strings.HasPrefix(common.CurrentVersionDetails.RuntimeVersion, "1.9.") {
common.CurrentVersionDetails.ClusterRoles = clusterRoles1_9_X
common.CurrentVersionDetails.ClusterRoleBindings = clusterRoleBindings1_9_X
} else {
currentVersionDetails.ClusterRoles = clusterRoles1_10_X
currentVersionDetails.ClusterRoleBindings = clusterRoleBindings1_10_X
}

if strings.HasPrefix(currentRuntimeVersion, "1.14.") {
currentVersionDetails.HasScheduler = true
common.CurrentVersionDetails.ClusterRoles = clusterRoles1_10_X
common.CurrentVersionDetails.ClusterRoleBindings = clusterRoleBindings1_10_X
}
// Ensure a clean environment
common.EnsureUninstall(true, true) // does not wait for pod deletion
}
8 changes: 5 additions & 3 deletions tests/e2e/standalone/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import (
"runtime"
"testing"

"github.com/dapr/cli/tests/e2e/common"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestStandaloneRun(t *testing.T) {
ensureDaprInstallation(t)
ensureEnvVersionSet(t, false)
common.EnsureEnvVersionSet(t, false)

ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
Expand All @@ -36,7 +38,7 @@ func TestStandaloneRun(t *testing.T) {
output, err := cmdProcess(ctx, "placement", t.Log, "--metrics-port", "9091", "--healthz-port", "8081")
require.NoError(t, err)
t.Log(output)
if currentVersionDetails.HasScheduler {
if common.CurrentVersionDetails.HasScheduler {
output, err = cmdProcess(ctx, "scheduler", t.Log, "--metrics-port", "9092", "--healthz-port", "8082")
require.NoError(t, err)
t.Log(output)
Expand Down Expand Up @@ -71,7 +73,7 @@ func TestStandaloneRun(t *testing.T) {
output, err := cmdRun(path, "--dapr-internal-grpc-port", "9999", "--", "bash", "-c", "echo test")
t.Log(output)
require.NoError(t, err, "run failed")
if currentVersionDetails.HasScheduler {
if common.CurrentVersionDetails.HasScheduler {
assert.Contains(t, output, "Internal gRPC server is running on :9999")
} else {
assert.Contains(t, output, "Internal gRPC server is running on port 9999")
Expand Down

0 comments on commit 39e8c8c

Please sign in to comment.