Skip to content

Commit

Permalink
fix : fixed broken unit tests for jkube-kit/common on windows (#2574)
Browse files Browse the repository at this point in the history
* fix : fixed broken unit tests for windows
  • Loading branch information
l3002 authored Jan 30, 2024
1 parent 0f530e0 commit b7e1d6c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
Expand All @@ -33,6 +35,7 @@ void setUp() {
}

@Test
@DisabledOnOs(OS.WINDOWS)
void execute_whenCommandCompletedSuccessfully_thenPrintResult() throws IOException {
// Given
TestCommand testCommand = new TestCommand(kitLogger, new String[] {"echo", "hello"});
Expand All @@ -45,6 +48,7 @@ void execute_whenCommandCompletedSuccessfully_thenPrintResult() throws IOExcepti
}

@Test
@DisabledOnOs(OS.WINDOWS)
void execute_whenCommandFailed_thenThrowException() {
// Given
TestCommand testCommand = new TestCommand(kitLogger, new String[] {"ls", "idontexist"});
Expand Down Expand Up @@ -86,6 +90,7 @@ protected void processError(String errorLine) {
}

@Test
@DisabledOnOs(OS.WINDOWS)
void execute_whenWorkDirProvided_thenUseWorkDir(@TempDir File temporaryFolder) throws IOException {
// Given
TestCommand testCommand = new TestCommand(kitLogger, new String[] {"touch", "foo"}, temporaryFolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.InputStream;
import java.nio.file.Files;

import static org.apache.commons.io.FilenameUtils.separatorsToSystem;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

class ArchiveDecompressorTest {
Expand Down Expand Up @@ -66,7 +67,7 @@ void extractArchive_whenArchiveWithNestedDir_thenExtractToSpecifiedDir(String fi
FileAssertions.assertThat(tempDir)
.exists()
.fileTree()
.containsExactlyInAnyOrder(parentDir, artifactParentDir, artifact);
.containsExactlyInAnyOrder(parentDir, separatorsToSystem(artifactParentDir), separatorsToSystem(artifact));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import static org.apache.commons.io.FilenameUtils.separatorsToSystem;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIOException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -140,7 +141,7 @@ void downloadArchive_whenUnixArtifactProvided_thenDownloadAndExtract() throws IO
FileAssertions.assertThat(temporaryFolder)
.exists()
.fileTree()
.containsExactlyInAnyOrder("linux-amd64", "linux-amd64/foo");
.containsExactlyInAnyOrder("linux-amd64", separatorsToSystem("linux-amd64/foo"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@ void asJson_withConfigMap_returnsJsonString() {
final String result = Serialization.asJson(source);
// Then
assertThat(result)
.isEqualTo("{\n" +
" \"apiVersion\" : \"v1\",\n" +
" \"kind\" : \"ConfigMap\",\n" +
" \"metadata\" : {\n" +
" \"name\" : \"test\"\n" +
" },\n" +
" \"data\" : {\n" +
" \"key\" : \"value\"\n" +
" }\n" +
"}");
.isEqualTo(String.format("{%n" +
" \"apiVersion\" : \"v1\",%n" +
" \"kind\" : \"ConfigMap\",%n" +
" \"metadata\" : {%n" +
" \"name\" : \"test\"%n" +
" },%n" +
" \"data\" : {%n" +
" \"key\" : \"value\"%n" +
" }%n" +
"}"));
}

@Test
Expand All @@ -182,16 +182,16 @@ void saveJson_withConfigMap_savesFile(@TempDir Path targetDir) throws IOExceptio
// Then
assertThat(targetFile)
.content()
.isEqualTo("{\n" +
" \"apiVersion\" : \"v1\",\n" +
" \"kind\" : \"ConfigMap\",\n" +
" \"metadata\" : {\n" +
" \"name\" : \"test\"\n" +
" },\n" +
" \"data\" : {\n" +
" \"key\" : \"value\"\n" +
" }\n" +
"}");
.isEqualTo(String.format("{%n" +
" \"apiVersion\" : \"v1\",%n" +
" \"kind\" : \"ConfigMap\",%n" +
" \"metadata\" : {%n" +
" \"name\" : \"test\"%n" +
" },%n" +
" \"data\" : {%n" +
" \"key\" : \"value\"%n" +
" }%n" +
"}"));
}

@Test
Expand Down

0 comments on commit b7e1d6c

Please sign in to comment.