diff --git a/pkg/common/operator-defaults/defaults.go b/pkg/common/operator-defaults/defaults.go index 2a9796a20..75089d059 100644 --- a/pkg/common/operator-defaults/defaults.go +++ b/pkg/common/operator-defaults/defaults.go @@ -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) } } diff --git a/pkg/common/test/utils.go b/pkg/common/test/utils.go index a17ea009d..4a127d128 100644 --- a/pkg/common/test/utils.go +++ b/pkg/common/test/utils.go @@ -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) diff --git a/pkg/deploy/dashboard/dashboard_deployment_test.go b/pkg/deploy/dashboard/dashboard_deployment_test.go index c6f905eef..38a94743d 100644 --- a/pkg/deploy/dashboard/dashboard_deployment_test.go +++ b/pkg/deploy/dashboard/dashboard_deployment_test.go @@ -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) }) } } diff --git a/pkg/deploy/defaults_test.go b/pkg/deploy/defaults_test.go index c0e5d404e..35012b763 100644 --- a/pkg/deploy/defaults_test.go +++ b/pkg/deploy/defaults_test.go @@ -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) { diff --git a/pkg/deploy/migration/checluster-defaults-cleaner_test.go b/pkg/deploy/migration/checluster-defaults-cleaner_test.go index aa13d85a8..18f3c1604 100644 --- a/pkg/deploy/migration/checluster-defaults-cleaner_test.go +++ b/pkg/deploy/migration/checluster-defaults-cleaner_test.go @@ -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 {