Skip to content

Commit de4bab9

Browse files
committed
move the unsupported privilege test to the CRDValidation tests and do not hardcode PostgreSQL 16 in the assertion
1 parent dc5e0fa commit de4bab9

5 files changed

Lines changed: 141 additions & 264 deletions

File tree

operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/GrantCreate.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ protected Grant create(int index) {
124124
spec.setRole(getRole());
125125

126126
spec.setObjectType(withObjectType);
127-
spec.setObjects(withObjects);
128127

129128
if (withObjectType != GrantObjectType.DATABASE
130129
|| withSchema != null

operator/src/test/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeReconcilerErrorTest.java

Lines changed: 0 additions & 104 deletions
This file was deleted.

operator/src/test/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeReconcilerTest.java

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.junit.jupiter.api.DisplayName;
2121
import org.junit.jupiter.api.Nested;
2222
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
2324
import org.junit.jupiter.params.ParameterizedTest;
2425
import org.junit.jupiter.params.provider.MethodSource;
2526

@@ -33,6 +34,7 @@
3334
import java.util.stream.Stream;
3435

3536
import static it.aboutbits.postgresql.core.Privilege.CREATE;
37+
import static it.aboutbits.postgresql.core.Privilege.MAINTAIN;
3638
import static it.aboutbits.postgresql.core.Privilege.SELECT;
3739
import static it.aboutbits.postgresql.core.Privilege.USAGE;
3840
import static it.aboutbits.postgresql.crd.defaultprivilege.DefaultPrivilegeObjectType.SCHEMA;
@@ -308,29 +310,79 @@ void failWhenDatabaseHasSchema() {
308310
@Test
309311
@DisplayName("Should reconcile to ERROR when privileges are invalid for objectType")
310312
void errorWhenInvalidPrivileges() {
311-
// given
312-
var now = OffsetDateTime.now(ZoneOffset.UTC);
313-
314-
// when
313+
// given / when
315314
var defaultPrivilege = given.one()
316315
.defaultPrivilege()
317316
.withObjectType(SCHEMA)
318317
// SELECT is not allowed for SCHEMA
319318
.withPrivileges(SELECT)
320319
.returnFirst();
321320

322-
var expectedStatus = new CRStatus()
323-
.setName("")
324-
.setPhase(CRPhase.ERROR)
325-
.setMessage("DefaultPrivilege contains invalid privileges for the specified objectType")
326-
.setObservedGeneration(1L);
321+
// then
322+
assertThat(defaultPrivilege)
323+
.isNotNull()
324+
.extracting(DefaultPrivilege::getStatus)
325+
.satisfies(status -> {
326+
assertThat(status.getPhase()).isEqualTo(CRPhase.ERROR);
327+
assertThat(status.getMessage()).startsWith("DefaultPrivilege contains invalid privileges for the specified objectType");
328+
});
329+
}
330+
331+
@Test
332+
@EnabledIfSystemProperty(
333+
named = "quarkus.test.profile",
334+
matches = "test-pg(15|16)",
335+
disabledReason = "PostgreSQL 15 and 16 do not support the MAINTAIN privilege"
336+
)
337+
@DisplayName(
338+
"Should reconcile to ERROR when the PostgreSQL version does not support the MAINTAIN table privilege")
339+
void errorWhenUnsupportedMaintainTablePrivilege() {
340+
// given
341+
var clusterConnectionMain = given.one()
342+
.clusterConnection()
343+
.returnFirst();
344+
345+
var database = given.one()
346+
.database()
347+
.withClusterConnectionName(clusterConnectionMain.getMetadata().getName())
348+
.returnFirst();
349+
350+
var clusterConnectionDb = given.one()
351+
.clusterConnection()
352+
.withDatabase(database.getSpec().getName())
353+
.returnFirst();
354+
355+
var schema = given.one()
356+
.schema()
357+
.withClusterConnectionName(clusterConnectionDb.getMetadata().getName())
358+
.returnFirst();
359+
360+
var role = given.one()
361+
.role()
362+
.withClusterConnectionName(clusterConnectionMain.getMetadata().getName())
363+
.returnFirst();
364+
365+
// when
366+
var defaultPrivilege = given.one()
367+
.defaultPrivilege()
368+
.withClusterConnectionName(clusterConnectionDb.getMetadata().getName())
369+
.withDatabase(database.getSpec().getName())
370+
.withSchema(schema.getSpec().getName())
371+
.withRole(role.getSpec().getName())
372+
.withObjectType(TABLE)
373+
.withPrivileges(MAINTAIN)
374+
.returnFirst();
327375

328376
// then
329-
assertThatDefaultPrivilegeHasStatus(
330-
defaultPrivilege,
331-
expectedStatus,
332-
now
333-
);
377+
assertThat(defaultPrivilege)
378+
.isNotNull()
379+
.extracting(DefaultPrivilege::getStatus)
380+
.satisfies(status -> {
381+
assertThat(status.getPhase()).isEqualTo(CRPhase.ERROR);
382+
assertThat(status.getMessage())
383+
.startsWith("The following privileges require a newer PostgreSQL version (current:")
384+
.contains("{MAINTAIN=17}");
385+
});
334386
}
335387
}
336388
}

operator/src/test/java/it/aboutbits/postgresql/crd/grant/GrantReconcilerErrorTest.java

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)