Skip to content

Commit d470106

Browse files
authored
test: cover the remaining ConfigurationServiceOverrider settings (#3586)
overrideShouldWork asserted the informer stopped handler override against getLeaderElectionConfiguration(), so it passed whatever the overrider did with the handler, and set a resource cloner it never asserted. Fixes both, and adds coverage for withDependentResourceFactory and withDefaultNonSSAResource, neither of which was exercised anywhere. withDependentResourceFactory had no coverage at all: unlike the scalar setters, it is not reachable through a ConfigLoader binding, so operatorBindingsCoverAllSingleScalarSettersOnConfigurationServiceOverrider does not guard it either.
1 parent 6fb7675 commit d470106

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

‎operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
import java.time.Duration;
1919
import java.util.Optional;
20+
import java.util.Set;
2021
import java.util.concurrent.Executors;
2122
import java.util.concurrent.ThreadPoolExecutor;
2223

2324
import org.junit.jupiter.api.Test;
2425

26+
import io.fabric8.kubernetes.api.model.ConfigMap;
2527
import io.fabric8.kubernetes.api.model.HasMetadata;
28+
import io.fabric8.kubernetes.api.model.Secret;
2629
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
30+
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceFactory;
2731

2832
import static org.assertj.core.api.Assertions.assertThat;
2933
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -98,10 +102,10 @@ public <R extends HasMetadata> R clone(R object) {
98102
assertNotEquals(config.getExecutorService(), overridden.getExecutorService());
99103
assertNotEquals(config.getWorkflowExecutorService(), overridden.getWorkflowExecutorService());
100104
assertNotEquals(config.getMetrics(), overridden.getMetrics());
105+
assertNotEquals(config.getResourceCloner(), overridden.getResourceCloner());
101106
assertNotEquals(
102107
config.getLeaderElectionConfiguration(), overridden.getLeaderElectionConfiguration());
103-
assertNotEquals(
104-
config.getInformerStoppedHandler(), overridden.getLeaderElectionConfiguration());
108+
assertNotEquals(config.getInformerStoppedHandler(), overridden.getInformerStoppedHandler());
105109
assertNotEquals(
106110
config.reconciliationTerminationTimeout(), overridden.reconciliationTerminationTimeout());
107111
}
@@ -118,4 +122,30 @@ void threadCountConfiguredProperly() {
118122
assertThat(((ThreadPoolExecutor) overridden.getWorkflowExecutorService()).getMaximumPoolSize())
119123
.isEqualTo(14);
120124
}
125+
126+
@SuppressWarnings("rawtypes")
127+
@Test
128+
void dependentResourceFactoryDefaultsToTheSharedOneAndCanBeOverridden() {
129+
final var factory = new DependentResourceFactory() {};
130+
131+
assertThat(config.dependentResourceFactory()).isSameAs(DependentResourceFactory.DEFAULT);
132+
assertThat(
133+
new ConfigurationServiceOverrider(config)
134+
.withDependentResourceFactory(factory)
135+
.build()
136+
.dependentResourceFactory())
137+
.isSameAs(factory);
138+
}
139+
140+
@Test
141+
void defaultNonSSAResourcesDefaultToConfigMapsAndSecretsAndCanBeOverridden() {
142+
assertThat(config.defaultNonSSAResources())
143+
.containsExactlyInAnyOrder(ConfigMap.class, Secret.class);
144+
assertThat(
145+
new ConfigurationServiceOverrider(config)
146+
.withDefaultNonSSAResource(Set.of())
147+
.build()
148+
.defaultNonSSAResources())
149+
.isEmpty();
150+
}
121151
}

0 commit comments

Comments
 (0)