PublishExecutor { public TaskExecutionResult execute(Config config, final Context context) { try { final GoEnvironment env = new GoEnvironment(context.getEnvironmentVariables()); if (env.isAbsent(GO_SERVER_DASHBOARD_URL)) return envNotFound(GO_SERVER_DASHBOARD_URL); String bucket = getBucket(env, config); if(bucket == null) return envNotFound(GO_ARTIFACTS_S3_BUCKET); final S3ArtifactStore store = getS3ArtifactStore(env, bucket); store.setStorageClass(env.getOrElse(AWS_STORAGE_CLASS, STORAGE_CLASS_STANDARD)); final String destinationPrefix = getDestinationPrefix(config, env); List<SourceDestination> sourceDestinations = config.sourceDestinations(); for(SourceDestination input : sourceDestinations) { String[] files = parseSourcePath(input.source, context.getWorkingDir()); if (files.length == 0) { return new TaskExecutionResult(false, String.format("Source %s didn't yield any files to upload", input.source)); } for (String includedFile : files) { File localFileToUpload = new File(String.format("%s/%s", context.getWorkingDir(), includedFile)); pushToS3(context, destinationPrefix, store, localFileToUpload, input.destination); } } if(!hasConfigDestinationPrefix(config)) { setMetadata(env, bucket, destinationPrefix, store); } return new TaskExecutionResult(true, "Published all artifacts to S3 successfully"); } catch (JsonSyntaxException e) { String message = "Failed while parsing configuration"; logger.error(message); return new TaskExecutionResult(false, message, e); } catch (Exception e) { logger.error(e.getMessage(), e); return new TaskExecutionResult(false, e.getMessage()); } }  TaskExecutionResult execute(Config config, final Context context);  }
@Test public void shouldThrowIfGO_ARTIFACTS_S3_BUCKETNotPresent() { Map<String, String> mockVariables = mockEnvironmentVariables.with(GO_ARTIFACTS_S3_BUCKET, "").build(); Config config = new Config(Maps.builder() .with(Constants.SOURCEDESTINATIONS, Maps.builder().with("value", "[{\"source\": \"target/*\", \"destination\": \"\"}]").build()) .with(Constants.DESTINATION_PREFIX, Maps.builder().with("value", "").build()) .with(Constants.ARTIFACTS_BUCKET, Maps.builder().with("value", "").build()) .build()); TaskExecutionResult result = publishExecutor.execute(config, mockContext(mockVariables)); assertFalse(result.isSuccessful()); assertThat(result.message(), is("GO_ARTIFACTS_S3_BUCKET environment variable is not set")); }