@Test public void parse_a_semantic_and_raw_name_correctly_from_a_single_line() { ContainerName actual = ContainerName.fromPsLine("dir_db_1 other line contents"); ContainerName expected = ImmutableContainerName.builder() .rawName("dir_db_1") .semanticName("db") .build(); assertThat(actual, is(expected)); }
public static ContainerName fromPsLine(String psLine) { String[] lineComponents = psLine.split(" "); String rawName = lineComponents[0]; if (probablyCustomName(rawName)) { return ImmutableContainerName.builder() .rawName(rawName) .semanticName(rawName) .build(); } String semanticName = withoutDirectory(withoutScaleNumber(rawName)); return ImmutableContainerName.builder() .rawName(rawName) .semanticName(semanticName) .build(); }
public static ContainerName fromPsLine(String psLine) { String[] lineComponents = psLine.split(" "); String rawName = lineComponents[0]; if (probablyCustomName(rawName)) { return ImmutableContainerName.builder() .rawName(rawName) .semanticName(rawName) .build(); } String semanticName = withoutDirectory(withoutScaleNumber(rawName)); return ImmutableContainerName.builder() .rawName(rawName) .semanticName(semanticName) .build(); }
public static ContainerName fromPsLine(String psLine) { String[] lineComponents = psLine.split(" "); String rawName = lineComponents[0]; if (probablyCustomName(rawName)) { return ImmutableContainerName.builder() .rawName(rawName) .semanticName(rawName) .build(); } String semanticName = withoutDirectory(withoutScaleNumber(rawName)); return ImmutableContainerName.builder() .rawName(rawName) .semanticName(semanticName) .build(); }
@Test public void parse_and_returns_container_names_on_ps() throws IOException, InterruptedException { when(executedProcess.getInputStream()).thenReturn(toInputStream("ps\n----\ndir_db_1")); List<ContainerName> containerNames = compose.ps(); verify(executor).execute("ps"); assertThat(containerNames, contains(ImmutableContainerName.builder().semanticName("db").rawName("dir_db_1").build())); }
@Test public void can_handle_custom_container_names() { ContainerName name = ContainerName.fromPsLine("test-1.container.name /docker-entrypoint.sh postgres Up 5432/tcp"); ContainerName expected = ImmutableContainerName.builder() .rawName("test-1.container.name") .semanticName("test-1.container.name") .build(); assertThat(name, is(expected)); }
private static ContainerName containerName(String project, String semantic, String number) { return ImmutableContainerName.builder() .rawName(project + "_" + semantic + "_" + number) .semanticName(semantic) .build(); } }
private static ContainerName testContainerName(String testName) { return ImmutableContainerName.builder() .semanticName(testName) .rawName("123456_" + testName + "_1") .build(); }