Skip to content

Commit

Permalink
Merge pull request #146 from palantir/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
iamdanfox authored Feb 6, 2017
2 parents d35070e + 3529834 commit 5622a90
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,18 @@
import static java.util.Collections.emptyList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.IOException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class PortsShould {

public static final String LOCALHOST_IP = "127.0.0.1";
private static final String LOCALHOST_IP = "127.0.0.1";
@Rule
public ExpectedException exception = ExpectedException.none();

private final DockerPort port = mock(DockerPort.class);

@Before
public void setup() {
when(port.getInternalPort()).thenReturn(7001);
when(port.getExternalPort()).thenReturn(7000);
}

@Test
public void result_in_no_ports_when_there_are_no_ports_in_ps_output() throws IOException, InterruptedException {
String psOutput = "------";
Expand Down Expand Up @@ -90,10 +79,10 @@ public void parse_actual_docker_compose_output() throws IOException, Interrupted
String psOutput =
" Name Command State Ports \n"
+ "-------------------------------------------------------------------------------------------------------------------------------------------------\n"
+ "magritte_magritte_1 /bin/sh -c /usr/local/bin/ ... Up 0.0.0.0:7000->7000/tcp, 7001/tcp, 7002/tcp, 7003/tcp, 7004/tcp, 7005/tcp, 7006/tcp \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, 7000, 7000)));
Ports expected = new Ports(newArrayList(new DockerPort(LOCALHOST_IP, 8880, 8880)));
assertThat(ports, is(expected));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void parse_actual_docker_compose_output_when_state_is_Up() throws IOExcep
String psOutput =
" Name Command State Ports \n"
+ "-------------------------------------------------------------------------------------------------------------------------------------------------\n"
+ "magritte_magritte_1 /bin/sh -c /usr/local/bin/ ... Up 0.0.0.0:7000->7000/tcp, 7001/tcp, 7002/tcp, 7003/tcp, 7004/tcp, 7005/tcp, 7006/tcp \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"
+ "";
State state = State.parseFromDockerComposePs(psOutput);
assertThat(state, is(State.Up));
Expand All @@ -45,7 +45,7 @@ public void parse_actual_docker_compose_output_when_state_is_Exit() throws IOExc
String psOutput =
" Name Command State Ports \n"
+ "-------------------------------------------------------------------------------------------------------------------------------------------------\n"
+ "magritte_magritte_1 /bin/sh -c /usr/local/bin/ ... Exit 0.0.0.0:7000->7000/tcp, 7001/tcp, 7002/tcp, 7003/tcp, 7004/tcp, 7005/tcp, 7006/tcp \n"
+ "postgres_postgres_1 /bin/sh -c /usr/local/bin/ ... Exit 0.0.0.0:8880->8880/tcp, 8881/tcp, 8882/tcp, 8883/tcp, 8884/tcp, 8885/tcp, 8886/tcp \n"
+ "";
State state = State.parseFromDockerComposePs(psOutput);
assertThat(state, is(State.Exit));
Expand All @@ -56,7 +56,7 @@ public void throw_on_unknown_state() throws IOException, InterruptedException {
String psOutput =
" Name Command State Ports \n"
+ "-------------------------------------------------------------------------------------------------------------------------------------------------\n"
+ "magritte_magritte_1 /bin/sh -c /usr/local/bin/ ... WhatIsThis 0.0.0.0:7000->7000/tcp, 7001/tcp, 7002/tcp, 7003/tcp, 7004/tcp, 7005/tcp, 7006/tcp \n"
+ "postgres_postgres_1 /bin/sh -c /usr/local/bin/ ... WhatIsThis 0.0.0.0:8880->8880/tcp, 8881/tcp, 8882/tcp, 8883/tcp, 8884/tcp, 8885/tcp, 8886/tcp \n"
+ "";
exception.expect(IllegalStateException.class);
State.parseFromDockerComposePs(psOutput);
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-rule-core/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<Configuration monitorInterval="5">
<Appenders>
<RollingFile name="LOG" fileName="logs/magritte.log" filePattern="logs/magritte-%d{yyyy-MM-dd}.log.gz">
<RollingFile name="LOG" fileName="logs/docker-compose-rule.log" filePattern="logs/docker-compose-rule-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="%d{ISO8601} %-5p - %t %c - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1"/>
Expand Down

0 comments on commit 5622a90

Please sign in to comment.