Search in sources :

Example 16 with CommandLine

use of com.thoughtworks.go.util.command.CommandLine 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 17 with CommandLine

use of com.thoughtworks.go.util.command.CommandLine 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 18 with CommandLine

use of com.thoughtworks.go.util.command.CommandLine 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 19 with CommandLine

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

the class ProcessWrapperTest method shouldTryCommandWithTimeout.

@Test
public void shouldTryCommandWithTimeout() throws IOException {
    CommandLine line = CommandLine.createCommandLine("doesnotexist");
    try {
        line.waitForSuccess(100);
        fail("Expected Exception");
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("Timeout after 0.1 seconds waiting for command 'doesnotexist'"));
    }
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) CommandLineException(com.thoughtworks.go.util.command.CommandLineException) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with CommandLine

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

the class GarageService method gc.

public void gc(HttpLocalizedOperationResult result) {
    CommandLine gitCheck = getGit().withArg("--version");
    InMemoryStreamConsumer consumer = new InMemoryStreamConsumer();
    if (execute(gitCheck, consumer, result)) {
        File configRepoDir = systemEnvironment.getConfigRepoDir();
        CommandLine gc = getGit().withArg("gc").withWorkingDir(configRepoDir);
        execute(gc, consumer, result);
    }
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) File(java.io.File)

Aggregations

CommandLine (com.thoughtworks.go.util.command.CommandLine)31 Test (org.junit.Test)16 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)6 ConsoleResult (com.thoughtworks.go.util.command.ConsoleResult)5 File (java.io.File)5 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 CommandLineException (com.thoughtworks.go.util.command.CommandLineException)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 RunIf (com.googlecode.junit.ext.RunIf)2 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)2 ProcessOutputStreamConsumer (com.thoughtworks.go.util.command.ProcessOutputStreamConsumer)2 LinkedList (java.util.LinkedList)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 CheckedCommandLineException (com.thoughtworks.go.util.command.CheckedCommandLineException)1 CompositeConsumer (com.thoughtworks.go.util.command.CompositeConsumer)1 CruiseControlException (com.thoughtworks.go.util.command.CruiseControlException)1 ExecScript (com.thoughtworks.go.util.command.ExecScript)1 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)1 IOException (java.io.IOException)1