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());
}
}
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());
}
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());
}
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;
}
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;
}
Aggregations