Search in sources :

Example 1 with DescriptorDigest

use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.

the class BlobPullerTest method testHandleResponse_unexpectedDigest.

@Test
public void testHandleResponse_unexpectedDigest() throws IOException {
    Blob testBlob = Blobs.from("some BLOB content");
    DescriptorDigest testBlobDigest = testBlob.writeTo(ByteStreams.nullOutputStream()).getDigest();
    Response mockResponse = Mockito.mock(Response.class);
    Mockito.when(mockResponse.getBody()).thenReturn(testBlob);
    try {
        testBlobPuller.handleResponse(mockResponse);
        Assert.fail("Receiving an unexpected digest should fail");
    } catch (UnexpectedBlobDigestException ex) {
        Assert.assertEquals("The pulled BLOB has digest '" + testBlobDigest + "', but the request digest was '" + fakeDigest + "'", ex.getMessage());
    }
}
Also used : Response(com.google.cloud.tools.jib.http.Response) Blob(com.google.cloud.tools.jib.blob.Blob) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) Test(org.junit.Test)

Example 2 with DescriptorDigest

use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.

the class BlobPullerTest method testHandleResponse.

@Test
public void testHandleResponse() throws IOException, UnexpectedBlobDigestException {
    Blob testBlob = Blobs.from("some BLOB content");
    DescriptorDigest testBlobDigest = testBlob.writeTo(ByteStreams.nullOutputStream()).getDigest();
    Response mockResponse = Mockito.mock(Response.class);
    Mockito.when(mockResponse.getBody()).thenReturn(testBlob);
    BlobPuller blobPuller = new BlobPuller(fakeRegistryEndpointProperties, testBlobDigest, layerOutputStream);
    blobPuller.handleResponse(mockResponse);
    Assert.assertEquals("some BLOB content", new String(layerContentOutputStream.toByteArray(), StandardCharsets.UTF_8));
    Assert.assertEquals(testBlobDigest, layerOutputStream.toBlobDescriptor().getDigest());
}
Also used : Response(com.google.cloud.tools.jib.http.Response) Blob(com.google.cloud.tools.jib.blob.Blob) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) Test(org.junit.Test)

Example 3 with DescriptorDigest

use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.

the class BlobTest method verifyBlobWriteTo.

/**
 * Checks that the {@link Blob} streams the expected string.
 */
private void verifyBlobWriteTo(String expected, Blob blob) throws IOException {
    OutputStream outputStream = new ByteArrayOutputStream();
    BlobDescriptor blobDescriptor = blob.writeTo(outputStream);
    String output = outputStream.toString();
    Assert.assertEquals(expected, output);
    byte[] expectedBytes = expected.getBytes(StandardCharsets.UTF_8);
    Assert.assertEquals(expectedBytes.length, blobDescriptor.getSize());
    CountingDigestOutputStream countingDigestOutputStream = new CountingDigestOutputStream(Mockito.mock(OutputStream.class));
    countingDigestOutputStream.write(expectedBytes);
    DescriptorDigest expectedDigest = countingDigestOutputStream.toBlobDescriptor().getDigest();
    Assert.assertEquals(expectedDigest, blobDescriptor.getDigest());
}
Also used : CountingDigestOutputStream(com.google.cloud.tools.jib.hash.CountingDigestOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CountingDigestOutputStream(com.google.cloud.tools.jib.hash.CountingDigestOutputStream) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with DescriptorDigest

use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.

the class CacheMetadataTest method mockCachedLayer.

private static CachedLayer mockCachedLayer() {
    CachedLayer mockCachedLayer = Mockito.mock(CachedLayer.class);
    BlobDescriptor mockBlobDescriptor = Mockito.mock(BlobDescriptor.class);
    DescriptorDigest mockDescriptorDigest = Mockito.mock(DescriptorDigest.class);
    Mockito.when(mockCachedLayer.getBlobDescriptor()).thenReturn(mockBlobDescriptor);
    Mockito.when(mockBlobDescriptor.getDigest()).thenReturn(mockDescriptorDigest);
    return mockCachedLayer;
}
Also used : BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest)

Example 5 with DescriptorDigest

use of com.google.cloud.tools.jib.image.DescriptorDigest in project jib by google.

the class JsonToImageTranslator method toImage.

/**
 * Translates {@link V21ManifestTemplate} to {@link Image}.
 */
public static Image toImage(V21ManifestTemplate manifestTemplate) throws LayerPropertyNotFoundException {
    Image image = new Image();
    for (DescriptorDigest digest : manifestTemplate.getLayerDigests()) {
        Layer layer = new DigestOnlyLayer(digest);
        image.addLayer(layer);
    }
    return image;
}
Also used : DescriptorDigest(com.google.cloud.tools.jib.image.DescriptorDigest) DigestOnlyLayer(com.google.cloud.tools.jib.image.DigestOnlyLayer) Image(com.google.cloud.tools.jib.image.Image) ReferenceNoDiffIdLayer(com.google.cloud.tools.jib.image.ReferenceNoDiffIdLayer) Layer(com.google.cloud.tools.jib.image.Layer) ReferenceLayer(com.google.cloud.tools.jib.image.ReferenceLayer) DigestOnlyLayer(com.google.cloud.tools.jib.image.DigestOnlyLayer)

Aggregations

DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)19 Test (org.junit.Test)9 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)6 Blob (com.google.cloud.tools.jib.blob.Blob)5 CountingDigestOutputStream (com.google.cloud.tools.jib.hash.CountingDigestOutputStream)5 Layer (com.google.cloud.tools.jib.image.Layer)4 Image (com.google.cloud.tools.jib.image.Image)3 ReferenceLayer (com.google.cloud.tools.jib.image.ReferenceLayer)3 Response (com.google.cloud.tools.jib.http.Response)2 DigestOnlyLayer (com.google.cloud.tools.jib.image.DigestOnlyLayer)2 ReferenceNoDiffIdLayer (com.google.cloud.tools.jib.image.ReferenceNoDiffIdLayer)2 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 Timer (com.google.cloud.tools.jib.Timer)1 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)1 LayerCountMismatchException (com.google.cloud.tools.jib.image.LayerCountMismatchException)1 UnwrittenLayer (com.google.cloud.tools.jib.image.UnwrittenLayer)1