use of com.thoughtworks.go.config.ArtifactStore in project gocd by gocd.
the class ArtifactExtensionTest method shouldSubmitFetchArtifactRequest.
@Test
public void shouldSubmitFetchArtifactRequest() throws JSONException {
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(""));
final FetchPluggableArtifactTask pluggableArtifactTask = new FetchPluggableArtifactTask(null, null, "artifactId", create("Filename", false, "build/libs/foo.jar"));
artifactExtension.fetchArtifact(PLUGIN_ID, new ArtifactStore("s3", "cd.go.s3"), pluggableArtifactTask.getConfiguration(), Collections.singletonMap("Version", "10.12.0"), "/temp");
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
final String requestBody = "{\n" + " \"artifact_metadata\": {\n" + " \"Version\": \"10.12.0\"\n" + " },\n" + " \"store_configuration\": {},\n" + " \"fetch_artifact_configuration\": {\n" + " \"Filename\": \"build/libs/foo.jar\"\n" + " },\n" + " \"agent_working_directory\": \"/temp\"\n" + "}";
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_FETCH_ARTIFACT));
JSONAssert.assertEquals(requestBody, request.requestBody(), true);
}
use of com.thoughtworks.go.config.ArtifactStore in project gocd by gocd.
the class ArtifactExtensionTest method shouldSubmitPublishArtifactRequest.
@Test
public void shouldSubmitPublishArtifactRequest() throws JSONException {
final String responseBody = "{\n" + " \"metadata\": {\n" + " \"artifact-version\": \"10.12.0\"\n" + " }\n" + "}";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
final PublishArtifactResponse response = artifactExtension.publishArtifact(PLUGIN_ID, new ArtifactPlan("{\"id\":\"installer\",\"storeId\":\"docker\"}"), new ArtifactStore("docker", "cd.go.docker"), "/temp");
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_PUBLISH_ARTIFACT));
final String expectedJSON = "{\n" + " \"artifact_plan\": {\n" + " \"id\": \"installer\",\n" + " \"storeId\": \"docker\"\n" + " },\n" + " \"artifact_store\": {\n" + " \"configuration\": {},\n" + " \"id\": \"docker\"\n" + " },\n" + " \"agent_working_directory\": \"/temp\"\n" + "}";
JSONAssert.assertEquals(expectedJSON, request.requestBody(), true);
assertThat(response.getMetadata().size(), is(1));
assertThat(response.getMetadata(), hasEntry("artifact-version", "10.12.0"));
}
use of com.thoughtworks.go.config.ArtifactStore 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(ArtifactType.file, "installer.zip", "dist"), new ArtifactPlan(ArtifactType.unit, "testreports.xml", "testreports"), artifactPlan);
when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString())).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);
assertThat(Arrays.asList(workingFolder.list()), containsInAnyOrder("testreports.xml", "installer.zip", "cruise-output"));
}
use of com.thoughtworks.go.config.ArtifactStore 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(ArtifactType.file, "installer.zip", "dist"), new ArtifactPlan(ArtifactType.unit, "testreports.xml", "testreports"), artifactPlan);
when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString())).thenReturn(new PublishArtifactResponse(Collections.singletonMap("Foo", "Bar")));
final GoPublisher publisher = mock(GoPublisher.class);
new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(artifactPlans);
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.config.ArtifactStore in project gocd by gocd.
the class ArtifactsPublisherTest method shouldContinueWithOtherPluginWhenPublishArtifactCallFailsForOnePlugin.
@Test
public void shouldContinueWithOtherPluginWhenPublishArtifactCallFailsForOnePlugin() throws IOException {
final ArtifactStore s3ArtifactStore = new ArtifactStore("s3", "cd.go.s3", create("access_key", false, "some-key"));
final ArtifactStore dockerArtifactStore = new ArtifactStore("docker", "cd.go.docker", create("registry-url", false, "docker.io"));
final ArtifactStores artifactStores = new ArtifactStores(s3ArtifactStore, dockerArtifactStore);
final ArtifactPlan s3ArtifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
final ArtifactPlan dockerArtifactPlan = new ArtifactPlan(new PluggableArtifactConfig("test-reports", "docker", create("junit", false, "junit.xml")));
when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(s3ArtifactPlan), eq(s3ArtifactStore), anyString())).thenThrow(new RuntimeException("Interaction with plugin `cd.go.s3` failed."));
when(artifactExtension.publishArtifact(eq("cd.go.docker"), eq(dockerArtifactPlan), eq(dockerArtifactStore), anyString())).thenReturn(new PublishArtifactResponse(Collections.singletonMap("tag", "10.12.0")));
try {
new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(Arrays.asList(s3ArtifactPlan, dockerArtifactPlan));
fail("Should throw error for pluggable artifact [installers].");
} catch (Exception e) {
assertThat(uploadedPluggableMetadataFiles(publisher.publishedFiles()), containsInAnyOrder("cd.go.docker.json"));
assertThat(publisher.getMessage(), containsString("[go] Interaction with plugin `cd.go.s3` failed"));
assertThat(e.getMessage(), containsString("[go] Uploading finished. Failed to upload [installers]."));
}
}
Aggregations