Search in sources :

Example 46 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project gocd by gocd.

the class CommandLineTest method shouldNotLogPasswordsOnExceptionThrown.

@Test
@DisabledOnOs(OS.WINDOWS)
void shouldNotLogPasswordsOnExceptionThrown() throws IOException {
    File file = Files.writeString(temporaryFolder.resolve("test.sh"), "echo $1 && exit 10", UTF_8).toFile();
    CommandLine line = CommandLine.createCommandLine("/bin/sh").withArg(file.getAbsolutePath()).withArg(new PasswordArgument("secret")).withEncoding("utf-8");
    assertThatThrownBy(() -> line.runOrBomb(null)).isExactlyInstanceOf(CommandLineException.class).hasMessageContaining("EXIT CODE (10)").hasMessageNotContaining("secret");
}
Also used : File(java.io.File) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 47 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project gocd by gocd.

the class CommandLineTest method shouldLogPasswordsOnEnvironmentAsStarsUnderLinux.

@Test
@DisabledOnOs(OS.WINDOWS)
void shouldLogPasswordsOnEnvironmentAsStarsUnderLinux() {
    CommandLine line = CommandLine.createCommandLine("echo").withArg("My Password is:").withArg("secret").withArg(new PasswordArgument("secret")).withEncoding("utf-8");
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    environmentVariableContext.setProperty("ENV_PASSWORD", "secret", false);
    InMemoryStreamConsumer output = new InMemoryStreamConsumer();
    InMemoryStreamConsumer forDisplay = InMemoryStreamConsumer.inMemoryConsumer();
    ProcessWrapper processWrapper = line.execute(output, environmentVariableContext, null);
    processWrapper.waitForExit();
    assertThat(forDisplay.getAllOutput(), not(containsString("secret")));
    assertThat(output.getAllOutput(), containsString("secret"));
}
Also used : ProcessWrapper(com.thoughtworks.go.util.ProcessWrapper) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 48 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project gocd by gocd.

the class CommandLineTest method shouldNotLogPasswordsFromStream.

@Test
@DisabledOnOs(OS.WINDOWS)
void shouldNotLogPasswordsFromStream() {
    try (LogFixture logFixture = logFixtureFor(CommandLine.class, Level.DEBUG)) {
        CommandLine line = CommandLine.createCommandLine("/bin/echo").withArg("=>").withArg(new PasswordArgument("secret")).withEncoding("utf-8");
        line.runOrBomb(null);
        assertThat(logFixture.getLog(), not(containsString("secret")));
        assertThat(logFixture.getLog(), containsString("=> ******"));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 49 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project gocd by gocd.

the class CommandLineTest method shouldBeAbleToRunCommandsInSubdirectories.

@Test
@DisabledOnOs(OS.WINDOWS)
void shouldBeAbleToRunCommandsInSubdirectories() throws IOException {
    File shellScript = createScriptInSubFolder("hello-world.sh", "echo ${PWD}");
    assertThat(shellScript.setExecutable(true), is(true));
    CommandLine line = CommandLine.createCommandLine("./hello-world.sh").withWorkingDir(subFolder).withEncoding("utf-8");
    InMemoryStreamConsumer out = new InMemoryStreamConsumer();
    line.execute(out, new EnvironmentVariableContext(), null).waitForExit();
    assertThat(out.getAllOutput().trim(), endsWith("subFolder"));
}
Also used : File(java.io.File) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 50 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project gocd by gocd.

the class BuilderTest method shouldReportErrorWhenCancelCommandDoesNotExist.

@Test
@DisabledOnOs(OS.WINDOWS)
void shouldReportErrorWhenCancelCommandDoesNotExist() {
    StubBuilder stubBuilder = new StubBuilder();
    CommandBuilder cancelBuilder = new CommandBuilder("echo2", "cancel task", new File("."), new RunIfConfigs(FAILED), stubBuilder, "");
    CommandBuilder builder = new CommandBuilder("echo", "normal task", new File("."), new RunIfConfigs(FAILED), cancelBuilder, "");
    builder.cancel(goPublisher, new EnvironmentVariableContext(), null, null, "utf-8");
    assertThat(goPublisher.getMessage()).contains("Error happened while attempting to execute 'echo2 cancel task'");
}
Also used : RunIfConfigs(com.thoughtworks.go.domain.RunIfConfigs) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) File(java.io.File) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Aggregations

DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)87 Test (org.junit.jupiter.api.Test)80 Path (java.nio.file.Path)39 File (java.io.File)26 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 PathsBaseTest (org.assertj.core.internal.PathsBaseTest)12 AssertionsUtil.expectAssertionError (org.assertj.core.util.AssertionsUtil.expectAssertionError)11 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)6 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)6 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)6 CommandBuilder (com.thoughtworks.go.domain.builder.CommandBuilder)5 DelegatingStoreChannel (org.neo4j.io.fs.DelegatingStoreChannel)5 StoreChannel (org.neo4j.io.fs.StoreChannel)5 DisabledForRoot (org.neo4j.test.extension.DisabledForRoot)5 Closeable (java.io.Closeable)4 URI (java.net.URI)4 FileUtils.writeByteArrayToFile (org.apache.commons.io.FileUtils.writeByteArrayToFile)4 ShouldBeFile.shouldBeFile (org.assertj.core.error.ShouldBeFile.shouldBeFile)4 FilesBaseTest (org.assertj.core.internal.FilesBaseTest)4 Files.newFile (org.assertj.core.util.Files.newFile)4