-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #605 from mageddo/develop
Develop Merge
- Loading branch information
Showing
9 changed files
with
267 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=3.32.2-snapshot | ||
version=3.32.3-snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...t/java/com/mageddo/dnsproxyserver/docker/dataprovider/ContainerFacadeDefaultCompTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.mageddo.dnsproxyserver.docker.dataprovider; | ||
|
||
import com.github.dockerjava.api.DockerClient; | ||
import com.github.dockerjava.api.model.Container; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import testing.templates.docker.ContainerTemplates; | ||
import testing.templates.docker.DockerClientTemplates; | ||
import testing.templates.docker.InspectContainerResponseTemplates; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.spy; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ContainerFacadeDefaultCompTest { | ||
|
||
ContainerFacadeDefault dao; | ||
|
||
DockerClient dockerClient; | ||
|
||
@BeforeEach | ||
void before(){ | ||
this.dockerClient = DockerClientTemplates.buildSpy(); | ||
this.dao = spy(new ContainerFacadeDefault(this.dockerClient)); | ||
} | ||
|
||
@Test | ||
void mustFindContainerById(){ | ||
// arrange | ||
final var mockReturn = new ArrayList<Container>(); | ||
mockReturn.add(ContainerTemplates.buildDpsContainer()); | ||
mockReturn.add(ContainerTemplates.buildRegularContainerCoffeeMakerCheckout()); | ||
|
||
final var containerId = mockReturn.get(0).getId(); | ||
|
||
final var inspectContainerCmd = this.dockerClient.listContainersCmd(); | ||
doReturn(mockReturn) | ||
.when(inspectContainerCmd) | ||
.exec() | ||
; | ||
|
||
// act | ||
final var container = this.dao.findById(containerId); | ||
|
||
// assert | ||
assertEquals(mockReturn.get(0), container); | ||
} | ||
|
||
@Test | ||
void mustReturnNullWhenFindContainerByIdNotFound(){ | ||
// arrange | ||
final var mockReturn = new ArrayList<Container>(); | ||
|
||
final var containerId = "abc123"; | ||
|
||
final var listContainerCmd = this.dockerClient.listContainersCmd(); | ||
doReturn(mockReturn) | ||
.when(listContainerCmd) | ||
.exec() | ||
; | ||
|
||
// act | ||
final var container = this.dao.findById(containerId); | ||
|
||
// assert | ||
assertNull(container); | ||
} | ||
|
||
@Test | ||
void mustListActiveContainers(){ | ||
// arrange | ||
final var expected = new ArrayList<Container>(); | ||
expected.add(ContainerTemplates.buildRegularContainerCoffeeMakerCheckout()); | ||
|
||
final var listContainerCmd = this.dockerClient.listContainersCmd(); | ||
doReturn(expected) | ||
.when(listContainerCmd) | ||
.exec() | ||
; | ||
|
||
// act | ||
final var findActiveContainersResponse = this.dao.findActiveContainers(); | ||
|
||
// assert | ||
assertEquals(expected, findActiveContainersResponse); | ||
} | ||
|
||
@Test | ||
void mustInspectContainerById(){ | ||
// arrange | ||
final var expected = InspectContainerResponseTemplates.ngixWithDefaultBridgeNetworkOnly(); | ||
final var containerId = expected.getId(); | ||
|
||
final var inspectContainerCmd = this.dockerClient.inspectContainerCmd(containerId); | ||
doReturn(expected) | ||
.when(inspectContainerCmd) | ||
.exec() | ||
; | ||
|
||
// act | ||
final var inspectResponse = this.dao.inspect(containerId); | ||
|
||
// assert | ||
assertEquals(expected, inspectResponse); | ||
} | ||
|
||
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/test/java/com/mageddo/dnsproxyserver/docker/dataprovider/ContainerFacadeDefaultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.mageddo.dnsproxyserver.docker.dataprovider; | ||
|
||
import com.github.dockerjava.api.exception.NotFoundException; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import testing.templates.docker.ContainerTemplates; | ||
import testing.templates.docker.InspectContainerResponseTemplates; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.doThrow; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ContainerFacadeDefaultTest { | ||
|
||
@Spy | ||
@InjectMocks | ||
ContainerFacadeDefault facade; | ||
|
||
@Test | ||
void mustNotThrowErrorWhenInspectContainerGetNotFound() { | ||
// arrange | ||
final var containerId = "a39bba9a8bab2899"; | ||
|
||
doThrow(new NotFoundException("Container not found")) | ||
.when(this.facade).inspect(containerId) | ||
; | ||
|
||
// act | ||
final var container = this.facade.safeInspect(containerId); | ||
|
||
// assert | ||
assertNull(container); | ||
} | ||
|
||
@Test | ||
void mustNotThrowErrorWhenInspectContainerFails() { | ||
// arrange | ||
final var containerId = "a39bba9a8bab28aa"; | ||
|
||
doThrow(new NullPointerException("Unexpected failure")) | ||
.when(this.facade).inspect(containerId) | ||
; | ||
|
||
// act | ||
final var container = this.facade.safeInspect(containerId); | ||
|
||
// assert | ||
assertNull(container); | ||
} | ||
|
||
@Test | ||
void mustFilterNullContainerInspections() { | ||
final var c1 = ContainerTemplates.buildRegularContainerCoffeeMakerCheckout(); | ||
final var c2 = ContainerTemplates.buildDpsContainer(); | ||
final var containers = List.of(c1, c2); | ||
|
||
doReturn(InspectContainerResponseTemplates.withDpsLabel()) | ||
.when(this.facade).safeInspect(c1.getId()) | ||
; | ||
|
||
doReturn(null) | ||
.when(this.facade).safeInspect(c2.getId()) | ||
; | ||
|
||
final var filtered = this.facade.inspectFilteringValidContainers(containers) | ||
.toList(); | ||
|
||
assertEquals(1, filtered.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters