Search in sources :

Example 11 with ConsoleResult

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

the class CachedGoConfigIntegrationTest method setupExternalConfigRepo.

private Modification setupExternalConfigRepo(File configRepo, String configRepoTestResource) throws IOException {
    ClassPathResource resource = new ClassPathResource(configRepoTestResource);
    FileUtils.copyDirectory(resource.getFile(), configRepo);
    CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("init").withArg(configRepo.getAbsolutePath()).runOrBomb(null);
    CommandLine.createCommandLine("git").withEncoding("utf-8").withArgs("config", "commit.gpgSign", "false").withWorkingDir(configRepo.getAbsoluteFile()).runOrBomb(null);
    gitAddDotAndCommit(configRepo);
    ConsoleResult consoleResult = CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("log").withArg("-1").withArg("--pretty=format:%h").withWorkingDir(configRepo).runOrBomb(null);
    Modification modification = new Modification();
    modification.setRevision(consoleResult.outputAsString());
    return modification;
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 12 with ConsoleResult

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

the class ProcessWrapperTest method shouldCollectOutput.

@Test
public void shouldCollectOutput() throws Exception {
    String output = "SYSOUT: Hello World!";
    String error = "SYSERR: Some error happened!";
    CommandLine line = CommandLine.createCommandLine("ruby").withArgs(script("echo"), output, error);
    ConsoleResult result = run(line);
    assertThat("Errors: " + result.errorAsString(), result.returnValue(), is(0));
    assertThat(result.output(), contains(output));
    assertThat(result.error(), contains(error));
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 13 with ConsoleResult

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

the class ProcessWrapperTest method shouldReportReturnValueIfProcessFails.

@Test
public void shouldReportReturnValueIfProcessFails() {
    CommandLine line = CommandLine.createCommandLine("ruby").withArgs(script("nonexistent-script"));
    ConsoleResult result = run(line);
    assertThat(result.returnValue(), is(1));
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) Test(org.junit.Test)

Example 14 with ConsoleResult

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

the class ProcessWrapperTest method shouldAcceptInputString.

@Test
public void shouldAcceptInputString() throws Exception {
    String input = "SYSIN: Hello World!";
    CommandLine line = CommandLine.createCommandLine("ruby").withArgs(script("echo-input"));
    ConsoleResult result = run(line, input);
    assertThat(result.output(), contains(input));
    assertThat(result.error().size(), is(0));
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 15 with ConsoleResult

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

the class GoRepoConfigDataSourceIntegrationTest method setupExternalConfigRepo.

private String setupExternalConfigRepo(File configRepo, String configRepoTestResource) throws IOException {
    ClassPathResource resource = new ClassPathResource(configRepoTestResource);
    FileUtils.copyDirectory(resource.getFile(), configRepo);
    CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("init").withArg(configRepo.getAbsolutePath()).runOrBomb("");
    CommandLine.createCommandLine("git").withEncoding("utf-8").withArgs("config", "commit.gpgSign", "false").withWorkingDir(configRepo.getAbsoluteFile()).runOrBomb("");
    gitAddDotAndCommit(configRepo);
    ConsoleResult consoleResult = CommandLine.createCommandLine("git").withEncoding("utf-8").withArg("log").withArg("-1").withArg("--pretty=format:%h").withWorkingDir(configRepo).runOrBomb("");
    return consoleResult.outputAsString();
}
Also used : ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) ClassPathResource(org.springframework.core.io.ClassPathResource)

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