public void TestListDigests() { CacheStorageFiles cacheStorageFiles = new CacheStorageFiles(temporaryFolder.NewFolder().ToPath()); CacheStorageReader cacheStorageReader = new CacheStorageReader(cacheStorageFiles); // Creates test layer directories. Files.CreateDirectories(cacheStorageFiles.GetLayersDirectory().Resolve(layerDigest1.GetHash())); Files.CreateDirectories(cacheStorageFiles.GetLayersDirectory().Resolve(layerDigest2.GetHash())); // Checks that layer directories created are all listed. Assert.AreEqual( new HashSet <DescriptorDigest>(new[] { layerDigest1, layerDigest2 }), cacheStorageReader.FetchDigests()); // Checks that non-digest directories means the cache is corrupted. Files.CreateDirectory(cacheStorageFiles.GetLayersDirectory().Resolve("not a hash")); try { cacheStorageReader.FetchDigests(); Assert.Fail("Listing digests should have failed"); } catch (CacheCorruptedException ex) { Assert.That( ex.Message, Does.StartWith("Found non-digest file in layers directory")); Assert.IsInstanceOf <DigestException>(ex.InnerException); } }
public void TestGetLayersDirectory() { Assert.AreEqual( Paths.Get("cache", "directory", "layers"), TEST_CACHE_STORAGE_FILES.GetLayersDirectory()); }