use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class CacheStorageFilesTest method testGetLayerDirectory.
@Test
public void testGetLayerDirectory() throws DigestException {
DescriptorDigest layerDigest = DescriptorDigest.fromHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
Assert.assertEquals(Paths.get("cache", "directory", "layers", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), TEST_CACHE_STORAGE_FILES.getLayerDirectory(layerDigest));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class CacheStorageFilesTest method testGetSelectorFile.
@Test
public void testGetSelectorFile() throws DigestException {
DescriptorDigest selector = DescriptorDigest.fromHash("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc");
Assert.assertEquals(Paths.get("cache", "directory", "selectors", "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"), TEST_CACHE_STORAGE_FILES.getSelectorFile(selector));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class CacheStorageReaderTest method testSelect_invalidLayerDigest.
@Test
public void testSelect_invalidLayerDigest() throws IOException {
DescriptorDigest selector = layerDigest1;
Path selectorFile = cacheStorageFiles.getSelectorFile(selector);
Files.createDirectories(selectorFile.getParent());
Files.write(selectorFile, "not a valid layer digest".getBytes(StandardCharsets.UTF_8));
try {
cacheStorageReader.select(selector);
Assert.fail("Should have thrown CacheCorruptedException");
} catch (CacheCorruptedException ex) {
MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Expected valid layer digest as contents of selector file `" + selectorFile + "` for selector `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`, but got: not a valid layer digest"));
}
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
the class CacheStorageReaderTest method testSelect.
@Test
public void testSelect() throws IOException, CacheCorruptedException {
DescriptorDigest selector = layerDigest1;
Path selectorFile = cacheStorageFiles.getSelectorFile(selector);
Files.createDirectories(selectorFile.getParent());
Files.write(selectorFile, layerDigest2.getHash().getBytes(StandardCharsets.UTF_8));
Optional<DescriptorDigest> selectedLayerDigest = cacheStorageReader.select(selector);
Assert.assertTrue(selectedLayerDigest.isPresent());
Assert.assertEquals(layerDigest2, selectedLayerDigest.get());
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by google.
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())));
}
Aggregations