use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class CachedLayerTest method testGetBlob.
@Test
public void testGetBlob() throws URISyntaxException, IOException {
Path fileA = Paths.get(Resources.getResource("fileA").toURI());
String expectedFileAString = new String(Files.readAllBytes(fileA), StandardCharsets.UTF_8);
CachedLayer cachedLayer = new CachedLayer(fileA, mockBlobDescriptor, mockDiffId);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Blob fileBlob = cachedLayer.getBlob();
fileBlob.writeTo(outputStream);
Assert.assertEquals(expectedFileAString, new String(outputStream.toByteArray(), StandardCharsets.UTF_8));
Assert.assertEquals(mockBlobDescriptor, cachedLayer.getBlobDescriptor());
Assert.assertEquals(mockDiffId, cachedLayer.getDiffId());
}
use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class ImageToJsonTranslatorTest method testGetContainerConfiguration.
@Test
public void testGetContainerConfiguration() throws IOException, LayerPropertyNotFoundException, URISyntaxException {
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource("json/containerconfig.json").toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
// Translates the image to the container configuration and writes the JSON string.
Blob containerConfigurationBlob = imageToJsonTranslator.getContainerConfigurationBlob();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
containerConfigurationBlob.writeTo(byteArrayOutputStream);
Assert.assertEquals(expectedJson, new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8));
}
use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class ImageToJsonTranslatorTest method testGetManifest.
/**
* Tests translation of image to {@link BuildableManifestTemplate}.
*/
private <T extends BuildableManifestTemplate> void testGetManifest(Class<T> manifestTemplateClass, String translatedJsonFilename) throws URISyntaxException, IOException, LayerPropertyNotFoundException {
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource(translatedJsonFilename).toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
// Translates the image to the manifest and writes the JSON string.
Blob containerConfigurationBlob = imageToJsonTranslator.getContainerConfigurationBlob();
BlobDescriptor blobDescriptor = containerConfigurationBlob.writeTo(ByteStreams.nullOutputStream());
T manifestTemplate = imageToJsonTranslator.getManifestTemplate(manifestTemplateClass, blobDescriptor);
ByteArrayOutputStream jsonStream = new ByteArrayOutputStream();
JsonTemplateMapper.toBlob(manifestTemplate).writeTo(jsonStream);
Assert.assertEquals(expectedJson, new String(jsonStream.toByteArray(), StandardCharsets.UTF_8));
}
use of com.google.cloud.tools.jib.blob.Blob 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.blob.Blob 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());
}
Aggregations