private Map<String, String> resolveDockerInsideDocker(Map<String, String> cubeConfiguration) { // if DIND_RESOLUTION property is not set, since by default is enabled, we need to go inside code. if (!cubeConfiguration.containsKey(CubeDockerConfiguration.DIND_RESOLUTION) || Boolean.parseBoolean( cubeConfiguration.get(CubeDockerConfiguration.DIND_RESOLUTION))) { if (top.isSpinning()) { log.fine(String.format( "Your Cube tests are going to run inside a running Docker container. %s property is replaced to %s", CubeDockerConfiguration.DOCKER_URI, OperatingSystemFamily.DIND.getServerUri())); String serverUri = OperatingSystemFamily.DIND.getServerUri(); cubeConfiguration.put(CubeDockerConfiguration.DOCKER_URI, serverUri); } } return cubeConfiguration; }
private Map<String, String> resolveDockerInsideDocker(Map<String, String> cubeConfiguration) { // if DIND_RESOLUTION property is not set, since by default is enabled, we need to go inside code. if (!cubeConfiguration.containsKey(CubeDockerConfiguration.DIND_RESOLUTION) || Boolean.parseBoolean( cubeConfiguration.get(CubeDockerConfiguration.DIND_RESOLUTION))) { if (top.isSpinning()) { log.fine(String.format( "Your Cube tests are going to run inside a running Docker container. %s property is replaced to %s", CubeDockerConfiguration.DOCKER_URI, OperatingSystemFamily.DIND.getServerUri())); String serverUri = OperatingSystemFamily.DIND.getServerUri(); cubeConfiguration.put(CubeDockerConfiguration.DOCKER_URI, serverUri); } } return cubeConfiguration; }
@Test public void shouldNotChangeServerUriInCaseODockerInsideDockerIfItIsDisabled() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://dockerHost:22222"); config.put(CubeDockerConfiguration.DIND_RESOLUTION, "false"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1"); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); when(top.isSpinning()).thenReturn(true); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.1:22222")); }
@Test public void shouldChangeServerUriInCaseOfRunningDockerInsideDocker() { Map<String, String> config = new HashMap<>(); 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"); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); when(top.isSpinning()).thenReturn(true); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, OperatingSystemFamily.DIND.getServerUri())); }
@Test public void shouldNotStopSpinningIfRunningInsideDocker() throws IOException { temporaryFolder.newFile(Top.DOCKERENV); temporaryFolder.newFile(Top.DOCKERINIT); Top top = new Top(temporaryFolder.getRoot().getAbsolutePath(), temporaryFolder.getRoot().getAbsolutePath()); assertThat(top.isSpinning(), is(false)); } }
@Test public void shouldStopSpinningIfRunningInsideDocker() throws IOException { temporaryFolder.newFile(Top.DOCKER_SOCK); temporaryFolder.newFile(Top.DOCKERENV); temporaryFolder.newFile(Top.DOCKERINIT); Top top = new Top(temporaryFolder.getRoot().getAbsolutePath(), temporaryFolder.getRoot().getAbsolutePath()); assertThat(top.isSpinning(), is(true)); }
@Before public void setup() { bind(ApplicationScoped.class, Boot2Docker.class, new Boot2Docker(commandLineExecutor)); bind(ApplicationScoped.class, DockerMachine.class, new DockerMachine(commandLineExecutor)); bind(ApplicationScoped.class, ArquillianDescriptor.class, arquillianDescriptor); bind(ApplicationScoped.class, Top.class, top); when(top.isSpinning()).thenReturn(false); }