Search in sources :

Example 1 with Blob

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());
}
Also used : Path(java.nio.file.Path) Blob(com.google.cloud.tools.jib.blob.Blob) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with Blob

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));
}
Also used : Path(java.nio.file.Path) Blob(com.google.cloud.tools.jib.blob.Blob) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 3 with Blob

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));
}
Also used : Path(java.nio.file.Path) Blob(com.google.cloud.tools.jib.blob.Blob) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with Blob

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());
    }
}
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 5 with Blob

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

Aggregations

Blob (com.google.cloud.tools.jib.blob.Blob)13 Test (org.junit.Test)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 DescriptorDigest (com.google.cloud.tools.jib.image.DescriptorDigest)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Path (java.nio.file.Path)4 BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)3 CountingDigestOutputStream (com.google.cloud.tools.jib.hash.CountingDigestOutputStream)2 Response (com.google.cloud.tools.jib.http.Response)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)2 HttpResponse (com.google.api.client.http.HttpResponse)1 Timer (com.google.cloud.tools.jib.Timer)1 CachedLayer (com.google.cloud.tools.jib.cache.CachedLayer)1 Image (com.google.cloud.tools.jib.image.Image)1 ImageToJsonTranslator (com.google.cloud.tools.jib.image.json.ImageToJsonTranslator)1 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)1 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1