Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow S3 Fetch config with dashes in the name to still work #17

Merged
merged 1 commit into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fetch/src/main/java/com/indix/gocd/s3fetch/FetchConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public FetchConfig(TaskConfig config, TaskExecutionContext context) {
this.env = new GoEnvironment();
env.putAll(context.environment().asMap());

String repoName = config.getValue(FetchTask.REPO).toUpperCase();
String packageName = config.getValue(FetchTask.PACKAGE).toUpperCase();
String repoName = config.getValue(FetchTask.REPO).toUpperCase().replaceAll("-", "_");
String packageName = config.getValue(FetchTask.PACKAGE).toUpperCase().replaceAll("-", "_");
this.materialLabel = env.get(String.format("GO_PACKAGE_%s_%s_LABEL", repoName, packageName));
this.pipeline = env.get(String.format("GO_PACKAGE_%s_%s_PIPELINE_NAME", repoName, packageName));
this.stage = env.get(String.format("GO_PACKAGE_%s_%s_STAGE_NAME", repoName, packageName));
Expand Down
20 changes: 20 additions & 0 deletions fetch/src/test/java/com/indix/gocd/s3fetch/FetchConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ public void shouldNotBeValidIfPackageConfigIsNotValid() {
assertThat(validationResult.getMessages(), Matchers.<List<String>>is(messages));
}

@Test
public void shouldAllowFetchTaskVariablesWithDashesInTheName() throws Exception {
config = mock(TaskConfig.class);
when(config.getValue(FetchTask.REPO)).thenReturn("repo-with-dash");
when(config.getValue(FetchTask.PACKAGE)).thenReturn("package-with-dash");
mockEnvironmentVariables = Maps.<String, String>builder()
.with(AWS_SECRET_ACCESS_KEY, secretKey)
.with(AWS_ACCESS_KEY_ID, accessId)
.with(GO_ARTIFACTS_S3_BUCKET, bucket)
.with("GO_PACKAGE_REPO_WITH_DASH_PACKAGE_WITH_DASH_LABEL", "20.1")
.with("GO_REPO_REPO_WITH_DASH_PACKAGE_WITH_DASH_S3_BUCKET", bucket)
.with("GO_PACKAGE_REPO_WITH_DASH_PACKAGE_WITH_DASH_PIPELINE_NAME", "TestPublish")
.with("GO_PACKAGE_REPO_WITH_DASH_PACKAGE_WITH_DASH_STAGE_NAME", "defaultStage")
.with("GO_PACKAGE_REPO_WITH_DASH_PACKAGE_WITH_DASH_JOB_NAME", "defaultJob");

fetchConfig = new FetchConfig(config, mockContext(mockEnvironmentVariables.build()));
ValidationResult validationResult = fetchConfig.validate();
assertTrue(validationResult.isSuccessful());
}

private TaskExecutionContext mockContext(final Map<String, String> environmentMap) {
return new MockTaskExecutionContext(environmentMap);
}
Expand Down