public OperatingSystemInterface currentOperatingSystem() { return OperatingSystem.resolve(osNameProperty); } }
static public OperatingSystem resolve(String osName) { for (OperatingSystem os : OperatingSystem.values()) { if (os.label.equalsIgnoreCase(osName)) return os; } return OperatingSystem.UNKNOWN_OS; }
@Test public void shouldDetectsValidDockerDefault() throws Exception { CubeDockerConfigurationResolver resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(null), new Boot2Docker(null), mockDefaultDocker(), operatingSystemInterface); when(info.getName()).thenReturn("docker-ce"); when(info.getServerVersion()).thenReturn("arquillian-test"); when(info.getKernelVersion()).thenReturn("0.0.0"); URL sockURL = this.getClass().getClassLoader().getResource("docker.sock"); String sockUri = "unix://" + sockURL; when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri); when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface); when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.MAC_OSX.getFamily()); Map<String, String> config = new HashMap<>(); Map<String, String> resolvedConfig = resolver.resolve(config); assertThat(Boolean.valueOf(resolvedConfig.get(CubeDockerConfiguration.TLS_VERIFY)), is(false)); assertThat(resolvedConfig.get(CubeDockerConfiguration.CERT_PATH), is(nullValue())); assertThat(resolvedConfig.get(CubeDockerConfiguration.DOCKER_URI), is(sockUri)); }
@Test public void shouldNotSetTlsVerifyForTcpSchemeOnOSX() { CubeDockerConfigurationResolver resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(null), new Boot2Docker(null), mockDefaultDocker(), operatingSystemInterface); 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()); Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://localhost:2376"); Map<String, String> resolvedConfig = resolver.resolve(config); assertThat(Boolean.valueOf(resolvedConfig.get(CubeDockerConfiguration.TLS_VERIFY)), is(false)); assertThat(resolvedConfig.get(CubeDockerConfiguration.CERT_PATH), is(nullValue())); }
@Test public void shouldSkipsInvalidDockerDefault() throws Exception { CubeDockerConfigurationResolver resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(null), new Boot2Docker(boot2dockerCommandLineExecutor), mockDefaultDocker(), operatingSystemInterface); when(boot2dockerCommandLineExecutor.execCommand(Matchers.<String>anyVararg())).thenReturn("127.0.0.1"); 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()); Map<String, String> config = new HashMap<>(); Map<String, String> resolvedConfig = resolver.resolve(config); assertThat(Boolean.valueOf(resolvedConfig.get(CubeDockerConfiguration.TLS_VERIFY)), is(true)); assertThat(resolvedConfig.get(CubeDockerConfiguration.DOCKER_URI), is("tcp://127.0.0.1:2376")); }
static public OperatingSystem resolve(String osName) { for (OperatingSystem os : OperatingSystem.values()) { if (os.label.equalsIgnoreCase(osName)) return os; } return OperatingSystem.UNKNOWN_OS; }
public OperatingSystemInterface currentOperatingSystem() { return OperatingSystem.resolve(osNameProperty); } }
@Test public void shouldNotSetTlsVerifyForTcpSchemeOnLinux() { CubeDockerConfigurationResolver resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(null), new Boot2Docker(null), mockDefaultDocker(), operatingSystemInterface); 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()); Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://localhost:2376"); Map<String, String> resolvedConfig = resolver.resolve(config); assertThat(Boolean.valueOf(resolvedConfig.get(CubeDockerConfiguration.TLS_VERIFY)), is(false)); assertThat(resolvedConfig.get(CubeDockerConfiguration.CERT_PATH), is(nullValue())); } }