chore: Adapt tests for downstream (#1652)

* chore: Adapt tests for downstream

Signed-off-by: Anatolii Bazko <abazko@redhat.com>

* make fmt

Signed-off-by: Anatolii Bazko <abazko@redhat.com>

---------

Signed-off-by: Anatolii Bazko <abazko@redhat.com>
pull/1653/head
Anatolii Bazko 2023-04-04 08:58:40 +03:00 committed by GitHub
parent 4ee7d5b0d4
commit 3a61595a99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 42 deletions

View File

@ -61,9 +61,7 @@ func InitializeForTesting(operatorDeploymentFilePath string) {
for _, container := range operatorDeployment.Spec.Template.Spec.Containers {
for _, env := range container.Env {
if env.Value != "" {
os.Setenv(env.Name, env.Value)
}
os.Setenv(env.Name, env.Value)
}
}

View File

@ -86,6 +86,23 @@ func CompareResources(actualDeployment *appsv1.Deployment, expected TestExpected
)
}
func AssertEqualEnvVars(t *testing.T, expected []corev1.EnvVar, actual []corev1.EnvVar) {
assert.Equal(t, len(expected), len(actual))
for _, expectedEnvVar := range expected {
found := true
for _, actualEnvVar := range actual {
if expectedEnvVar.Name == actualEnvVar.Name && expectedEnvVar.Value == actualEnvVar.Value {
found = true
break
}
}
if !found {
t.Errorf("Expected env var %s=%s not found", expectedEnvVar.Name, expectedEnvVar.Value)
}
}
}
func ValidateSecurityContext(actualDeployment *appsv1.Deployment, t *testing.T) {
assert.Equal(t, corev1.Capability("ALL"), actualDeployment.Spec.Template.Spec.Containers[0].SecurityContext.Capabilities.Drop[0])
assert.Equal(t, pointer.BoolPtr(false), actualDeployment.Spec.Template.Spec.Containers[0].SecurityContext.AllowPrivilegeEscalation)

View File

@ -15,9 +15,8 @@ package dashboard
import (
"os"
fakeDiscovery "k8s.io/client-go/discovery/fake"
"k8s.io/apimachinery/pkg/api/resource"
fakeDiscovery "k8s.io/client-go/discovery/fake"
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
configv1 "github.com/openshift/api/config/v1"
@ -177,24 +176,28 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
Name: "CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL",
Value: "http://plugin-registry.eclipse-che.svc:8080/v3",
},
{
Name: "OPENSHIFT_CONSOLE_URL",
},
{
Name: "CHE_DEFAULT_SPEC_COMPONENTS_DASHBOARD_HEADERMESSAGE_TEXT",
Value: defaults.GetDashboardHeaderMessageText(),
},
{
Name: "CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DEFAULTEDITOR",
Value: "che-incubator/che-code/latest",
Value: defaults.GetDevEnvironmentsDefaultEditor(),
},
{
Name: "CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DEFAULTCOMPONENTS",
Value: `[{"name": "universal-developer-image", "container": {"image": "quay.io/devfile/universal-developer-image:ubi8-latest"}}]`,
Value: defaults.GetDevEnvironmentsDefaultComponents(),
},
{
Name: "CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL",
Value: "https://open-vsx.org",
Value: defaults.GetPluginRegistryOpenVSXURL(),
},
{
Name: "CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DISABLECONTAINERBUILDCAPABILITIES",
Value: "false",
},
{
Name: "OPENSHIFT_CONSOLE_URL",
Value: defaults.GetDevEnvironmentsDisableContainerBuildCapabilities(),
},
},
cheCluster: &chev2.CheCluster{
@ -249,25 +252,29 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
Name: "CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL",
Value: "http://plugin-registry.eclipse-che.svc:8080/v3",
},
{
Name: "OPENSHIFT_CONSOLE_URL",
Value: "https://console-openshift-console.apps.my-host/",
},
{
Name: "CHE_DEFAULT_SPEC_COMPONENTS_DASHBOARD_HEADERMESSAGE_TEXT",
Value: defaults.GetDashboardHeaderMessageText(),
},
{
Name: "CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DEFAULTEDITOR",
Value: "che-incubator/che-code/latest",
Value: defaults.GetDevEnvironmentsDefaultEditor(),
},
{
Name: "CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DEFAULTCOMPONENTS",
Value: `[{"name": "universal-developer-image", "container": {"image": "quay.io/devfile/universal-developer-image:ubi8-latest"}}]`,
Value: defaults.GetDevEnvironmentsDefaultComponents(),
},
{
Name: "CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL",
Value: "https://open-vsx.org",
Value: defaults.GetPluginRegistryOpenVSXURL(),
},
{
Name: "CHE_DEFAULT_SPEC_DEVENVIRONMENTS_DISABLECONTAINERBUILDCAPABILITIES",
Value: "false",
},
{
Name: "OPENSHIFT_CONSOLE_URL",
Value: "https://console-openshift-console.apps.my-host/",
Value: defaults.GetDevEnvironmentsDisableContainerBuildCapabilities(),
},
},
cheCluster: &chev2.CheCluster{
@ -299,7 +306,7 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, len(deployment.Spec.Template.Spec.Containers), 1)
assert.Empty(t, cmp.Diff(testCase.envVars, deployment.Spec.Template.Spec.Containers[0].Env))
test.AssertEqualEnvVars(t, testCase.envVars, deployment.Spec.Template.Spec.Containers[0].Env)
})
}
}

View File

@ -22,9 +22,9 @@ import (
func TestCorrectImageName(t *testing.T) {
testCases := map[string]string{
"docker.io/eclipse/che-operator:latest": "che-operator:latest",
"eclipse/che-operator:7.1.0": "che-operator:7.1.0",
"che-operator:7.2.0": "che-operator:7.2.0",
"docker.io/eclipse/my-operator:latest": "my-operator:latest",
"eclipse/my-operator:7.1.0": "my-operator:7.1.0",
"my-operator:7.2.0": "my-operator:7.2.0",
}
for k, v := range testCases {
t.Run(k, func(*testing.T) {

View File

@ -261,7 +261,7 @@ func TestCheClusterDefaultsCleanerOpenVSXURL(t *testing.T) {
CheVersion: "7.52.0",
},
},
expectedOpenVSXURL: pointer.StringPtr("https://open-vsx.org"),
expectedOpenVSXURL: pointer.StringPtr(defaults.GetPluginRegistryOpenVSXURL()),
},
{
name: "Test upgrade from v7.62.0",
@ -328,23 +328,6 @@ func TestCheClusterDefaultsCleanerOpenVSXURL(t *testing.T) {
},
expectedOpenVSXURL: pointer.StringPtr("https://bla-bla-bla"),
},
{
name: "Keep empty OpenVSXURL after upgrade",
cheCluster: &chev2.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "eclipse-che",
Namespace: "eclipse-che",
},
Spec: chev2.CheClusterSpec{
Components: chev2.CheClusterComponents{
PluginRegistry: chev2.PluginRegistry{
OpenVSXURL: pointer.StringPtr(""),
},
},
},
},
expectedOpenVSXURL: pointer.StringPtr(""),
},
}
for _, testCase := range testCases {