Skip to content

Commit

Permalink
Minor changes in tests according to changes
Browse files Browse the repository at this point in the history
+ Wait till resource is deleted from cluster in failing tests
  • Loading branch information
rohanKanojia committed Mar 15, 2019
1 parent b3ca17b commit 66184ba
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ public Boolean call() {
return this.client.apps().replicaSets().inNamespace(this.namespace).list().getItems().size() == 0;
case "NetworkPolicy":
return this.client.network().networkPolicies().inNamespace(this.namespace).list().getItems().size() == 0;
case "SecurityContextConstraints":
return ((OpenShiftClient)this.client).securityContextConstraints().withName(this.name).get() == null;
case "ClusterRoleBinding":
return this.client.rbac().clusterRoleBindings().withName(this.name).get() == null;
case "ClusterRole":
return this.client.rbac().clusterRoles().withName(this.name).get() == null;
case "RoleBinding":
return this.client.rbac().roleBindings().inNamespace(this.namespace).withName(this.name).get() == null;
case "Role":
return this.client.rbac().roles().inNamespace(this.namespace).withName(this.name).get() == null;
case "PodSecurityPolicy":
return this.client.extensions().podSecurityPolicies().withName(this.name).get() == null;
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.fabric8.kubernetes;

import io.fabric8.commons.DeleteEntity;
import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding;
import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder;
import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingList;
Expand All @@ -31,6 +32,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -179,8 +183,11 @@ public void delete() {
ClusterRoleBindingList clusterRoleBindingListBefore = client.rbac().clusterRoleBindings().list();

boolean deleted = client.rbac().clusterRoleBindings().withName("read-nodes").delete();

assertTrue(deleted);

DeleteEntity<ClusterRoleBinding> clusterRoleBindingDeleteEntity = new DeleteEntity<>(ClusterRoleBinding.class, client, "read-nodes", null);
await().atMost(30, TimeUnit.SECONDS).until(clusterRoleBindingDeleteEntity);

ClusterRoleBindingList clusterRoleBindingListAfter = client.rbac().clusterRoleBindings().list();
assertEquals(clusterRoleBindingListBefore.getItems().size()-1,clusterRoleBindingListAfter.getItems().size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package io.fabric8.kubernetes;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import io.fabric8.commons.DeleteEntity;
import io.fabric8.kubernetes.api.model.rbac.ClusterRole;
import io.fabric8.kubernetes.api.model.rbac.ClusterRoleList;
import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBuilder;
Expand All @@ -31,6 +33,7 @@
import org.junit.Test;
import org.junit.After;

import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -202,15 +205,20 @@ public void delete() {
ClusterRoleList clusterRoleListBefore = client.rbac().clusterRoles().list();

boolean deleted = client.rbac().clusterRoles().withName("node-reader").delete();

assertTrue(deleted);

DeleteEntity<ClusterRole> deleteEntity = new DeleteEntity<>(ClusterRole.class, client, "node-reader", null);
await().atMost(30, TimeUnit.SECONDS).until(deleteEntity);

ClusterRoleList clusterRoleListAfter = client.rbac().clusterRoles().list();
assertEquals(clusterRoleListBefore.getItems().size()-1,clusterRoleListAfter.getItems().size());
}

@After
public void cleanup() {
client.rbac().clusterRoles().withName("node-reader").delete();
DeleteEntity<ClusterRole> deleteEntity = new DeleteEntity<>(ClusterRole.class, client, "node-reader", null);
await().atMost(30, TimeUnit.SECONDS).until(deleteEntity);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,16 @@ public void delete(){
boolean deleted = client.network().networkPolicies().delete(networkPolicy);

assertTrue(deleted);

DeleteEntity<NetworkPolicy> deleteEntity = new DeleteEntity<>(NetworkPolicy.class, client, "networkpolicy", currentNamespace);
await().atMost(30, TimeUnit.SECONDS).until(deleteEntity);

NetworkPolicyList networkPolicyList = client.network().networkPolicies().list();
assertEquals(0,networkPolicyList.getItems().size());
}

@After
public void cleanup() throws InterruptedException {
public void cleanup() {
if (client.network().networkPolicies().list().getItems().size()!= 0) {
client.network().networkPolicies().delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.fabric8.kubernetes;

import io.fabric8.commons.DeleteEntity;
import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicy;
import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicyBuilder;
import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicyList;
Expand All @@ -24,6 +25,8 @@
import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes;
import org.arquillian.cube.requirement.ArquillianConditionalRunner;
import org.jboss.arquillian.test.api.ArquillianResource;

import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
Expand All @@ -34,6 +37,7 @@
import org.junit.runner.RunWith;

import java.util.Collections;
import java.util.concurrent.TimeUnit;

@RunWith(ArquillianConditionalRunner.class)
@RequiresKubernetes
Expand Down Expand Up @@ -124,12 +128,17 @@ public void update(){
public void delete(){
boolean deleted = client.extensions().podSecurityPolicies().delete(podSecurityPolicy);
assertTrue(deleted);

DeleteEntity<PodSecurityPolicy> deleteEntity = new DeleteEntity<>(PodSecurityPolicy.class, client, "test-example", null);
await().atMost(30, TimeUnit.SECONDS).until(deleteEntity);
PodSecurityPolicyList podSecurityPolicyList = client.extensions().podSecurityPolicies().list();
assertEquals(0,podSecurityPolicyList.getItems().size());
}

@After
public void cleanup() {
client.extensions().podSecurityPolicies().withName("test-example").delete();
DeleteEntity<PodSecurityPolicy> deleteEntity = new DeleteEntity<>(PodSecurityPolicy.class, client, "test-example", null);
await().atMost(30, TimeUnit.SECONDS).until(deleteEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.fabric8.kubernetes;

import io.fabric8.commons.DeleteEntity;
import io.fabric8.kubernetes.api.model.rbac.RoleBinding;
import io.fabric8.kubernetes.api.model.rbac.RoleBindingList;
import io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder;
Expand All @@ -31,7 +32,9 @@
import org.junit.runner.RunWith;

import java.util.Collections;
import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -170,11 +173,16 @@ public void update() {
@Test
public void delete() {

boolean deleted = client.rbac().roleBindings().inNamespace(currentNamespace).delete();
Integer initialCountBeforeDeletion = client.rbac().roleBindings().inNamespace(currentNamespace).list().getItems().size();
boolean deleted = client.rbac().roleBindings().inNamespace(currentNamespace).withName("read-jobs").delete();

assertTrue(deleted);

DeleteEntity<RoleBinding> deleteEntity = new DeleteEntity<>(RoleBinding.class, client, "read-jobs", currentNamespace);
await().atMost(30, TimeUnit.SECONDS).until(deleteEntity);

RoleBindingList roleBindingList = client.rbac().roleBindings().inNamespace(currentNamespace).list();
assertEquals(0,roleBindingList.getItems().size());
assertEquals(initialCountBeforeDeletion - 1,roleBindingList.getItems().size());
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.fabric8.kubernetes;

import io.fabric8.commons.DeleteEntity;
import io.fabric8.kubernetes.api.model.rbac.Role;
import io.fabric8.kubernetes.api.model.rbac.RoleList;
import io.fabric8.kubernetes.api.model.rbac.RoleBuilder;
Expand All @@ -29,6 +30,9 @@
import org.junit.Test;
import org.junit.After;

import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -196,11 +200,16 @@ public void update() {
@Test
public void delete() {

Integer countBeforeDeletion = client.rbac().roles().inNamespace(currentNamespace).list().getItems().size();
boolean deleted = client.rbac().roles().inNamespace(currentNamespace).delete();

assertTrue(deleted);

DeleteEntity<Role> deleteEntity = new DeleteEntity<>(Role.class, client, "job-reader", currentNamespace);
await().atMost(30, TimeUnit.SECONDS).until(deleteEntity);

RoleList roleList = client.rbac().roles().inNamespace(currentNamespace).list();
assertEquals(0,roleList.getItems().size());
assertEquals(countBeforeDeletion - 1,roleList.getItems().size());
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.fabric8.openshift;


import io.fabric8.commons.DeleteEntity;
import io.fabric8.openshift.api.model.SecurityContextConstraints;
import io.fabric8.openshift.api.model.SecurityContextConstraintsBuilder;
import io.fabric8.openshift.api.model.SecurityContextConstraintsList;
Expand All @@ -29,7 +30,9 @@
import org.junit.runner.RunWith;

import java.util.Collections;
import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;
import static org.junit.Assert.*;

@RunWith(ArquillianConditionalRunner.class)
Expand Down Expand Up @@ -152,11 +155,14 @@ public void delete(){
assertFalse(sccList.getItems().contains(scc));
}


@After
public void cleanup() {
if (client.securityContextConstraints().list().getItems().size()!= 0) {
client.securityContextConstraints().withName("test-scc").delete();
}

client.securityContextConstraints().withName("test-scc").delete();
DeleteEntity<SecurityContextConstraints> sccDelete = new DeleteEntity<>(SecurityContextConstraints.class, client, "test-scc", null);
await().atMost(30, TimeUnit.SECONDS).until(sccDelete);
}

}

0 comments on commit 66184ba

Please sign in to comment.