private BuildCommand setupEnvironmentVariables() { EnvironmentVariableContext context = environmentVariableContext(); ArrayList<BuildCommand> commands = new ArrayList<>(); commands.add(export("GO_SERVER_URL")); for (String property : context.getPropertyKeys()) { commands.add(export(property, context.getProperty(property), context.isPropertySecure(property))); } return BuildCommand.compose(commands); }
@Test public void exportEnvironmentVariableHasMeaningfulOutput() throws Exception { runBuild(compose( export("answer", "2", false), export("answer", "42", false)), Passed); assertThat(console.asList().get(0), is("[go] setting environment variable 'answer' to value '2'")); assertThat(console.asList().get(1), is("[go] overriding environment variable 'answer' with value '42'")); }
@Test public void exportWithoutValueDisplayCurrentValue() throws Exception { runBuild(export("foo"), Passed); assertThat(console.lastLine(), is("[go] setting environment variable 'foo' to value 'null'")); runBuild(compose( export("foo", "bar", false), export("foo")), Passed); assertThat(console.lastLine(), is("[go] setting environment variable 'foo' to value 'bar'")); } }
@Test public void exportOutputWhenOverridingSystemEnv() throws Exception { String envName = pathSystemEnvName(); runBuild(export(envName, "/foo/bar", false), Passed); assertThat(console.output(), is(String.format("[go] overriding environment variable '%s' with value '/foo/bar'", envName))); }
@Test public void exportSecretEnvShouldMaskValue() throws Exception { runBuild(export("answer", "42", true), Passed); assertThat(console.output(), is("[go] setting environment variable 'answer' to value '********'")); }
@Test public void secretMaskValuesInExportOutput() throws Exception { runBuild(compose( secret("42"), export("oracle", "the answer is 42", false)), Passed); assertThat(console.output(), is("[go] setting environment variable 'oracle' to value 'the answer is ******'")); }
@Test public void execUseExportedEnv() throws IOException { runBuild(compose( export("foo", "bar", false), execEchoEnv("foo")), Passed); assertThat(console.lastLine(), is("bar")); }
@Test public void execUseOverriddenSystemEnvValue() throws Exception { runBuild(compose( export(pathSystemEnvName(), "/foo/bar", false), execEchoEnv(pathSystemEnvName())), Passed); assertThat(console.lastLine(), is("/foo/bar")); }