Search in sources :

Example 56 with DescriptorDigest

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());
}
Also used : Path(java.nio.file.Path) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 57 with DescriptorDigest

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());
}
Also used : Path(java.nio.file.Path) V22ManifestListTemplate(com.google.cloud.tools.jib.image.json.V22ManifestListTemplate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) V22ManifestTemplate(com.google.cloud.tools.jib.image.json.V22ManifestTemplate) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) OciManifestTemplate(com.google.cloud.tools.jib.image.json.OciManifestTemplate) ManifestTemplate(com.google.cloud.tools.jib.image.json.ManifestTemplate) Test(org.junit.Test)

Example 58 with DescriptorDigest

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());
}
Also used : Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) V21ManifestTemplate(com.google.cloud.tools.jib.image.json.V21ManifestTemplate) Test(org.junit.Test)

Example 59 with DescriptorDigest

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"));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Example 60 with DescriptorDigest

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"));
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.api.DescriptorDigest) Test(org.junit.Test)

Aggregations

DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)112 Test (org.junit.Test)68 Path (java.nio.file.Path)28 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)24 Blob (com.google.cloud.tools.jib.blob.Blob)18 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)16 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)16 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)16 Image (com.google.cloud.tools.jib.image.Image)14 ByteArrayInputStream (java.io.ByteArrayInputStream)14 IOException (java.io.IOException)14 InputStream (java.io.InputStream)14 RegistryException (com.google.cloud.tools.jib.api.RegistryException)12 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)12 ManifestTemplate (com.google.cloud.tools.jib.image.json.ManifestTemplate)10 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)10 DigestException (java.security.DigestException)10 FailoverHttpClient (com.google.cloud.tools.jib.http.FailoverHttpClient)8 Layer (com.google.cloud.tools.jib.image.Layer)8 OutputStream (java.io.OutputStream)8