Skip to content

Commit

Permalink
simplify a little (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
wind57 authored Oct 15, 2024
1 parent a27bf65 commit 8d02d1a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.springframework.context.annotation.Primary;

import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.TestConfig;
import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.assertLogStatement;
import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.invokeAndAssert;

/**
* @author wind57
Expand All @@ -61,6 +63,7 @@ void beforeEach() {

@AfterEach
void afterEach() {
// busybox is deleted as part of the test itself, thus not seen here
util.deleteNamespace(NAMESPACE_A);
util.deleteNamespace(NAMESPACE_B);
}
Expand All @@ -77,8 +80,8 @@ void afterEach() {
*/
@Test
void test(CapturedOutput output) {
TestAssertions.assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointSliceV1CatalogWatch");
TestAssertions.invokeAndAssert(util, Set.of(NAMESPACE_A, NAMESPACE_B), port, NAMESPACE_A);
assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointSliceV1CatalogWatch");
invokeAndAssert(util, Set.of(NAMESPACE_A, NAMESPACE_B), port, NAMESPACE_A);
}

@TestConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Set;

import io.fabric8.kubernetes.client.KubernetesClient;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -34,6 +35,8 @@
import org.springframework.context.annotation.Primary;

import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchWithEndpointSlicesIT.TestConfig;
import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.assertLogStatement;
import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.invokeAndAssert;

/**
* @author wind57
Expand All @@ -51,6 +54,12 @@ void beforeEach() {
util.busybox(NAMESPACE, Phase.CREATE);
}

@AfterEach
void afterEach() {
// empty on purpose
// busybox is deleted as part of the test itself, thus not seen here
}

/**
* <pre>
* - we deploy a busybox service with 2 replica pods
Expand All @@ -62,8 +71,8 @@ void beforeEach() {
*/
@Test
void test(CapturedOutput output) {
TestAssertions.assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointSliceV1CatalogWatch");
TestAssertions.invokeAndAssert(util, Set.of(NAMESPACE), port, NAMESPACE);
assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointSliceV1CatalogWatch");
invokeAndAssert(util, Set.of(NAMESPACE), port, NAMESPACE);
}

@TestConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.springframework.context.annotation.Primary;

import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.TestConfig;
import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.assertLogStatement;
import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.invokeAndAssert;

/**
* @author wind57
Expand All @@ -61,6 +63,7 @@ void beforeEach() {

@AfterEach
void afterEach() {
// busybox is deleted as part of the assertions, thus not seen here
util.deleteNamespace(NAMESPACE_A);
util.deleteNamespace(NAMESPACE_B);
}
Expand All @@ -77,8 +80,8 @@ void afterEach() {
*/
@Test
void test(CapturedOutput output) {
TestAssertions.assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointsCatalogWatch");
TestAssertions.invokeAndAssert(util, Set.of(NAMESPACE_A, NAMESPACE_B), port, NAMESPACE_A);
assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointsCatalogWatch");
invokeAndAssert(util, Set.of(NAMESPACE_A, NAMESPACE_B), port, NAMESPACE_A);
}

@TestConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Set;

import io.fabric8.kubernetes.client.KubernetesClient;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -34,6 +35,8 @@
import org.springframework.context.annotation.Primary;

import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchWithEndpointsIT.TestConfig;
import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.assertLogStatement;
import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.invokeAndAssert;

/**
* @author wind57
Expand All @@ -51,6 +54,12 @@ void beforeEach() {
util.busybox(NAMESPACE, Phase.CREATE);
}

@AfterEach
void afterEach() {
// empty on purpose
// busybox is deleted as part of the test itself, thus not seen here
}

/**
* <pre>
* - we deploy a busybox service with 2 replica pods
Expand All @@ -62,8 +71,8 @@ void beforeEach() {
*/
@Test
void test(CapturedOutput output) {
TestAssertions.assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointsCatalogWatch");
TestAssertions.invokeAndAssert(util, Set.of(NAMESPACE), port, NAMESPACE);
assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointsCatalogWatch");
invokeAndAssert(util, Set.of(NAMESPACE), port, NAMESPACE);
}

@TestConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -159,8 +160,7 @@ public static void loadImage(String image, String tag, String tarName, K3sContai
InputStream imageStream = saveImageCmd.withTag(tag).exec();

Path imagePath = Paths.get(TEMP_FOLDER + "/" + tarName + ".tar");
Files.deleteIfExists(imagePath);
Files.copy(imageStream, imagePath);
Files.copy(imageStream, imagePath, StandardCopyOption.REPLACE_EXISTING);
// import image with ctr. this works because TEMP_FOLDER is mounted in the
// container
await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(1)).until(() -> {
Expand Down

0 comments on commit 8d02d1a

Please sign in to comment.