use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class CacheStorageWriterTest method verifyCachedLayer.
private void verifyCachedLayer(CachedLayer cachedLayer, Blob uncompressedLayerBlob) throws IOException {
BlobDescriptor layerBlobDescriptor = getDigest(compress(uncompressedLayerBlob));
DescriptorDigest layerDiffId = getDigest(uncompressedLayerBlob).getDigest();
// Verifies cachedLayer is correct.
Assert.assertEquals(layerBlobDescriptor.getDigest(), cachedLayer.getDigest());
Assert.assertEquals(layerDiffId, cachedLayer.getDiffId());
Assert.assertEquals(layerBlobDescriptor.getSize(), cachedLayer.getSize());
Assert.assertArrayEquals(Blobs.writeToByteArray(uncompressedLayerBlob), Blobs.writeToByteArray(decompress(cachedLayer.getBlob())));
// Verifies that the files are present.
Assert.assertTrue(Files.exists(cacheStorageFiles.getLayerFile(cachedLayer.getDigest(), cachedLayer.getDiffId())));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class CacheStorageWriterTest method testWriteTarLayer.
@Test
public void testWriteTarLayer() throws IOException {
Blob uncompressedLayerBlob = Blobs.from("uncompressedLayerBlob");
DescriptorDigest diffId = getDigest(uncompressedLayerBlob).getDigest();
CachedLayer cachedLayer = cacheStorageWriter.writeTarLayer(diffId, compress(uncompressedLayerBlob));
BlobDescriptor layerBlobDescriptor = getDigest(compress(uncompressedLayerBlob));
// Verifies cachedLayer is correct.
Assert.assertEquals(layerBlobDescriptor.getDigest(), cachedLayer.getDigest());
Assert.assertEquals(diffId, cachedLayer.getDiffId());
Assert.assertEquals(layerBlobDescriptor.getSize(), cachedLayer.getSize());
Assert.assertArrayEquals(Blobs.writeToByteArray(uncompressedLayerBlob), Blobs.writeToByteArray(decompress(cachedLayer.getBlob())));
// Verifies that the files are present.
Assert.assertTrue(Files.exists(cacheStorageFiles.getLocalDirectory().resolve(cachedLayer.getDiffId().getHash()).resolve(cachedLayer.getDigest().getHash())));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class LayerEntriesSelectorTest method testGenerateSelector.
@Test
public void testGenerateSelector() throws IOException {
DescriptorDigest expectedSelector = Digests.computeJsonDigest(toLayerEntryTemplates(inOrderLayerEntries));
Assert.assertEquals(expectedSelector, LayerEntriesSelector.generateSelector(outOfOrderLayerEntries));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class LayerEntriesSelectorTest method testGenerateSelector_sourceModificationTimeChanged.
@Test
public void testGenerateSelector_sourceModificationTimeChanged() throws IOException {
Path layerFile = temporaryFolder.newFile().toPath();
Files.setLastModifiedTime(layerFile, FileTime.from(Instant.EPOCH));
FileEntry layerEntry = defaultLayerEntry(layerFile, AbsoluteUnixPath.get("/extraction/path"));
DescriptorDigest expectedSelector = LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry));
// Verify that changing source modification time generates a different selector
Files.setLastModifiedTime(layerFile, FileTime.from(Instant.ofEpochSecond(1)));
Assert.assertNotEquals(expectedSelector, LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry)));
// Verify that changing source modification time back generates same selector
Files.setLastModifiedTime(layerFile, FileTime.from(Instant.EPOCH));
Assert.assertEquals(expectedSelector, LayerEntriesSelector.generateSelector(ImmutableList.of(layerEntry)));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class CacheStorageFilesTest method testGetLayerFile.
@Test
public void testGetLayerFile() throws DigestException {
DescriptorDigest layerDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
DescriptorDigest diffId = DescriptorDigest.fromHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
Assert.assertEquals(Paths.get("cache", "directory", "layers", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), TEST_CACHE_STORAGE_FILES.getLayerFile(layerDigest, diffId));
}
Aggregations