use of com.google.cloud.tools.jib.blob.BlobDescriptor in project jib by google.
the class CacheMetadataTranslatorTest method setUp.
@Before
public void setUp() throws DigestException {
baseLayerBlobDescriptor = new BlobDescriptor(631, DescriptorDigest.fromDigest("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"));
baseLayerDiffId = DescriptorDigest.fromDigest("sha256:b56ae66c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a4647");
classesLayerBlobDescriptor = new BlobDescriptor(223, DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"));
classesLayerDiffId = DescriptorDigest.fromDigest("sha256:a3f3e99c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a8372");
}
use of com.google.cloud.tools.jib.blob.BlobDescriptor 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.BlobDescriptor in project jib by google.
the class JsonToImageTranslatorTest method testToImage_buildable.
private <T extends BuildableManifestTemplate> void testToImage_buildable(String jsonFilename, Class<T> manifestTemplateClass) throws IOException, LayerPropertyNotFoundException, LayerCountMismatchException, DigestException, URISyntaxException {
// Loads the container configuration JSON.
Path containerConfigurationJsonFile = Paths.get(getClass().getClassLoader().getResource("json/containerconfig.json").toURI());
ContainerConfigurationTemplate containerConfigurationTemplate = JsonTemplateMapper.readJsonFromFile(containerConfigurationJsonFile, ContainerConfigurationTemplate.class);
// Loads the manifest JSON.
Path manifestJsonFile = Paths.get(getClass().getClassLoader().getResource(jsonFilename).toURI());
T manifestTemplate = JsonTemplateMapper.readJsonFromFile(manifestJsonFile, manifestTemplateClass);
Image image = JsonToImageTranslator.toImage(manifestTemplate, containerConfigurationTemplate);
List<Layer> layers = image.getLayers();
Assert.assertEquals(1, layers.size());
Assert.assertEquals(new BlobDescriptor(1000000, DescriptorDigest.fromDigest("sha256:4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236")), layers.get(0).getBlobDescriptor());
Assert.assertEquals(DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"), layers.get(0).getDiffId());
Assert.assertEquals(Arrays.asList("some", "entrypoint", "command"), image.getEntrypoint());
Assert.assertEquals(Arrays.asList("VAR1=VAL1", "VAR2=VAL2"), image.getEnvironment());
}
use of com.google.cloud.tools.jib.blob.BlobDescriptor in project jib by google.
the class BlobCheckerTest method testHandleHttpResponseException.
@Test
public void testHandleHttpResponseException() throws IOException, RegistryErrorException {
HttpResponseException mockHttpResponseException = Mockito.mock(HttpResponseException.class);
Mockito.when(mockHttpResponseException.getStatusCode()).thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
ErrorResponseTemplate emptyErrorResponseTemplate = new ErrorResponseTemplate().addError(new ErrorEntryTemplate(ErrorCodes.BLOB_UNKNOWN.name(), "some message"));
Mockito.when(mockHttpResponseException.getContent()).thenReturn(Blobs.writeToString(JsonTemplateMapper.toBlob(emptyErrorResponseTemplate)));
BlobDescriptor blobDescriptor = testBlobChecker.handleHttpResponseException(mockHttpResponseException);
Assert.assertNull(blobDescriptor);
}
use of com.google.cloud.tools.jib.blob.BlobDescriptor 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;
}
Aggregations