Skip to content

Commit 7649ee5

Browse files
committed
fix some disabled tests and test data creators
1 parent d400d37 commit 7649ee5

10 files changed

Lines changed: 77 additions & 34 deletions

File tree

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,38 +116,48 @@ private String getNamespace() {
116116
return withNamespace;
117117
}
118118

119-
return kubernetesClient.getNamespace();
119+
withNamespace = kubernetesClient.getNamespace();
120+
121+
return withNamespace;
120122
}
121123

122124
private String getName() {
123125
if (withName != null) {
124126
return withName;
125127
}
126128

127-
return randomKubernetesNameSuffix("test-cluster-connection");
129+
withName = randomKubernetesNameSuffix("test-cluster-connection");
130+
131+
return withName;
128132
}
129133

130134
private String getHost() {
131135
if (withHost != null) {
132136
return withHost;
133137
}
134138

135-
return "localhost";
139+
withHost = "localhost";
140+
141+
return withHost;
136142
}
137143

138144
private int getPort() {
139145
if (withPort != null) {
140146
return withPort;
141147
}
142148

143-
return dbConnectionDetails.port();
149+
withPort = dbConnectionDetails.port();
150+
151+
return withPort;
144152
}
145153

146154
private String getDatabase() {
147-
return Objects.requireNonNullElse(
155+
withDatabase = Objects.requireNonNullElse(
148156
withDatabase,
149157
"postgres"
150158
);
159+
160+
return withDatabase;
151161
}
152162

153163
private SecretRef getAdminSecretRef() {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,19 @@ private String getNamespace() {
110110
return withNamespace;
111111
}
112112

113-
return kubernetesClient.getNamespace();
113+
withNamespace = kubernetesClient.getNamespace();
114+
115+
return withNamespace;
114116
}
115117

116118
private String getName() {
117119
if (withName != null) {
118120
return withName;
119121
}
120122

121-
return randomKubernetesNameSuffix("test-database");
123+
withName = randomKubernetesNameSuffix("test-database");
124+
125+
return withName;
122126
}
123127

124128
private String getClusterConnectionName() {
@@ -128,6 +132,7 @@ private String getClusterConnectionName() {
128132

129133
var clusterConnection = given.one()
130134
.clusterConnection()
135+
.withName("conn-%s".formatted(withName))
131136
.returnFirst();
132137

133138
withClusterConnectionNamespace = clusterConnection.getMetadata().getNamespace();

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,19 @@ private String getNamespace() {
150150
return withNamespace;
151151
}
152152

153-
return kubernetesClient.getNamespace();
153+
withNamespace = kubernetesClient.getNamespace();
154+
155+
return withNamespace;
154156
}
155157

156158
private String getName() {
157159
if (withName != null) {
158160
return withName;
159161
}
160162

161-
return randomKubernetesNameSuffix("test-default-privilege");
163+
withName = randomKubernetesNameSuffix("test-default-privilege");
164+
165+
return withName;
162166
}
163167

164168
private String getClusterConnectionName() {
@@ -168,6 +172,7 @@ private String getClusterConnectionName() {
168172

169173
var clusterConnection = given.one()
170174
.clusterConnection()
175+
.withName("conn-%s".formatted(withName))
171176
.returnFirst();
172177

173178
withClusterConnectionNamespace = clusterConnection.getMetadata().getNamespace();

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,19 @@ private String getNamespace() {
168168
return withNamespace;
169169
}
170170

171-
return kubernetesClient.getNamespace();
171+
withNamespace = kubernetesClient.getNamespace();
172+
173+
return withNamespace;
172174
}
173175

174176
private String getName() {
175177
if (withName != null) {
176178
return withName;
177179
}
178180

179-
return randomKubernetesNameSuffix("test-grant");
181+
withName = randomKubernetesNameSuffix("test-grant");
182+
183+
return withName;
180184
}
181185

182186
private String getClusterConnectionName() {
@@ -186,6 +190,7 @@ private String getClusterConnectionName() {
186190

187191
var clusterConnection = given.one()
188192
.clusterConnection()
193+
.withName("conn-%s".formatted(withName))
189194
.returnFirst();
190195

191196
withClusterConnectionNamespace = clusterConnection.getMetadata().getNamespace();

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,19 @@ private String getNamespace() {
136136
return withNamespace;
137137
}
138138

139-
return kubernetesClient.getNamespace();
139+
withNamespace = kubernetesClient.getNamespace();
140+
141+
return withNamespace;
140142
}
141143

142144
private String getName() {
143145
if (withName != null) {
144146
return withName;
145147
}
146148

147-
return randomKubernetesNameSuffix("test-role");
149+
withName = randomKubernetesNameSuffix("test-role");
150+
151+
return withName;
148152
}
149153

150154
private String getClusterConnectionName() {
@@ -154,6 +158,7 @@ private String getClusterConnectionName() {
154158

155159
var clusterConnection = given.one()
156160
.clusterConnection()
161+
.withName("conn-%s".formatted(withName))
157162
.returnFirst();
158163

159164
withClusterConnectionNamespace = clusterConnection.getMetadata().getNamespace();

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,19 @@ private String getNamespace() {
110110
return withNamespace;
111111
}
112112

113-
return kubernetesClient.getNamespace();
113+
withNamespace = kubernetesClient.getNamespace();
114+
115+
return withNamespace;
114116
}
115117

116118
private String getName() {
117119
if (withName != null) {
118120
return withName;
119121
}
120122

121-
return randomKubernetesNameSuffix("test-schema");
123+
withName = randomKubernetesNameSuffix("test-schema");
124+
125+
return withName;
122126
}
123127

124128
private String getClusterConnectionName() {
@@ -128,6 +132,7 @@ private String getClusterConnectionName() {
128132

129133
var clusterConnection = given.one()
130134
.clusterConnection()
135+
.withName("conn-%s".formatted(withName))
131136
.returnFirst();
132137

133138
withClusterConnectionNamespace = clusterConnection.getMetadata().getNamespace();

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,19 @@ private String getNamespace() {
101101
return withNamespace;
102102
}
103103

104-
return kubernetesClient.getNamespace();
104+
withNamespace = kubernetesClient.getNamespace();
105+
106+
return withNamespace;
105107
}
106108

107109
private String getName() {
108110
if (withName != null) {
109111
return withName;
110112
}
111113

112-
return randomKubernetesNameSuffix("test-secret");
114+
withName = randomKubernetesNameSuffix("test-secret");
115+
116+
return withName;
113117
}
114118

115119
@Nullable
@@ -122,7 +126,9 @@ private String getUsername() {
122126
return withUsername;
123127
}
124128

125-
return FAKER.credentials().username();
129+
withUsername = FAKER.credentials().username();
130+
131+
return withUsername;
126132
}
127133

128134
@Nullable
@@ -135,6 +141,8 @@ private String getPassword() {
135141
return withPassword;
136142
}
137143

138-
return FAKER.credentials().username();
144+
withPassword = FAKER.credentials().username();
145+
146+
return withPassword;
139147
}
140148
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void resetEnvironment() {
103103
class CRDValidation {
104104
@Nested
105105
class FieldSize {
106-
@Disabled("Test is way too slow")
106+
@Disabled("Test is way too slow with all combinations")
107107
@ParameterizedTest
108108
@BlankSource
109109
@DisplayName("Should fail when the database is a blank or empty String (CEL rule)")
@@ -123,7 +123,7 @@ void failWhenDatabaseIsBlankOrEmptyString(
123123
.hasMessageContaining("The DefaultPrivilege database must not be empty.");
124124
}
125125

126-
@Disabled("Test is way too slow")
126+
@Disabled("Test is way too slow with all combinations")
127127
@ParameterizedTest
128128
@BlankSource
129129
@DisplayName("Should fail when the role is a blank or empty String (CEL rule)")
@@ -143,7 +143,7 @@ void failWhenRoleIsBlankOrEmptyString(
143143
.hasMessageContaining("The DefaultPrivilege role must not be empty.");
144144
}
145145

146-
@Disabled("Test is way too slow")
146+
@Disabled("Test is way too slow with all combinations")
147147
@ParameterizedTest
148148
@BlankSource
149149
@DisplayName("Should fail when the owner is a blank or empty String (CEL rule)")
@@ -163,7 +163,7 @@ void failWhenOwnerIsBlankOrEmptyString(
163163
.hasMessageContaining("The DefaultPrivilege owner must not be empty.");
164164
}
165165

166-
@Disabled("Test is way too slow")
166+
@Disabled("Test is way too slow with all combinations")
167167
@ParameterizedTest
168168
@BlankSource
169169
@DisplayName("Should fail when the schema is a blank or empty String (CEL rule)")
@@ -185,8 +185,7 @@ void failWhenSchemaIsBlankOrEmptyString(
185185

186186
@Test
187187
@DisplayName("Should fail when the privileges are an empty List (CEL rule)")
188-
void failWhenPrivilegesAreAnEmptyList(
189-
) {
188+
void failWhenPrivilegesAreAnEmptyList() {
190189
// then
191190
assertThatThrownBy(() ->
192191
// given / when

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void resetEnvironment() {
108108
class CRDValidation {
109109
@Nested
110110
class FieldSize {
111-
@Disabled("Test is way too slow")
111+
@Disabled("Test is way too slow with all combinations")
112112
@ParameterizedTest
113113
@BlankSource
114114
@DisplayName("Should fail when the database is a blank or empty String (CEL rule)")
@@ -128,7 +128,7 @@ void failWhenDatabaseIsBlankOrEmptyString(
128128
.hasMessageContaining("The Grant database must not be empty.");
129129
}
130130

131-
@Disabled("Test is way too slow")
131+
@Disabled("Test is way too slow with all combinations")
132132
@ParameterizedTest
133133
@BlankSource
134134
@DisplayName("Should fail when the role is a blank or empty String (CEL rule)")
@@ -148,7 +148,7 @@ void failWhenRoleIsBlankOrEmptyString(
148148
.hasMessageContaining("The Grant role must not be empty.");
149149
}
150150

151-
@Disabled("Test is way too slow")
151+
@Disabled("Test is way too slow with all combinations")
152152
@ParameterizedTest
153153
@BlankSource
154154
@DisplayName("Should fail when the schema is a blank or empty String (CEL rule)")
@@ -170,8 +170,7 @@ void failWhenSchemaIsBlankOrEmptyString(
170170

171171
@Test
172172
@DisplayName("Should fail when the privileges are an empty List (CEL rule)")
173-
void failWhenPrivilegesAreAnEmptyList(
174-
) {
173+
void failWhenPrivilegesAreAnEmptyList() {
175174
// then
176175
assertThatThrownBy(() ->
177176
// given / when

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.jspecify.annotations.NullMarked;
1717
import org.jspecify.annotations.Nullable;
1818
import org.junit.jupiter.api.BeforeEach;
19-
import org.junit.jupiter.api.Disabled;
2019
import org.junit.jupiter.api.DisplayName;
2120
import org.junit.jupiter.api.Test;
2221
import org.junit.jupiter.params.ParameterizedTest;
@@ -209,9 +208,6 @@ void toggleRoleLogin_updatesCorrectly() {
209208
assertThat(getRoleFlagValue(dsl, roleName, PG_AUTHID.ROLCANLOGIN)).isFalse();
210209
}
211210

212-
@Disabled(
213-
"The before each timeout will always be triggered by the deletion of the role (CRD cleanup) as the connection does not exist"
214-
)
215211
@Test
216212
@DisplayName("When a Role references a missing ClusterConnection, status should be PENDING with a helpful message")
217213
void createRole_withMissingClusterConnection_setsPending() {
@@ -245,6 +241,12 @@ void createRole_withMissingClusterConnection_setsPending() {
245241
now
246242
);
247243
assertThat(role.getStatus().getLastPhaseTransitionTime()).isNull();
244+
245+
// Cleanup manually
246+
kubernetesClient.resource(role).delete();
247+
role.getMetadata().setFinalizers(null);
248+
role.getMetadata().setResourceVersion(null);
249+
kubernetesClient.resource(role).patch();
248250
}
249251

250252
@Test

0 commit comments

Comments
 (0)