Skip to content

Commit

Permalink
add unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeddada1 committed May 23, 2024
1 parent f16f6a7 commit 8f81743
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.cloud.tools.jib.json.JsonTemplate;

/** Contains the os and architecture from {@code docker info}. */
/** Contains docker info details outputted by {@code docker info}. */
@JsonIgnoreProperties(ignoreUnknown = true)
public class DockerInfoDetails implements JsonTemplate {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ public void testInfo_fail() throws InterruptedException {
.contains("'docker info' command failed with error: error");
}

@Test
public void testInfo_returnsUnknownKeys() throws InterruptedException, IOException {
String dockerInfoJson = "{ \"unknownOS\": \"windows\"," + "\"unknownArchitecture\": \"arm64\"}";
DockerClient testDockerClient =
new CliDockerClient(
subcommand -> {
assertThat(subcommand).containsExactly("info", "-f", "{{json .}}");
return mockProcessBuilder;
});
Mockito.when(mockProcess.waitFor()).thenReturn(0);
Mockito.when(mockProcess.getInputStream())
.thenReturn(new ByteArrayInputStream(dockerInfoJson.getBytes()));

DockerInfoDetails infoDetails = testDockerClient.info();
assertThat(infoDetails.getArchitecture()).isEmpty();
assertThat(infoDetails.getOsType()).isEmpty();
}

@Test
public void testLoad() throws IOException, InterruptedException {
DockerClient testDockerClient =
Expand Down

0 comments on commit 8f81743

Please sign in to comment.