Skip to content

Commit

Permalink
Add a few more test cases for managed DWO namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
sleshchenko committed Sep 30, 2021
1 parent 6b80bb6 commit 282f7e8
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions pkg/deploy/dev-workspace/dev_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,85 @@ func TestReconcileDevWorkspaceCheckIfCSVExists(t *testing.T) {
err = deployContext.ClusterAPI.Client.Get(context.TODO(), client.ObjectKey{Name: DevWorkspaceNamespace}, &corev1.Namespace{})
assert.True(t, k8sErrors.IsNotFound(err), "DevWorkspace namespace is created when instead DWO CSV is expected to be created")
}

func TestReconcileDevWorkspaceIfUnmanagedDWONamespaceExists(t *testing.T) {
cheCluster := &orgv1.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: "eclipse-che",
},
Spec: orgv1.CheClusterSpec{
DevWorkspace: orgv1.CheClusterSpecDevWorkspace{
Enable: true,
},
},
}

dwoNamespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: DevWorkspaceNamespace,
// no che annotations are there
},
}
deployContext := deploy.GetTestDeployContext(cheCluster, []runtime.Object{})
err := deployContext.ClusterAPI.Client.Create(context.TODO(), dwoNamespace)
assert.NoError(t, err)

util.IsOpenShift = true
util.IsOpenShift4 = true
err = os.Setenv("ALLOW_DEVWORKSPACE_ENGINE", "true")
assert.NoError(t, err)
reconciled, _ := ReconcileDevWorkspace(deployContext)

assert.True(t, reconciled, "Reconcile is not triggered")

// check is reconcile created deployment if existing namespace is not annotated in che specific way
err = deployContext.ClusterAPI.Client.Get(context.TODO(), client.ObjectKey{Name: DevWorkspaceDeploymentName}, &appsv1.Deployment{})
assert.True(t, k8sErrors.IsNotFound(err), "DevWorkspace deployment is created but it should not since it's DWO namespace managed not by Che")
}

func TestReconcileDevWorkspaceIfManagedDWONamespaceExists(t *testing.T) {
cheCluster := &orgv1.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: "eclipse-che",
},
Spec: orgv1.CheClusterSpec{
DevWorkspace: orgv1.CheClusterSpecDevWorkspace{
Enable: true,
},
},
}

dwoNamespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: DevWorkspaceNamespace,
Annotations: map[string]string{
deploy.CheEclipseOrgNamespace: "eclipse-che",
},
// no che annotations are there
},
}
deployContext := deploy.GetTestDeployContext(cheCluster, []runtime.Object{})
err := deployContext.ClusterAPI.NonCachedClient.Create(context.TODO(), dwoNamespace)
assert.NoError(t, err)

exists, err := deploy.Get(deployContext,
types.NamespacedName{Name: DevWorkspaceNamespace, Namespace: DevWorkspaceNamespace},
&corev1.Namespace{})

util.IsOpenShift = true
util.IsOpenShift4 = true
err = os.Setenv("ALLOW_DEVWORKSPACE_ENGINE", "true")
assert.NoError(t, err)

reconciled, err := ReconcileDevWorkspace(deployContext)

assert.True(t, reconciled, "Reconcile is not triggered")
assert.NoError(t, err, "Reconcile failed")

// check is reconcile created deployment if existing namespace is not annotated in che specific way
exists, err = deploy.Get(deployContext,
types.NamespacedName{Name: DevWorkspaceDeploymentName, Namespace: DevWorkspaceNamespace},
&appsv1.Deployment{})
assert.True(t, exists, "DevWorkspace deployment is not created in Che managed DWO namespace")
assert.NoError(t, err, "Failed to get devworkspace deployment")
}

0 comments on commit 282f7e8

Please sign in to comment.