use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class ManifestPullerTest method testHandleResponse_v22ManifestList.
@Test
public void testHandleResponse_v22ManifestList() throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v22ManifestListFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
InputStream v22ManifestList = new ByteArrayInputStream(Files.readAllBytes(v22ManifestListFile));
DescriptorDigest expectedDigest = Digests.computeDigest(v22ManifestList).getDigest();
v22ManifestList.reset();
Mockito.when(mockResponse.getBody()).thenReturn(v22ManifestList);
ManifestAndDigest<V22ManifestListTemplate> manifestAndDigest = new ManifestPuller<>(fakeRegistryEndpointRequestProperties, "test-image-tag", V22ManifestListTemplate.class).handleResponse(mockResponse);
V22ManifestListTemplate manifestTemplate = manifestAndDigest.getManifest();
MatcherAssert.assertThat(manifestTemplate, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
Assert.assertTrue(manifestTemplate.getManifests().size() > 0);
Assert.assertEquals(expectedDigest, manifestAndDigest.getDigest());
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class ManifestPullerTest method testHandleResponse_v22ManifestListFromParentType.
@Test
public void testHandleResponse_v22ManifestListFromParentType() throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v22ManifestListFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
InputStream v22ManifestList = new ByteArrayInputStream(Files.readAllBytes(v22ManifestListFile));
DescriptorDigest expectedDigest = Digests.computeDigest(v22ManifestList).getDigest();
v22ManifestList.reset();
Mockito.when(mockResponse.getBody()).thenReturn(v22ManifestList);
ManifestAndDigest<?> manifestAndDigest = new ManifestPuller<>(fakeRegistryEndpointRequestProperties, "test-image-tag", ManifestTemplate.class).handleResponse(mockResponse);
ManifestTemplate manifestTemplate = manifestAndDigest.getManifest();
MatcherAssert.assertThat(manifestTemplate, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
Assert.assertTrue(((V22ManifestListTemplate) manifestTemplate).getManifests().size() > 0);
Assert.assertEquals(expectedDigest, manifestAndDigest.getDigest());
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class ManifestPullerTest method testHandleResponse_v21.
@Test
public void testHandleResponse_v21() throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v21ManifestFile = Paths.get(Resources.getResource("core/json/v21manifest.json").toURI());
InputStream v21Manifest = new ByteArrayInputStream(Files.readAllBytes(v21ManifestFile));
DescriptorDigest expectedDigest = Digests.computeDigest(v21Manifest).getDigest();
v21Manifest.reset();
Mockito.when(mockResponse.getBody()).thenReturn(v21Manifest);
ManifestAndDigest<?> manifestAndDigest = new ManifestPuller<>(fakeRegistryEndpointRequestProperties, "test-image-tag", V21ManifestTemplate.class).handleResponse(mockResponse);
MatcherAssert.assertThat(manifestAndDigest.getManifest(), CoreMatchers.instanceOf(V21ManifestTemplate.class));
Assert.assertEquals(expectedDigest, manifestAndDigest.getDigest());
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class ManifestPusherTest method testHandleResponse_multipleDigests.
@Test
public void testHandleResponse_multipleDigests() throws IOException {
DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
Mockito.when(mockResponse.getHeader("Docker-Content-Digest")).thenReturn(Arrays.asList("too", "many"));
Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse));
Mockito.verify(mockEventHandlers).dispatch(LogEvent.warn("Expected image digest " + expectedDigest + ", but received: too, many"));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class ManifestPusherTest method testHandleResponse_invalidDigest.
@Test
public void testHandleResponse_invalidDigest() throws IOException {
DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
Mockito.when(mockResponse.getHeader("Docker-Content-Digest")).thenReturn(Collections.singletonList("not valid"));
Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse));
Mockito.verify(mockEventHandlers).dispatch(LogEvent.warn("Expected image digest " + expectedDigest + ", but received: not valid"));
}
Aggregations