Search in sources :

Example 6 with ConsoleResult

use of com.thoughtworks.go.util.command.ConsoleResult in project gocd by gocd.

the class P4OutputParserTest method shouldParseChangesWithLotsOfFilesWithoutError.

/*
     * This test reproduces a problem we saw at a customer's installation, where the changelist was really really large
     * It caused a frequent StackOverflow in the java regex library.
     */
@Test
void shouldParseChangesWithLotsOfFilesWithoutError() throws IOException, P4OutputParseException {
    final StringWriter writer = new StringWriter();
    IOUtils.copy(new ClassPathResource("/BIG_P4_OUTPUT.txt").getInputStream(), writer, Charset.defaultCharset());
    String output = writer.toString();
    Modification modification = parser.modificationFromDescription(output, new ConsoleResult(0, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()));
    assertThat(modification.getModifiedFiles().size()).isEqualTo(1304);
    assertThat(modification.getModifiedFiles().get(0).getFileName()).isEqualTo("Internal Projects/ABC/Customers3/ABC/RIP/SomeProject/data/main/config/lib/java/AdvJDBCColumnHandler.jar");
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 7 with ConsoleResult

use of com.thoughtworks.go.util.command.ConsoleResult in project gocd by gocd.

the class P4OutputParserTest method shouldRetrieveModificationFromDescription.

@Test
void shouldRetrieveModificationFromDescription() throws P4OutputParseException, ParseException {
    String output = "Change 2 by cce123user@connect4_10.18.2.31 on 2008/08/19 15:04:43\n" + "\n" + "\tAdded config file\n" + "\n" + "Affected files ...\n" + "\n" + "... //depot/cruise-config.xml#1 add\n" + "... //depot/README.txt#2 edit\n" + "... //depot/cruise-output/log.xml#1 delete\n" + "";
    Modification mod = parser.modificationFromDescription(output, new ConsoleResult(0, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()));
    assertThat(mod.getRevision()).isEqualTo("2");
    assertThat(mod.getUserName()).isEqualTo("cce123user@connect4_10.18.2.31");
    assertThat(mod.getModifiedTime()).isEqualTo(DESCRIPTION_FORMAT.parse("2008/08/19 15:04:43"));
    assertThat(mod.getComment()).isEqualTo("Added config file");
    List<ModifiedFile> files = mod.getModifiedFiles();
    assertThat(files.size()).isEqualTo(3);
    assertThat(files.get(0).getAction()).isEqualTo(ModifiedAction.added);
    assertThat(files.get(0).getFileName()).isEqualTo("cruise-config.xml");
    assertThat(files.get(1).getAction()).isEqualTo(ModifiedAction.modified);
    assertThat(files.get(2).getAction()).isEqualTo(ModifiedAction.deleted);
    assertThat(files.get(2).getFileName()).isEqualTo("cruise-output/log.xml");
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) ArrayList(java.util.ArrayList) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) Test(org.junit.jupiter.api.Test)

Example 8 with ConsoleResult

use of com.thoughtworks.go.util.command.ConsoleResult in project gocd by gocd.

the class P4OutputParserTest method shouldParseCorrectlyWhenCommentIsEmpty.

@Test
void shouldParseCorrectlyWhenCommentIsEmpty() throws P4OutputParseException {
    String description = "Change 102 by godev@blrstdcrspair03 on 2013/06/04 12:00:35\n" + "\n" + "\n" + "Affected files ...\n" + "\n" + "... //another_depot/1.txt#6 edit";
    Modification modification = parser.modificationFromDescription(description, new ConsoleResult(0, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()));
    assertThat(modification.getComment()).isEqualTo("");
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 9 with ConsoleResult

use of com.thoughtworks.go.util.command.ConsoleResult in project gocd by gocd.

the class HgModificationSplitterTest method shouldBeAbleToParseModifications.

@Test
public void shouldBeAbleToParseModifications() throws Exception {
    ConsoleResult result = new ConsoleResult(0, Arrays.asList(("<changeset>\n" + "<node>ca3ebb67f527c0ad7ed26b789056823d8b9af23f</node>\n" + "<author>cruise</author>\n" + "<date>Tue, 09 Dec 2008 18:56:14 +0800</date>\n" + "<desc>test</desc>\n" + "<files>\n" + "<modified>\n" + "<file>end2end/file</file>\n" + "</modified>\n" + "<added>\n" + "<file>end2end/file</file>\n" + "</added>\n" + "<deleted>\n" + "</deleted>\n" + "</files>\n" + "</changeset>").split("\n")), new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
    HgModificationSplitter splitter = new HgModificationSplitter(result);
    List<Modification> list = splitter.modifications();
    assertThat(list.size(), is(1));
    assertThat(list.get(0).getModifiedTime(), is(new DateTime("2008-12-09T18:56:14+08:00").toDate()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 10 with ConsoleResult

use of com.thoughtworks.go.util.command.ConsoleResult in project gocd by gocd.

the class P4Fixture method stopP4d.

private void stopP4d(P4Client p4) {
    try {
        p4.admin("stop");
        ConsoleResult consoleResult = p4.checkConnection();
        while (!consoleResult.failed()) {
            try {
                // Wait for the server to shutdown
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
        }
    } catch (CommandLineException expected) {
        // Stopping p4d on windows returns the following failure:
        if (expected.getResult().errorAsString().contains("WSAECONNRESET") || expected.getResult().errorAsString().contains("WSAECONNREFUSED")) {
            return;
        }
        if (expected.getResult().errorAsString().contains("Connection refused") || expected.getResult().errorAsString().contains("Connection reset")) {
            return;
        }
        throw expected;
    }
}
Also used : ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) CommandLineException(com.thoughtworks.go.util.command.CommandLineException)

Aggregations

ConsoleResult (com.thoughtworks.go.util.command.ConsoleResult)24 Test (org.junit.jupiter.api.Test)12 Modification (com.thoughtworks.go.domain.materials.Modification)11 ArrayList (java.util.ArrayList)10 CommandLine (com.thoughtworks.go.util.command.CommandLine)5 Test (org.junit.Test)5 ClassPathResource (org.springframework.core.io.ClassPathResource)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)1 LogFixture (com.thoughtworks.go.util.LogFixture)1 CommandLineException (com.thoughtworks.go.util.command.CommandLineException)1 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)1 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)1 StringWriter (java.io.StringWriter)1 DateTime (org.joda.time.DateTime)1