Skip to content

Commit f8e539d

Browse files
committed
add a test to check if the Role CR instance deletion works and deletes the role from the database
1 parent 358aee1 commit f8e539d

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/test/java/it/aboutbits/postgresql/crd/role/RoleReconcilerTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,41 @@ void role_multipleMemberships_updatesCorrectly() {
833833
dsl.execute("drop role if exists {0}", role(roleC));
834834
}
835835

836+
@Test
837+
@DisplayName("When a Role is deleted, it should be dropped from the database")
838+
void deleteRole_removesFromDatabase() {
839+
// given
840+
var clusterConnection = given.one()
841+
.clusterConnection()
842+
.withName("test-connection-role-delete")
843+
.returnFirst();
844+
845+
var roleName = "test-role-delete";
846+
847+
var role = given.one()
848+
.role()
849+
.withName(roleName)
850+
.withClusterConnectionName(clusterConnection.getMetadata().getName())
851+
.returnFirst();
852+
853+
var dsl = postgreSQLContextFactory.getDSLContext(clusterConnection);
854+
855+
// Verify it exists initially
856+
assertThat(roleService.roleExists(dsl, role.getSpec())).isTrue();
857+
858+
// when
859+
kubernetesClient.resources(Role.class)
860+
.inNamespace(role.getMetadata().getNamespace())
861+
.withName(role.getMetadata().getName())
862+
.withTimeout(5, TimeUnit.SECONDS)
863+
.delete();
864+
865+
// then
866+
await().atMost(10, TimeUnit.SECONDS)
867+
.pollInterval(500, TimeUnit.MILLISECONDS)
868+
.until(() -> !roleService.roleExists(dsl, role.getSpec()));
869+
}
870+
836871
private @Nullable <T> T getRoleFlagValue(
837872
DSLContext dsl,
838873
String roleName,

0 commit comments

Comments
 (0)