Skip to content

Commit

Permalink
fix: non-independent unit tests because static state (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
csviri authored Dec 21, 2022
1 parent f2feb4d commit 53a553e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public static void registerConverter(Class<? extends DependentResource> dependen
knownConverters.put(converterClass, converter);
}

/** To support independent unit tests */
public static void clear() {
converters.clear();
knownConverters.clear();
}

private static class ConfiguredClassPair {
private final Configured configured;
private final Class<? extends DependentResource> annotatedClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Optional;
import java.util.Set;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.api.model.ConfigMap;
Expand Down Expand Up @@ -30,6 +31,12 @@
class ControllerConfigurationOverriderTest {
private final BaseConfigurationService configurationService = new BaseConfigurationService();


@BeforeEach
void clearStaticState() {
DependentResourceConfigurationResolver.clear();
}

@Test
void overridingNSShouldPreserveUntouchedDependents() {
var configuration = createConfiguration(new NamedDependentReconciler());
Expand Down

0 comments on commit 53a553e

Please sign in to comment.