generated from quarkiverse/quarkiverse-template
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: trim namespaces when setting them, add more tests (#680)
Fixes #678
- Loading branch information
Showing
7 changed files
with
137 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...n-tests/src/test/java/io/quarkiverse/operatorsdk/it/EmptyOperatorLevelNamespacesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.quarkiverse.operatorsdk.it; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@QuarkusTest | ||
@TestProfile(EmptyOperatorLevelNamespacesTestProfile.class) | ||
public class EmptyOperatorLevelNamespacesTest { | ||
|
||
@Test | ||
public void reconcilersWithoutSpecificNamespacesShouldWatchAllNamespaces() { | ||
given() | ||
.when().get("/operator/" + TestReconciler.NAME + | ||
"/config") | ||
.then() | ||
.statusCode(200) | ||
.body("watchAllNamespaces", is(true)); | ||
} | ||
|
||
@Test | ||
public void reconcilerWithSpecificNamespacesShouldUseThem() { | ||
given() | ||
.when().get("/operator/" + ApplicationScopedReconciler.NAME + | ||
"/config") | ||
.then() | ||
.statusCode(200) | ||
.body("watchAllNamespaces", is(false)) | ||
.body("namespaces.size()", is(1)) | ||
.body("namespaces[0]", equalTo("default")); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
.../src/test/java/io/quarkiverse/operatorsdk/it/EmptyOperatorLevelNamespacesTestProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.quarkiverse.operatorsdk.it; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
|
||
public class EmptyOperatorLevelNamespacesTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Collections.singletonMap("quarkus.operator-sdk.namespaces", ""); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ion-tests/src/test/java/io/quarkiverse/operatorsdk/it/SetOperatorLevelNamespacesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.quarkiverse.operatorsdk.it; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@QuarkusTest | ||
@TestProfile(SetOperatorLevelNamespacesTestProfile.class) | ||
public class SetOperatorLevelNamespacesTest { | ||
|
||
@Test | ||
void configurationForControllerShouldExistAndUseOperatorLevelConfigurationWhenSet() { | ||
// check that the config for the test controller can be retrieved and is conform to our | ||
// expectations | ||
final var resourceName = io.quarkiverse.operatorsdk.it.Test.class.getCanonicalName(); | ||
given() | ||
.when() | ||
.get("/operator/" + TestReconciler.NAME + "/config") | ||
.then() | ||
.statusCode(200) | ||
.body( | ||
"customResourceClass", equalTo(resourceName), | ||
"name", equalTo(TestReconciler.NAME), | ||
"watchCurrentNamespace", is(false), | ||
"namespaces", hasSize(1), | ||
"namespaces", hasItem("operator-level"), | ||
"retry.maxAttempts", equalTo(1), | ||
"generationAware", equalTo(false), | ||
"maxReconciliationIntervalSeconds", equalTo(TestReconciler.INTERVAL)); | ||
} | ||
|
||
@Test | ||
void dependentAnnotationsShouldAppearInConfiguration() { | ||
given() | ||
.when() | ||
.get("/operator/" + DependentDefiningReconciler.NAME + "/config") | ||
.then() | ||
.statusCode(200).body( | ||
"watchCurrentNamespace", Matchers.equalTo(false), | ||
"namespaces", hasSize(1), | ||
"namespaces", hasItem("operator-level"), | ||
"dependents", hasSize(2), | ||
"dependents.dependentClass", | ||
hasItems(ReadOnlyDependentResource.class.getCanonicalName(), | ||
CRUDDependentResource.class.getCanonicalName()), | ||
"dependents.dependentConfig.labelSelector", | ||
hasItems(ReadOnlyDependentResource.LABEL_SELECTOR, CRUDDependentResource.LABEL_SELECTOR), | ||
"dependents.dependentConfig.onAddFilter", | ||
hasItem(CRUDDependentResource.TestOnAddFilter.class.getCanonicalName()), | ||
"dependents.dependentConfig.resourceDiscriminator", | ||
hasItems(ReadOnlyDependentResource.ReadOnlyResourceDiscriminator.class.getCanonicalName(), | ||
CRUDDependentResource.TestResourceDiscriminator.class.getCanonicalName())); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ts/src/test/java/io/quarkiverse/operatorsdk/it/SetOperatorLevelNamespacesTestProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.quarkiverse.operatorsdk.it; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
|
||
public class SetOperatorLevelNamespacesTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Collections.singletonMap("quarkus.operator-sdk.namespaces", "operator-level"); | ||
} | ||
|
||
} |