use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.
the class ArtifactsPublisherTest method shouldDeletePluggableArtifactMetadataDirectory.
@Test
public void shouldDeletePluggableArtifactMetadataDirectory() throws Exception {
TestFileUtil.createTestFile(workingFolder, "installer.zip");
TestFileUtil.createTestFile(workingFolder, "testreports.xml");
final ArtifactStore artifactStore = new ArtifactStore("s3", "cd.go.s3", create("Foo", false, "Bar"));
final ArtifactStores artifactStores = new ArtifactStores(artifactStore);
final ArtifactPlan artifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
List<ArtifactPlan> artifactPlans = Arrays.asList(new ArtifactPlan(ArtifactPlanType.file, "installer.zip", "dist"), new ArtifactPlan(ArtifactPlanType.unit, "testreports.xml", "testreports"), artifactPlan);
when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("Foo", "Bar")));
final GoPublisher publisher = mock(GoPublisher.class);
assertThat(Arrays.asList(workingFolder.list()), containsInAnyOrder("testreports.xml", "installer.zip", "cruise-output"));
new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(artifactPlans, env);
assertThat(Arrays.asList(workingFolder.list()), containsInAnyOrder("testreports.xml", "installer.zip", "cruise-output"));
}
use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.
the class ArtifactsPublisherTest method shouldAddPluggableArtifactMetadataFileArtifactPlanAtTop.
@Test
public void shouldAddPluggableArtifactMetadataFileArtifactPlanAtTop() throws Exception {
TestFileUtil.createTestFile(workingFolder, "installer.zip");
TestFileUtil.createTestFile(workingFolder, "testreports.xml");
final ArtifactStore artifactStore = new ArtifactStore("s3", "cd.go.s3", create("Foo", false, "Bar"));
final ArtifactStores artifactStores = new ArtifactStores(artifactStore);
final ArtifactPlan artifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
List<ArtifactPlan> artifactPlans = Arrays.asList(new ArtifactPlan(ArtifactPlanType.file, "installer.zip", "dist"), new ArtifactPlan(ArtifactPlanType.unit, "testreports.xml", "testreports"), artifactPlan);
when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("Foo", "Bar")));
final GoPublisher publisher = mock(GoPublisher.class);
new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(artifactPlans, env);
InOrder inOrder = inOrder(publisher);
inOrder.verify(publisher).upload(any(), eq("pluggable-artifact-metadata"));
inOrder.verify(publisher).upload(any(), eq("dist"));
inOrder.verify(publisher).upload(any(), eq("testreports"));
}
use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.
the class ArtifactsPublisher method publishPluggableArtifact.
private void publishPluggableArtifact(PluggableArtifactMetadata pluggableArtifactMetadata, ArtifactPlan artifactPlan, ArtifactStore artifactStore, EnvironmentVariableContext environmentVariableContext) {
try {
final String pluginId = artifactStore.getPluginId();
final String message = format("[%s] Start to upload pluggable artifact using plugin `%s`.", PRODUCT_NAME, pluginId);
goPublisher.taggedConsumeLine(GoPublisher.PUBLISH, message);
LOGGER.info(message);
final PublishArtifactResponse publishArtifactResponse = artifactExtension.publishArtifact(pluginId, artifactPlan, artifactStore, workingDirectory.getAbsolutePath(), environmentVariableContext);
if (!publishArtifactResponse.getMetadata().isEmpty()) {
final String artifactId = (String) artifactPlan.getPluggableArtifactConfiguration().get("id");
pluggableArtifactMetadata.addMetadata(pluginId, artifactId, publishArtifactResponse.getMetadata());
}
} catch (RuntimeException e) {
failedArtifact.add(artifactPlan);
goPublisher.taggedConsumeLine(GoPublisher.ERR, format("[%s] %s", PRODUCT_NAME, e.getMessage()));
LOGGER.error(e.getMessage(), e);
}
}
use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.
the class ArtifactsPublisherTest method shouldRegisterAndDeRegisterArtifactRequestProcessBeforeAndAfterPublishingPluggableArtifact.
@Test
public void shouldRegisterAndDeRegisterArtifactRequestProcessBeforeAndAfterPublishingPluggableArtifact() {
final ArtifactStore s3ArtifactStore = new ArtifactStore("s3", "cd.go.s3", create("access_key", false, "some-key"));
final ArtifactStores artifactStores = new ArtifactStores(s3ArtifactStore);
final ArtifactPlan s3ArtifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(s3ArtifactPlan), eq(s3ArtifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("src", "s3://dist")));
new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(Arrays.asList(s3ArtifactPlan), env);
InOrder inOrder = inOrder(registry, artifactExtension);
inOrder.verify(registry, times(1)).registerProcessorFor(eq(CONSOLE_LOG.requestName()), any(ArtifactRequestProcessor.class));
inOrder.verify(artifactExtension, times(1)).publishArtifact("cd.go.s3", s3ArtifactPlan, s3ArtifactStore, workingFolder.getAbsolutePath(), env);
inOrder.verify(registry, times(1)).removeProcessorFor(CONSOLE_LOG.requestName());
}
use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.
the class ArtifactsPublisherTest method shouldErrorOutWhenFailedToCreateFolderToWritePluggableArtifactMetadata.
@Test
public void shouldErrorOutWhenFailedToCreateFolderToWritePluggableArtifactMetadata() {
Assumptions.assumeFalse(IS_WINDOWS, "Do not run on windows.");
final ArtifactStore artifactStore = new ArtifactStore("s3", "cd.go.s3", create("Foo", false, "Bar"));
final ArtifactStores artifactStores = new ArtifactStores(artifactStore);
final ArtifactPlan artifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("Foo", "Bar")));
workingFolder.setWritable(false);
assertThatThrownBy(() -> new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(Arrays.asList(artifactPlan), env)).isInstanceOf(RuntimeException.class).hasMessageContaining("[go] Could not create pluggable artifact metadata folder");
}
Aggregations