Search in sources :

Example 21 with RunIfConfigs

use of com.thoughtworks.go.domain.RunIfConfigs in project gocd by gocd.

the class FetchPluggableArtifactBuilderTest method shouldUpdateEnvironmentVariableContextAfterFetchingArtifact.

@Test
public void shouldUpdateEnvironmentVariableContextAfterFetchingArtifact() {
    final FetchPluggableArtifactBuilder builder = new FetchPluggableArtifactBuilder(new RunIfConfigs(), new NullBuilder(), "", jobIdentifier, artifactStore, fetchPluggableArtifactTask.getConfiguration(), fetchPluggableArtifactTask.getArtifactId(), sourceOnServer, metadataDest, checksumFileHandler);
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    environmentVariableContext.setProperty("VAR1", "old-value1", false);
    environmentVariableContext.setProperty("VAR2", "old-value2", true);
    environmentVariableContext.setProperty("VAR3", "old-value3", true);
    environmentVariableContext.setProperty("VAR4", "old-value4", true);
    when(artifactExtension.fetchArtifact(eq(PLUGIN_ID), eq(artifactStore), any(), anyMap(), eq(metadataDest.getParent()))).thenReturn(Arrays.asList(new FetchArtifactEnvironmentVariable("VAR1", "value1-is-now-secure", true), new FetchArtifactEnvironmentVariable("VAR2", "value2-is-now-insecure", false), new FetchArtifactEnvironmentVariable("VAR3", "value3-but-secure-is-unchanged", true), new FetchArtifactEnvironmentVariable("VAR5", "new-value5-insecure", false), new FetchArtifactEnvironmentVariable("VAR6", "new-value6-secure", true)));
    builder.build(publisher, environmentVariableContext, null, artifactExtension, registry, "utf-8");
    Map<String, String> newVariablesAfterFetchArtifact = environmentVariableContext.getProperties();
    assertThat(newVariablesAfterFetchArtifact.size(), is(6));
    assertVariable(environmentVariableContext, "VAR1", "value1-is-now-secure", true);
    assertVariable(environmentVariableContext, "VAR2", "value2-is-now-insecure", false);
    assertVariable(environmentVariableContext, "VAR3", "value3-but-secure-is-unchanged", true);
    assertVariable(environmentVariableContext, "VAR4", "old-value4", true);
    assertVariable(environmentVariableContext, "VAR5", "new-value5-insecure", false);
    assertVariable(environmentVariableContext, "VAR6", "new-value6-secure", true);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(publisher, atLeastOnce()).taggedConsumeLine(eq(OUT), captor.capture());
    assertThat(captor.getAllValues(), hasItems("WARNING: Replacing environment variable: VAR1 = ******** (previously: old-value1)", "WARNING: Replacing environment variable: VAR2 = value2-is-now-insecure (previously: ********)", "WARNING: Replacing environment variable: VAR3 = ******** (previously: ********)", " NOTE: Setting new environment variable: VAR5 = new-value5-insecure", " NOTE: Setting new environment variable: VAR6 = ********"));
    String consoleOutput = String.join(" -- ", captor.getAllValues());
    assertThat(consoleOutput, not(containsString("value1-is-now-secure")));
    assertThat(consoleOutput, not(containsString("value3-but-secure-is-unchanged")));
    assertThat(consoleOutput, not(containsString("new-value6-secure")));
}
Also used : RunIfConfigs(com.thoughtworks.go.domain.RunIfConfigs) FetchArtifactEnvironmentVariable(com.thoughtworks.go.plugin.access.artifact.models.FetchArtifactEnvironmentVariable) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.jupiter.api.Test)

Example 22 with RunIfConfigs

use of com.thoughtworks.go.domain.RunIfConfigs in project gocd by gocd.

the class FetchPluggableArtifactBuilderTest method shouldCallArtifactExtensionWithMetadata.

