Skip to content

Commit

Permalink
[issues-1269] Fixing the tests in docker module
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiobrz committed Dec 15, 2023
1 parent f54f9f8 commit bc5c1a3
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.List;
import org.assertj.core.api.ListAssert;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Eddú Meléndez
*/
Expand All @@ -22,12 +20,12 @@ public ImagesAssert containsImages(String... imageIds) {
for (Image image : this.actual) {
imageList.add(image.getId());
}
/** rls TODO https://github.com/arquillian/arquillian-cube/issues/1289
assertThat(this.actual)

org.assertj.core.api.Assertions.assertThat(this.actual)
.extracting("id")
.overridingErrorMessage("%nExpecting:%n <%s>%nto contain:%n <%s>", imageList, Arrays.asList(imageIds))
.contains(imageIds);
**/

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.hamcrest.collection.IsMapContaining.hasKey;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeThat;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -76,8 +77,8 @@ private static Matcher<String> pathEndsWith(String suffix) {
}

private void bindNonExistingDockerSocketOS() {
when(operatingSystem.getDefaultFamily()).thenReturn(operatingSystemFamily);
when(operatingSystem.getFamily()).thenReturn(OperatingSystemFamily.MAC);
lenient().when(operatingSystem.getDefaultFamily()).thenReturn(operatingSystemFamily);
lenient().when(operatingSystem.getFamily()).thenReturn(OperatingSystemFamily.MAC);
when(operatingSystemFamily.getServerUri()).thenReturn("non/existing/path");

bind(ApplicationScoped.class, OperatingSystemInterface.class, operatingSystem);
Expand Down Expand Up @@ -107,8 +108,8 @@ public void shouldChangeServerUriInCaseOfRunningDockerInsideDocker() {
config.put(CubeDockerConfiguration.DOCKER_URI, "https://dockerHost:22222");

when(extensionDef.getExtensionProperties()).thenReturn(config);
when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef);
when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1");
lenient().when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef);
lenient().when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1");
when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException());
when(top.isSpinning()).thenReturn(true);

Expand All @@ -127,7 +128,7 @@ public void shouldNotChangeServerUriInCaseODockerInsideDockerIfItIsDisabled() {
when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1");
when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException());

when(top.isSpinning()).thenReturn(true);
lenient().when(top.isSpinning()).thenReturn(true);

fire(new CubeConfiguration());
assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.1:22222"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.arquillian.cube.docker.impl.util.Top;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.runner.RunWith;
Expand All @@ -31,6 +30,7 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
Expand Down Expand Up @@ -94,7 +94,7 @@ public void shouldDetectsValidDockerDefault() throws Exception {
String sockUri = isWindows ?sockURL.toExternalForm().replace("file:/", "") : "unix://" + sockURL.toExternalForm();
when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri);
when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface);
when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.MAC_OSX.getFamily());
lenient().when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.MAC_OSX.getFamily());

Map<String, String> config = new HashMap<>();

Expand All @@ -116,7 +116,7 @@ public void shouldSkipsInvalidDockerDefault() throws Exception {
new Boot2Docker(boot2dockerCommandLineExecutor),
mockDefaultDocker(),
operatingSystemInterface);
when(boot2dockerCommandLineExecutor.execCommand(ArgumentMatchers.<String>any())).thenReturn("127.0.0.1");
when(boot2dockerCommandLineExecutor.execCommand(anyString(), anyString())).thenReturn("127.0.0.1");

String sockUri = "unix:///a/path-that/does/not/exist";
when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri);
Expand All @@ -139,11 +139,11 @@ public void shouldNotSetTlsVerifyForTcpSchemeOnOSX() {
mockDefaultDocker(),
operatingSystemInterface);

when(infoCmd.exec()).thenThrow(new ProcessingException("test exception"));
lenient().when(infoCmd.exec()).thenThrow(new ProcessingException("test exception"));
String sockUri = "unix:///a/path-that/does/not/exist";
when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri);
when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface);
when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.MAC_OSX.getFamily());
lenient().when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri);
lenient().when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface);
lenient().when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.MAC_OSX.getFamily());

Map<String, String> config = new HashMap<>();
config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://localhost:2376");
Expand All @@ -161,12 +161,12 @@ public void shouldNotSetTlsVerifyForTcpSchemeOnLinux() {
new Boot2Docker(null),
mockDefaultDocker(),
operatingSystemInterface);
when(infoCmd.exec()).thenThrow(new ProcessingException("test exception"));
lenient().when(infoCmd.exec()).thenThrow(new ProcessingException("test exception"));

