use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class TarStreamBuilderTest method testToBlob.
@Test
public void testToBlob() throws IOException {
Blob blob = testTarStreamBuilder.toBlob();
// Writes the BLOB and captures the output.
ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream();
blob.writeTo(tarByteOutputStream);
// Rearrange the output into input for verification.
ByteArrayInputStream tarByteInputStream = new ByteArrayInputStream(tarByteOutputStream.toByteArray());
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(tarByteInputStream);
verifyTarArchive(tarArchiveInputStream);
}
use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class BlobPusherIntegrationTest method testPush.
@Test
public void testPush() throws DigestException, IOException, RegistryException {
Blob testBlob = Blobs.from("crepecake");
// Known digest for 'crepecake'
DescriptorDigest testBlobDigest = DescriptorDigest.fromHash("52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c");
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "testimage");
Assert.assertFalse(registryClient.pushBlob(testBlobDigest, testBlob));
}
use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class ManifestPusherIntegrationTest method testPush.
/**
* Tests manifest pushing. This test is a comprehensive test of push and pull.
*/
@Test
public void testPush() throws DigestException, IOException, RegistryException {
Blob testLayerBlob = Blobs.from("crepecake");
// Known digest for 'crepecake'
DescriptorDigest testLayerBlobDigest = DescriptorDigest.fromHash("52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c");
Blob testContainerConfigurationBlob = Blobs.from("12345");
DescriptorDigest testContainerConfigurationBlobDigest = DescriptorDigest.fromHash("5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5");
// Creates a valid image manifest.
V22ManifestTemplate expectedManifestTemplate = new V22ManifestTemplate();
expectedManifestTemplate.addLayer(9, testLayerBlobDigest);
expectedManifestTemplate.setContainerConfiguration(5, testContainerConfigurationBlobDigest);
// Pushes the BLOBs.
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "testimage");
Assert.assertFalse(registryClient.pushBlob(testLayerBlobDigest, testLayerBlob));
Assert.assertFalse(registryClient.pushBlob(testContainerConfigurationBlobDigest, testContainerConfigurationBlob));
// Pushes the manifest.
registryClient.pushManifest(expectedManifestTemplate, "latest");
// Pulls the manifest.
V22ManifestTemplate manifestTemplate = registryClient.pullManifest("latest", V22ManifestTemplate.class);
Assert.assertEquals(1, manifestTemplate.getLayers().size());
Assert.assertEquals(testLayerBlobDigest, manifestTemplate.getLayers().get(0).getDigest());
Assert.assertEquals(testContainerConfigurationBlobDigest, manifestTemplate.getContainerConfiguration().getDigest());
}
use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class ResponseTest method testGetContent.
@Test
public void testGetContent() throws IOException {
String expectedResponse = "crepecake\nis\ngood!";
ByteArrayInputStream responseInputStream = new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8));
Mockito.when(httpResponseMock.getContent()).thenReturn(responseInputStream);
Response response = new Response(httpResponseMock);
Blob responseStream = response.getBody();
ByteArrayOutputStream responseOutputStream = new ByteArrayOutputStream();
responseStream.writeTo(responseOutputStream);
Assert.assertEquals(expectedResponse, new String(responseOutputStream.toByteArray(), StandardCharsets.UTF_8));
}
use of com.google.cloud.tools.jib.blob.Blob in project jib by google.
the class LayerBuilderTest method testToBlob_reproducibility.
@Test
public void testToBlob_reproducibility() throws IOException {
Path testRoot = temporaryFolder.getRoot().toPath();
Path root1 = Files.createDirectories(testRoot.resolve("files1"));
Path root2 = Files.createDirectories(testRoot.resolve("files2"));
String extractionPath = "/somewhere";
// TODO: Currently this test only covers variation in order and modified time, even though
// TODO: the code is designed to clean up userid/groupid, this test does not check that yet.
String contentA = "abcabc";
Path fileA1 = createFile(root1, "fileA", contentA, 10000);
Path fileA2 = createFile(root2, "fileA", contentA, 20000);
String contentB = "yumyum";
Path fileB1 = createFile(root1, "fileB", contentB, 10000);
Path fileB2 = createFile(root2, "fileB", contentB, 20000);
// check if modified times are off
Assert.assertNotEquals(Files.getLastModifiedTime(fileA1), Files.getLastModifiedTime(fileA2));
Assert.assertNotEquals(Files.getLastModifiedTime(fileB1), Files.getLastModifiedTime(fileB2));
// create layers of exact same content but ordered differently and with different timestamps
Blob layer = new LayerBuilder(Arrays.asList(fileA1, fileB1), extractionPath, true).build().getBlob();
Blob reproduced = new LayerBuilder(Arrays.asList(fileB2, fileA2), extractionPath, true).build().getBlob();
// this is a control layer that is the same as 'layerReproduced' without reproducibility on
Blob notReproduced = new LayerBuilder(Arrays.asList(fileB2, fileA2), extractionPath, false).build().getBlob();
byte[] layerContent = Blobs.writeToByteArray(layer);
byte[] reproducedLayerContent = Blobs.writeToByteArray(reproduced);
byte[] notReproducedLayerContent = Blobs.writeToByteArray(notReproduced);
Assert.assertThat(layerContent, CoreMatchers.is(reproducedLayerContent));
Assert.assertThat(layerContent, CoreMatchers.not(notReproducedLayerContent));
}
Aggregations