-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform auto-injection when Command task is used to run Gradle (#58)
* Support running Gradle via the Command Builder * Test Gradle project run via Command builder * Add new project to Bamboo 6.9.2 resources * Do not attempt to delete agent if API is not supported * Test environment variable setting logic
- Loading branch information
Showing
16 changed files
with
191 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/test/java/com/gradle/enterprise/bamboo/DefaultEnvironmentVariableSetterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.gradle.enterprise.bamboo; | ||
|
||
import com.atlassian.bamboo.task.TaskDefinition; | ||
import com.atlassian.bamboo.task.TaskDefinitionImpl; | ||
import com.atlassian.bamboo.task.runtime.RuntimeTaskDefinition; | ||
import com.atlassian.bamboo.task.runtime.RuntimeTaskDefinitionImpl; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.apache.commons.lang3.RandomUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.springframework.core.Ordered; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasEntry; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
class DefaultEnvironmentVariableSetterTest { | ||
|
||
private final EnvironmentVariableSetter environmentVariableSetter = new DefaultEnvironmentVariableSetter(); | ||
|
||
@Test | ||
void orderIsSet() { | ||
// expect | ||
assertThat(environmentVariableSetter.getOrder(), is(equalTo(Ordered.LOWEST_PRECEDENCE))); | ||
} | ||
|
||
@Test | ||
void addsNewEnvironmentVariable() { | ||
// given | ||
TaskDefinition taskDefinition = | ||
new TaskDefinitionImpl( | ||
RandomUtils.nextLong(), | ||
RandomStringUtils.randomAscii(10), | ||
null, | ||
Collections.emptyMap() | ||
); | ||
RuntimeTaskDefinition runtimeTaskDefinition = new RuntimeTaskDefinitionImpl(taskDefinition); | ||
|
||
// when | ||
environmentVariableSetter.apply(runtimeTaskDefinition, "NEW", "value"); | ||
|
||
// then | ||
Map<String, String> result = runtimeTaskDefinition.getConfiguration(); | ||
|
||
assertThat(result.size(), is(equalTo(1))); | ||
assertThat(result, | ||
hasEntry( | ||
equalTo(Constants.DEFAULT_TASK_ENVIRONMENT_VARIABLES_KEY), | ||
equalTo("NEW=value")) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"NEW, value, OLD=value NEW=value", | ||
"NEW, value with space, OLD=value NEW=\"value with space\"", | ||
"NEW, \"value\" with space, OLD=value NEW='\"value\" with space'" | ||
}) | ||
void updatesExistingEnvironmentVariable(String key, String value, String expected) { | ||
// given | ||
TaskDefinition taskDefinition = | ||
new TaskDefinitionImpl( | ||
RandomUtils.nextLong(), | ||
RandomStringUtils.randomAscii(10), | ||
null, | ||
Collections.singletonMap(Constants.DEFAULT_TASK_ENVIRONMENT_VARIABLES_KEY, "OLD=value") | ||
); | ||
RuntimeTaskDefinition runtimeTaskDefinition = new RuntimeTaskDefinitionImpl(taskDefinition); | ||
|
||
// when | ||
environmentVariableSetter.apply(runtimeTaskDefinition, key, value); | ||
|
||
// then | ||
Map<String, String> result = runtimeTaskDefinition.getConfiguration(); | ||
|
||
assertThat(result.size(), is(equalTo(1))); | ||
assertThat(result, | ||
hasEntry( | ||
equalTo(Constants.DEFAULT_TASK_ENVIRONMENT_VARIABLES_KEY), | ||
equalTo(expected)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.