Skip to content

Commit a7d5d32

Browse files
committed
test: fixed broked tests
1 parent a3f5dbd commit a7d5d32

8 files changed

Lines changed: 17 additions & 22 deletions

File tree

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/cluster/context/ClusterPostgresVersionContextAppender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void appendContext(StackGresCluster cluster, Builder contextBuilder) {
179179
.getBuildVersion(postgresVersion);
180180

181181
if (BUGGY_PG_VERSIONS.keySet().contains(version)
182-
&& Objects.equals(Optional.of(version), previousVersion)) {
182+
&& !Objects.equals(Optional.of(version), previousVersion)) {
183183
throw new IllegalArgumentException(
184184
"Do not use PostgreSQL " + version + ". "
185185
+ BUGGY_PG_VERSIONS.get(version));

stackgres-k8s/src/operator/src/main/java/io/stackgres/operator/conciliation/factory/cluster/PostgresSslSecret.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class PostgresSslSecret
4343

4444
private static final Duration ONE_DAY = Duration.ofDays(1);
4545

46-
private static final long DEFAULT_DURATION = 13 * 30;
46+
private static final long DEFAULT_DURATION = 365;
4747

4848
private static final String SSL_SUFFIX = "-ssl";
4949

stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/conciliation/factory/cluster/PostgresSslSecretTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.security.interfaces.RSAPrivateCrtKey;
1717
import java.security.spec.PKCS8EncodedKeySpec;
1818
import java.security.spec.RSAPublicKeySpec;
19+
import java.time.Duration;
20+
import java.time.Instant;
1921
import java.util.Base64;
2022
import java.util.Optional;
2123

@@ -26,6 +28,7 @@
2628
import io.stackgres.common.fixture.Fixtures;
2729
import io.stackgres.common.labels.ClusterLabelFactory;
2830
import io.stackgres.common.labels.ClusterLabelMapper;
31+
import io.stackgres.operator.common.CryptoUtil;
2932
import io.stackgres.operator.conciliation.cluster.StackGresClusterContext;
3033
import io.stackgres.operatorframework.resource.ResourceUtil;
3134
import org.junit.jupiter.api.Assertions;
@@ -110,12 +113,15 @@ void givenAClusterWithSslAndNoSecret_itShouldGenerateSslSecret() throws Exceptio
110113
}
111114

112115
@Test
113-
void givenAClusterWithSslAndSecret_itShouldReuseSslSecret() {
116+
void givenAClusterWithSslAndSecret_itShouldReuseSslSecret() throws Exception {
114117
cluster.getSpec().getPostgres().setSsl(new StackGresClusterSsl());
115118
cluster.getSpec().getPostgres().getSsl().setEnabled(true);
116119
when(context.getSource()).thenReturn(cluster);
117-
when(context.getPostgresSslCertificate()).thenReturn(Optional.of("test-certificate"));
118-
when(context.getPostgresSslPrivateKey()).thenReturn(Optional.of("test-private-key"));
120+
var generated = CryptoUtil.generateCertificateAndPrivateKey(Instant.now().plus(Duration.ofDays(365)));
121+
final String cert = generated.v1;
122+
when(context.getPostgresSslCertificate()).thenReturn(Optional.of(cert));
123+
final String key = generated.v2;
124+
when(context.getPostgresSslPrivateKey()).thenReturn(Optional.of(key));
119125

120126
var secretVolumePairs = postgresSslSecret.buildVolumes(context).toList();
121127

@@ -130,7 +136,7 @@ void givenAClusterWithSslAndSecret_itShouldReuseSslSecret() {
130136
.map(Secret::getData)
131137
.map(data -> data.get(PatroniUtil.CERTIFICATE_KEY))
132138
.isPresent());
133-
Assertions.assertEquals("test-certificate",
139+
Assertions.assertEquals(cert,
134140
ResourceUtil.decodeSecret(
135141
secretVolumePairs.getFirst().getSource()
136142
.map(Secret.class::cast)
@@ -142,7 +148,7 @@ void givenAClusterWithSslAndSecret_itShouldReuseSslSecret() {
142148
.map(Secret::getData)
143149
.map(data -> data.get(PatroniUtil.PRIVATE_KEY_KEY))
144150
.isPresent());
145-
Assertions.assertEquals("test-private-key",
151+
Assertions.assertEquals(key,
146152
ResourceUtil.decodeSecret(
147153
secretVolumePairs.getFirst().getSource()
148154
.map(Secret.class::cast)

stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/validation/dbops/DbOpsMajorVersionUpgradeValidatorTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package io.stackgres.operator.validation.dbops;
77

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.Assert.assertTrue;
99
import static org.junit.jupiter.api.Assertions.assertThrows;
1010

1111
import io.stackgres.operator.common.StackGresDbOpsReview;
@@ -42,11 +42,7 @@ void givenBuggyVersionOnCreation_shouldFail() {
4242

4343
String resultMessage = ex.getMessage();
4444

45-
assertEquals("Do not use PostgreSQL " + BUGGY_VERSION + ". Please, use PostgreSQL 14.4 since it fixes"
46-
+ " an issue with CREATE INDEX CONCURRENTLY and REINDEX CONCURRENTLY"
47-
+ " that could cause silent data corruption of indexes. For more info see"
48-
+ " https://www.postgresql.org/about/news/postgresql-144-released-2470/.",
49-
resultMessage);
45+
assertTrue(resultMessage, resultMessage.startsWith("Do not use PostgreSQL " + BUGGY_VERSION + "."));
5046
}
5147

5248
private StackGresDbOpsReview getCreationReview() {

stackgres-k8s/src/operator/src/test/java/io/stackgres/operator/validation/shardeddbops/ShardedDbOpsMajorVersionUpgradeValidatorTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package io.stackgres.operator.validation.shardeddbops;
77

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.Assert.assertTrue;
99
import static org.junit.jupiter.api.Assertions.assertThrows;
1010

1111
import io.stackgres.operator.common.StackGresShardedDbOpsReview;
@@ -42,11 +42,7 @@ void givenBuggyMajorVersionOnCreation_shouldFail() {
4242

4343
String resultMessage = ex.getMessage();
4444

45-
assertEquals("Do not use PostgreSQL " + BUGGY_VERSION + ". Please, use PostgreSQL 14.4 since it"
46-
+ " fixes an issue with CREATE INDEX CONCURRENTLY and REINDEX CONCURRENTLY that could cause"
47-
+ " silent data corruption of indexes. For more info see"
48-
+ " https://www.postgresql.org/about/news/postgresql-144-released-2470/.",
49-
resultMessage);
45+
assertTrue(resultMessage, resultMessage.startsWith("Do not use PostgreSQL " + BUGGY_VERSION + "."));
5046
}
5147

5248
private StackGresShardedDbOpsReview getCreationReview() {

stackgres-k8s/src/test-util/src/main/resources/stackgres/pooling_config/from_version1.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"application_name_add_host": "1",
2929
"auth_query": "SELECT usename, passwd FROM pg_shadow WHERE usename=$1",
3030
"auth_type": "md5",
31-
"auth_user": "authenticator",
3231
"default_pool_size": "1000",
3332
"ignore_startup_parameters": "extra_float_digits",
3433
"max_client_conn": "1000",

stackgres-k8s/src/test-util/src/main/resources/stackgres/pooling_config/to_version1.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"application_name_add_host": "1",
2929
"auth_query": "SELECT usename, passwd FROM pg_shadow WHERE usename=$1",
3030
"auth_type": "md5",
31-
"auth_user": "authenticator",
3231
"default_pool_size": "1000",
3332
"ignore_startup_parameters": "extra_float_digits",
3433
"max_client_conn": "1000",

stackgres-k8s/src/test-util/src/main/resources/stackgres/pooling_config/to_version1beta1.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"auth_query",
3030
"application_name_add_host",
3131
"max_user_connections",
32-
"auth_user",
3332
"admin_users",
3433
"server_check_query"
3534
]

0 commit comments

Comments
 (0)