@Override public Ports ports(String service) throws IOException, InterruptedException { return Ports.parseFromDockerComposePs(psOutput(service), dockerMachine.getIp()); }
@Override public Ports ports(String service) throws IOException, InterruptedException { return Ports.parseFromDockerComposePs(psOutput(service), dockerMachine.getIp()); }
@Override public Ports ports(String service) throws IOException, InterruptedException { return Ports.parseFromDockerComposePs(psOutput(service), dockerMachine.getIp()); }
@Test public void result_in_no_ports_when_there_are_no_ports_in_ps_output() { String psOutput = "------"; Ports ports = Ports.parseFromDockerComposePs(psOutput, null); Ports expected = new Ports(emptyList()); assertThat(ports, is(expected)); }
@Test public void result_in_no_ports_when_there_is_a_non_mapped_exposed_port() { String psOutput = "5432/tcp"; Ports ports = Ports.parseFromDockerComposePs(psOutput, LOCALHOST_IP); Ports expected = new Ports(emptyList()); assertThat(ports, is(expected)); }
@Test public void result_in_single_port_when_there_is_single_tcp_port_mapping() { String psOutput = "0.0.0.0:5432->5432/tcp"; Ports ports = Ports.parseFromDockerComposePs(psOutput, LOCALHOST_IP); Ports expected = new Ports(newArrayList(new DockerPort(LOCALHOST_IP, 5432, 5432))); assertThat(ports, is(expected)); }
@Test public void result_in_single_port_with_ip_other_than_localhost_when_there_is_single_tcp_port_mapping() { String psOutput = "10.0.1.2:1234->2345/tcp"; Ports ports = Ports.parseFromDockerComposePs(psOutput, LOCALHOST_IP); Ports expected = new Ports(newArrayList(new DockerPort("10.0.1.2", 1234, 2345))); assertThat(ports, is(expected)); }
@Test public void parse_actual_docker_compose_output() { String psOutput = " Name Command State Ports \n" + "-------------------------------------------------------------------------------------------------------------------------------------------------\n" + "postgres_postgres_1 /bin/sh -c /usr/local/bin/ ... Up 0.0.0.0:8880->8880/tcp, 8881/tcp, 8882/tcp, 8883/tcp, 8884/tcp, 8885/tcp, 8886/tcp \n" + ""; Ports ports = Ports.parseFromDockerComposePs(psOutput, LOCALHOST_IP); Ports expected = new Ports(newArrayList(new DockerPort(LOCALHOST_IP, 8880, 8880))); assertThat(ports, is(expected)); }
@Test public void throw_illegal_state_exception_when_no_running_container_found_for_service() { exception.expect(IllegalArgumentException.class); exception.expectMessage("No container found"); Ports.parseFromDockerComposePs("", ""); } }
@Test public void result_in_two_ports_when_there_are_two_tcp_port_mappings() { String psOutput = "0.0.0.0:5432->5432/tcp, 0.0.0.0:5433->5432/tcp"; Ports ports = Ports.parseFromDockerComposePs(psOutput, LOCALHOST_IP); Ports expected = new Ports(newArrayList(new DockerPort(LOCALHOST_IP, 5432, 5432), new DockerPort(LOCALHOST_IP, 5433, 5432))); assertThat(ports, is(expected)); }