@Test
public void shouldCallArtifactExtensionWithMetadata() throws IOException {
    final FetchPluggableArtifactBuilder builder = new FetchPluggableArtifactBuilder(new RunIfConfigs(), new NullBuilder(), "", jobIdentifier, artifactStore, fetchPluggableArtifactTask.getConfiguration(), fetchPluggableArtifactTask.getArtifactId(), sourceOnServer, metadataDest, checksumFileHandler);
    final Map<String, Object> metadata = Collections.singletonMap("Version", "10.12.0");
    FileUtils.writeStringToFile(metadataDest, new Gson().toJson(metadata), StandardCharsets.UTF_8);
    builder.build(publisher, new EnvironmentVariableContext(), null, artifactExtension, registry, "utf-8");
    verify(artifactExtension).fetchArtifact(eq(PLUGIN_ID), eq(artifactStore), eq(fetchPluggableArtifactTask.getConfiguration()), any(), eq(metadataDest.getParent()));
}
Also used : RunIfConfigs(com.thoughtworks.go.domain.RunIfConfigs) Gson(com.google.gson.Gson) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.jupiter.api.Test)

Example 23 with RunIfConfigs

use of com.thoughtworks.go.domain.RunIfConfigs in project gocd by gocd.

the class FetchPluggableArtifactBuilderTest method shouldCallArtifactExtension.

@Test
public void shouldCallArtifactExtension() {
    final FetchPluggableArtifactBuilder builder = new FetchPluggableArtifactBuilder(new RunIfConfigs(), new NullBuilder(), "", jobIdentifier, artifactStore, fetchPluggableArtifactTask.getConfiguration(), fetchPluggableArtifactTask.getArtifactId(), sourceOnServer, metadataDest, checksumFileHandler);
    builder.build(publisher, new EnvironmentVariableContext(), null, artifactExtension, registry, "utf-8");
    verify(artifactExtension).fetchArtifact(eq(PLUGIN_ID), eq(artifactStore), eq(fetchPluggableArtifactTask.getConfiguration()), any(), eq(metadataDest.getParent()));
}
Also used : RunIfConfigs(com.thoughtworks.go.domain.RunIfConfigs) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.jupiter.api.Test)

Example 24 with RunIfConfigs

use of com.thoughtworks.go.domain.RunIfConfigs in project gocd by gocd.

the class BuilderTest method shouldRunCancelBuilderWhenCanceled.

@Test
void shouldRunCancelBuilderWhenCanceled() {
    StubBuilder stubBuilder = new StubBuilder();
    CommandBuilder builder = new CommandBuilder("echo", "", new File("."), new RunIfConfigs(FAILED), stubBuilder, "");
    builder.cancel(goPublisher, environmentVariableContext, null, null, "utf-8");
    assertThat(stubBuilder.wasCalled).isTrue();
}
Also used : RunIfConfigs(com.thoughtworks.go.domain.RunIfConfigs) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 25 with RunIfConfigs

use of com.thoughtworks.go.domain.RunIfConfigs in project gocd by gocd.

the class BuilderTest method shouldLogToConsoleOutWhenCanceling.

@Test
void shouldLogToConsoleOutWhenCanceling() {
    StubBuilder stubBuilder = new StubBuilder();
    CommandBuilder builder = new CommandBuilder("echo", "", new File("."), new RunIfConfigs(FAILED), stubBuilder, "");
    builder.cancel(goPublisher, environmentVariableContext, null, null, "utf-8");
    assertThat(goPublisher.getMessage()).contains("On Cancel Task");
    assertThat(goPublisher.getMessage()).contains("On Cancel Task completed");
}
Also used : RunIfConfigs(com.thoughtworks.go.domain.RunIfConfigs) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)29 Test (org.junit.jupiter.api.Test)22 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)10 File (java.io.File)9 Test (org.junit.Test)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 OnCancelConfig (com.thoughtworks.go.config.OnCancelConfig)3 RunIfConfig (com.thoughtworks.go.config.RunIfConfig)3 CommandBuilder (com.thoughtworks.go.domain.builder.CommandBuilder)3 StubBuilder (com.thoughtworks.go.domain.builder.StubBuilder)3 Gson (com.google.gson.Gson)2 StubGoPublisher (com.thoughtworks.go.domain.StubGoPublisher)2 Builder (com.thoughtworks.go.domain.builder.Builder)2 HgUrlArgument (com.thoughtworks.go.util.command.HgUrlArgument)2 RunIf (com.googlecode.junit.ext.RunIf)1 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)1 BuildLogElement (com.thoughtworks.go.domain.BuildLogElement)1 FetchArtifactEnvironmentVariable (com.thoughtworks.go.plugin.access.artifact.models.FetchArtifactEnvironmentVariable)1 ArtifactRequestProcessor (com.thoughtworks.go.remote.work.artifact.ArtifactRequestProcessor)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1