From 6899cb4fb4c021182fb888dffded03c1639a22d1 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Thu, 15 Jun 2023 13:22:20 +0200 Subject: [PATCH] test: PodIT don't rely on PodResource.file.read to verify the contents of the upload test Signed-off-by: Marc Nuri --- .../src/test/java/io/fabric8/kubernetes/PodIT.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java index 423541a45b1..423a776dbf2 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java @@ -409,7 +409,7 @@ void uploadBinaryFile() throws IOException { } @Test - void uploadDir(@TempDir Path toUpload) throws IOException { + void uploadDir(@TempDir Path toUpload) throws Exception { // Given final String[] files = new String[] { "1", "2", "a", "b", "c" }; final Path nestedDir = Files.createDirectory(toUpload.resolve("nested")); @@ -430,11 +430,13 @@ void uploadDir(@TempDir Path toUpload) throws IOException { .map(p -> Paths.get("tmp").resolve("upload-dir").resolve(p)) .collect(Collectors.toList()); for (Path pathToCheck : pathsToCheck) { - try (InputStream checkIs = podResource.file("/" + pathToCheck.toString()).read(); - BufferedReader br = new BufferedReader(new InputStreamReader(checkIs, StandardCharsets.UTF_8))) { - String result = br.lines().collect(Collectors.joining(System.lineSeparator())); - assertEquals("I'm uploaded" + System.lineSeparator() + pathToCheck.getFileName(), result); - } + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + podResource.writingOutput(baos) + .exec("sh", "-c", String.format("cat /%s", pathToCheck.toString())).exitCode().get(); + assertThat(baos) + .extracting(ByteArrayOutputStream::toString) + .asString() + .startsWith("I'm uploaded" + System.lineSeparator() + pathToCheck.getFileName()); } }