Skip to content

chore: polish the junit5 extension #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ private OperatorExtension(
this.waitForNamespaceDeletion = waitForNamespaceDeletion;
}

/**
* Creates a {@link Builder} to set up an {@link OperatorExtension} instance.
*
* @return the builder.
*/
public static Builder builder() {
return new Builder();
}
Expand Down Expand Up @@ -123,7 +128,7 @@ public <T extends HasMetadata> NonNamespaceOperation<T, KubernetesResourceList<T
return kubernetesClient.resources(type).inNamespace(namespace);
}

public <T extends HasMetadata> T getNamedResource(Class<T> type, String name) {
public <T extends HasMetadata> T get(Class<T> type, String name) {
return kubernetesClient.resources(type).inNamespace(namespace).withName(name).get();
}

Expand All @@ -135,10 +140,6 @@ public <T extends HasMetadata> T replace(Class<T> type, T resource) {
return kubernetesClient.resources(type).inNamespace(namespace).replace(resource);
}

public <T extends HasMetadata> T get(Class<T> type, String name) {
return kubernetesClient.resources(type).inNamespace(namespace).withName(name).get();
}


@SuppressWarnings("unchecked")
protected void before(ExtensionContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void manyResourcesGetCreatedUpdatedAndDeleted() throws InterruptedExcepti
// update some resources
for (int i = 0; i < NUMBER_OF_RESOURCES_UPDATED; i++) {
TestCustomResource tcr =
operator.getNamedResource(TestCustomResource.class,
operator.get(TestCustomResource.class,
TestUtils.TEST_CUSTOM_RESOURCE_PREFIX + i);
tcr.getSpec().setValue(i + UPDATED_SUFFIX);
operator.resources(TestCustomResource.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void awaitResourcesCreatedOrUpdated() {
.untilAsserted(
() -> {
ConfigMap configMap =
operator.getNamedResource(ConfigMap.class, "test-config-map");
operator.get(ConfigMap.class, "test-config-map");
assertThat(configMap).isNotNull();
assertThat(configMap.getData().get("test-key")).isEqualTo("test-value");
});
Expand All @@ -68,7 +68,7 @@ void awaitStatusUpdated(int timeout) {
.untilAsserted(
() -> {
TestCustomResource cr =
operator.getNamedResource(TestCustomResource.class,
operator.get(TestCustomResource.class,
TestUtils.TEST_CUSTOM_RESOURCE_NAME);
assertThat(cr).isNotNull();
assertThat(cr.getStatus()).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private InformerEventSourceTestCustomResource initialCustomResource() {
private void waitForCRStatusValue(String value) {
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
var cr =
operator.getNamedResource(InformerEventSourceTestCustomResource.class, RESOURCE_NAME);
operator.get(InformerEventSourceTestCustomResource.class, RESOURCE_NAME);
assertThat(cr.getStatus()).isNotNull();
assertThat(cr.getStatus().getConfigMapValue()).isEqualTo(value);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void retryFailedExecution() {
.isEqualTo(RetryTestCustomResourceController.NUMBER_FAILED_EXECUTIONS + 1);

RetryTestCustomResource finalResource =
operator.getNamedResource(RetryTestCustomResource.class,
operator.get(RetryTestCustomResource.class,
resource.getMetadata().getName());
assertThat(finalResource.getStatus().getState())
.isEqualTo(RetryTestCustomResourceStatus.State.SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void awaitStatusUpdated(String name) {
.untilAsserted(
() -> {
SubResourceTestCustomResource cr =
operator.getNamedResource(SubResourceTestCustomResource.class, name);
operator.get(SubResourceTestCustomResource.class, name);
assertThat(cr.getMetadata().getFinalizers()).hasSize(1);
assertThat(cr).isNotNull();
assertThat(cr.getStatus()).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void updatesSubResourceStatus() {

DoubleUpdateTestCustomResource customResource =
operator
.getNamedResource(DoubleUpdateTestCustomResource.class,
.get(DoubleUpdateTestCustomResource.class,
resource.getMetadata().getName());

assertThat(TestUtils.getNumberOfExecutions(operator))
Expand All @@ -57,7 +57,7 @@ void awaitStatusUpdated(String name) {
.untilAsserted(
() -> {
DoubleUpdateTestCustomResource cr =
operator.getNamedResource(DoubleUpdateTestCustomResource.class, name);
operator.get(DoubleUpdateTestCustomResource.class, name);

assertThat(cr)
.isNotNull();
Expand Down