cli/tests/e2e/kubernetes/kubernetes_test.go

159 lines
4.5 KiB
Go

//go:build e2e
// +build e2e
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------
package kubernetes_test
import (
"testing"
"github.com/dapr/cli/tests/e2e/common"
)
const (
currentRuntimeVersion = "1.5.0-rc.3"
currentDashboardVersion = "0.9.0-rc.1"
)
var currentVersionDetails = common.VersionDetails{
RuntimeVersion: currentRuntimeVersion,
DashboardVersion: currentDashboardVersion,
CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io"},
ClusterRoles: []string{"dapr-operator-admin", "dashboard-reader"},
ClusterRoleBindings: []string{"dapr-operator", "dapr-role-tokenreview-binding", "dashboard-reader-global"},
}
func ensureCleanEnv(t *testing.T, details common.VersionDetails) {
// Ensure a clean environment
common.EnsureUninstall(true) // does not wait for pod deletion
}
func TestKubernetesNonHAModeMTLSDisabled(t *testing.T) {
// ensure clean env for test
ensureCleanEnv(t, currentVersionDetails)
// setup tests
tests := []common.TestCase{}
tests = append(tests, common.GetTestsOnInstall(currentVersionDetails, common.TestOptions{
HAEnabled: false,
MTLSEnabled: false,
ApplyComponentChanges: true,
CheckResourceExists: map[common.Resource]bool{
common.CustomResourceDefs: true,
common.ClusterRoles: true,
common.ClusterRoleBindings: true,
},
})...)
tests = append(tests, common.GetTestsOnUninstall(currentVersionDetails, common.TestOptions{
CheckResourceExists: map[common.Resource]bool{
common.CustomResourceDefs: true,
common.ClusterRoles: false,
common.ClusterRoleBindings: false,
},
})...)
// execute tests
for _, tc := range tests {
t.Run(tc.Name, tc.Callable)
}
}
func TestKubernetesHAModeMTLSDisabled(t *testing.T) {
// ensure clean env for test
ensureCleanEnv(t, currentVersionDetails)
// setup tests
tests := []common.TestCase{}
tests = append(tests, common.GetTestsOnInstall(currentVersionDetails, common.TestOptions{
HAEnabled: true,
MTLSEnabled: false,
ApplyComponentChanges: true,
CheckResourceExists: map[common.Resource]bool{
common.CustomResourceDefs: true,
common.ClusterRoles: true,
common.ClusterRoleBindings: true,
},
})...)
tests = append(tests, common.GetTestsOnUninstall(currentVersionDetails, common.TestOptions{
CheckResourceExists: map[common.Resource]bool{
common.CustomResourceDefs: true,
common.ClusterRoles: false,
common.ClusterRoleBindings: false,
},
})...)
// execute tests
for _, tc := range tests {
t.Run(tc.Name, tc.Callable)
}
}
func TestKubernetesNonHAModeMTLSEnabled(t *testing.T) {
// ensure clean env for test
ensureCleanEnv(t, currentVersionDetails)
// setup tests
tests := []common.TestCase{}
tests = append(tests, common.GetTestsOnInstall(currentVersionDetails, common.TestOptions{
HAEnabled: false,
MTLSEnabled: true,
ApplyComponentChanges: true,
CheckResourceExists: map[common.Resource]bool{
common.CustomResourceDefs: true,
common.ClusterRoles: true,
common.ClusterRoleBindings: true,
},
})...)
tests = append(tests, common.GetTestsOnUninstall(currentVersionDetails, common.TestOptions{
CheckResourceExists: map[common.Resource]bool{
common.CustomResourceDefs: true,
common.ClusterRoles: false,
common.ClusterRoleBindings: false,
},
})...)
// execute tests
for _, tc := range tests {
t.Run(tc.Name, tc.Callable)
}
}
func TestKubernetesHAModeMTLSEnabled(t *testing.T) {
// ensure clean env for test
ensureCleanEnv(t, currentVersionDetails)
// setup tests
tests := []common.TestCase{}
tests = append(tests, common.GetTestsOnInstall(currentVersionDetails, common.TestOptions{
HAEnabled: true,
MTLSEnabled: true,
ApplyComponentChanges: true,
CheckResourceExists: map[common.Resource]bool{
common.CustomResourceDefs: true,
common.ClusterRoles: true,
common.ClusterRoleBindings: true,
},
})...)
tests = append(tests, common.GetTestsOnUninstall(currentVersionDetails, common.TestOptions{
UninstallAll: true,
CheckResourceExists: map[common.Resource]bool{
common.CustomResourceDefs: false,
common.ClusterRoles: false,
common.ClusterRoleBindings: false,
},
})...)
// execute tests
for _, tc := range tests {
t.Run(tc.Name, tc.Callable)
}
}