String sockUri = "unix:///a/path-that/does/not/exist";
when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri);
when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface);
when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.LINUX_OS.getFamily());
lenient().when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri);
lenient().when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface);
lenient().when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.LINUX_OS.getFamily());

Map<String, String> config = new HashMap<>();
config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://localhost:2376");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -111,9 +112,9 @@ public void shouldCreateAndStartAutoContainersWhenNoAutoStartIsProvided() {
ContainerRegistry containerRegistry = mock(ContainerRegistry.class);
List<org.jboss.arquillian.container.spi.Container> containers = new ArrayList<>();
org.jboss.arquillian.container.spi.Container container = mock(org.jboss.arquillian.container.spi.Container.class);
when(container.getName()).thenReturn("a");
lenient().when(container.getName()).thenReturn("a");
containers.add(container);
when(containerRegistry.getContainers()).thenReturn(containers);
lenient().when(containerRegistry.getContainers()).thenReturn(containers);

bind(ApplicationScoped.class, ContainerRegistry.class, containerRegistry);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.arquillian.cube.docker.impl.client.container;

import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void setup() {
Map<String, Object> content = (Map<String, Object>) yaml.load(CONTENT);

when(cube.getId()).thenReturn(CUBE_ID);
when(cube.configuration()).thenReturn(content);
lenient().when(cube.configuration()).thenReturn(content);
when(container.getName()).thenReturn(CUBE_ID);
when(container.getDeployableContainer()).thenReturn(deployableContainer);
when(deployableContainer.getConfigurationClass()).thenReturn(ContainerConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void shouldLinkInnerContainersWithoutLink() {
verify(cubeController, times(1)).create("containerWithNonAnnotatedLink");
verify(cubeController, times(1)).start("containerWithNonAnnotatedLink");

verify(cubeContainerObjectTestEnricher, times(1)).enrich(any(TestContainerObjectWithAnnotatedLink.class));
verify(cubeContainerObjectTestEnricher, times(1)).enrich(any(TestContainerObjectWithNonAnnotatedLink.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void should_start_a_network() {
containerNetworkObjectDslTestEnricher.networkRegistryInstance = () -> networkRegistry;
containerNetworkObjectDslTestEnricher.dockerClientExecutorInstance = () -> dockerClientExecutor;

when(injector.inject(any(Network.class))).then(invocation -> invocation.getArgument(0, Network.class));
lenient().when(injector.inject(any(Network.class))).then(invocation -> invocation.getArgument(0, Network.class));
when(dockerClientExecutor.createNetwork(eq("default"), any(org.arquillian.cube.docker.impl.client.config.Network.class))).thenReturn("default");

containerNetworkObjectDslTestEnricher.enrich(new NetworkTest());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.arquillian.cube.docker.impl.requirement;

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;

import org.arquillian.cube.docker.impl.util.CommandLineExecutor;
import org.arquillian.cube.spi.requirement.UnsatisfiedRequirementException;
import org.arquillian.spacelift.execution.ExecutionException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.ArgumentMatchers.any;

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
Expand All @@ -22,39 +23,44 @@ public class DockerMachineRequirementTest {

@Test(expected = UnsatisfiedRequirementException.class)
public void estDockerMachineRequirementCheckWhenExecutionExceptionThrown() throws UnsatisfiedRequirementException {
when(commandLineExecutor.execCommandAsArray(any())).thenThrow(ExecutionException.class);
when(commandLineExecutor.execCommandAsArray(anyString(), anyString(), anyString(), anyString(), anyString(), anyString()))
.thenThrow(ExecutionException.class);

DockerMachineRequirement dockerMachineRequirement = new DockerMachineRequirement(commandLineExecutor);
dockerMachineRequirement.check(createContext("testing"));
}

@Test(expected = UnsatisfiedRequirementException.class)
public void testDockerMachineRequirementCheckNoMatchingNameFound() throws Exception {
when(commandLineExecutor.execCommandAsArray(any())).thenReturn(Collections.emptyList());
when(commandLineExecutor.execCommandAsArray(anyString(), anyString(), anyString(), anyString(), anyString(), anyString()))
.thenReturn(Collections.emptyList());

DockerMachineRequirement dockerMachineRequirement = new DockerMachineRequirement(commandLineExecutor);
dockerMachineRequirement.check(createContext("testing"));
}

@Test(expected = UnsatisfiedRequirementException.class)
public void testDockerMachineRequirementCheckNoMachineFound() throws Exception {
when(commandLineExecutor.execCommandAsArray(any())).thenReturn(Arrays.asList(new String[] {"foo", "bar"}));
when(commandLineExecutor.execCommandAsArray(anyString(), anyString(), anyString(), anyString()))
.thenReturn(Arrays.asList(new String[] {"foo", "bar"}));

DockerMachineRequirement dockerMachineRequirement = new DockerMachineRequirement(commandLineExecutor);
dockerMachineRequirement.check(createContext(""));
}

@Test(expected = UnsatisfiedRequirementException.class)
public void testDockerMachineRequirementCheckNoMatchingNameNotMatched() throws Exception {
when(commandLineExecutor.execCommandAsArray(any())).thenReturn(Arrays.asList(new String[] {"my-docker-machine"}));
when(commandLineExecutor.execCommandAsArray(anyString(), anyString(), anyString(), anyString(), anyString(), anyString()))
.thenReturn(Arrays.asList(new String[] {"my-docker-machine"}));

DockerMachineRequirement dockerMachineRequirement = new DockerMachineRequirement(commandLineExecutor);
dockerMachineRequirement.check(createContext("testing"));
}

@Test
public void testDockerMachineRequirementCheckNoMatchingNameMatched() throws Exception {
when(commandLineExecutor.execCommandAsArray(any())).thenReturn(Arrays.asList(new String[] {"testing"}));
when(commandLineExecutor.execCommandAsArray(anyString(), anyString(), anyString(), anyString(), anyString(), anyString()))
.thenReturn(Arrays.asList(new String[] {"testing"}));

DockerMachineRequirement dockerMachineRequirement = new DockerMachineRequirement(commandLineExecutor);
dockerMachineRequirement.check(createContext("testing"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
Expand Down Expand Up @@ -65,8 +66,8 @@ public void shouldCreateCustomContainerFromImageName() {

@Test
public void shouldCreateCustomContainerFromDockerfile() {
when(cubeDroneConfiguration.isBrowserDockerfileDirectorySet()).thenReturn(true);
when(cubeDroneConfiguration.isBrowserImageSet()).thenReturn(false);
lenient().when(cubeDroneConfiguration.isBrowserDockerfileDirectorySet()).thenReturn(true);
lenient().when(cubeDroneConfiguration.isBrowserImageSet()).thenReturn(false);
when(cubeDroneConfiguration.getBrowserDockerfileLocation()).thenReturn("src/test/resources/browser");
when(cubeDroneConfiguration.getContainerNameStrategy()).thenReturn(ContainerNameStrategy.STATIC);

Expand All @@ -80,7 +81,7 @@ public void shouldCreateCustomContainerFromDockerfile() {
@Test
public void shouldTakePrecedenceDockerfileDirectoryThanImage() {
when(cubeDroneConfiguration.isBrowserDockerfileDirectorySet()).thenReturn(true);
when(cubeDroneConfiguration.isBrowserImageSet()).thenReturn(true);
lenient().when(cubeDroneConfiguration.isBrowserImageSet()).thenReturn(true);
when(cubeDroneConfiguration.getBrowserDockerfileLocation()).thenReturn("src/test/resources/browser");
when(cubeDroneConfiguration.getContainerNameStrategy()).thenReturn(ContainerNameStrategy.STATIC);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.mockito.junit.MockitoJUnitRunner;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -135,9 +136,9 @@ public void should_discard_recording_if_configured_in_only_failing_and_passed_te
final File destination = temporaryFolder.newFolder("destination");
final File video = temporaryFolder.newFile("file.flv");

when(seleniumContainers.getVideoRecordingFile()).thenReturn(video.toPath());
when(after.getTestClass()).thenReturn(new TestClass(VncRecorderLifecycleManagerTest.class));
when(after.getTestMethod()).thenReturn(VncRecorderLifecycleManagerTest.class.getMethod(
lenient().when(seleniumContainers.getVideoRecordingFile()).thenReturn(video.toPath());
lenient().when(after.getTestClass()).thenReturn(new TestClass(VncRecorderLifecycleManagerTest.class));
lenient().when(after.getTestMethod()).thenReturn(VncRecorderLifecycleManagerTest.class.getMethod(
"should_discard_recording_if_configured_in_only_failing_and_passed_test"));

Map<String, String> conf = new HashMap<>();
Expand Down

0 comments on commit bc5c1a3

Please sign in to comment.