diff options
author | 2018-04-23 01:51:01 -0700 | |
---|---|---|
committer | 2018-04-23 01:52:42 -0700 | |
commit | c49f9d8b50a7fe8984b51bc01d68b6923d52cc82 (patch) | |
tree | c851269360363bc39b25842e165c67a9b3bed7c7 /src/test | |
parent | 84d3097537f045a78baaebc3c6f2ffef4d814cb5 (diff) |
Repository cache: add a put method determining the key itself
Add a new put method to the repository cache, that computes the cache key
itself. The key is returned, so it can be reused without having to recompute
it. This is a convenient interface for caching a file that was downloaded
without prior knowledge of its hash.
Change-Id: I6ac844f4166bf64498b87e483896d155df35475e
PiperOrigin-RevId: 193889444
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCacheTest.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCacheTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCacheTest.java index dc1a690c86..35ce53c4fa 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCacheTest.java @@ -84,6 +84,22 @@ public class RepositoryCacheTest { } /** + * Test that the put mehtod without cache key correctly stores the downloaded file into the cache. + */ + @Test + public void testPutCacheValueWithoutHash() throws IOException { + String cacheKey = repositoryCache.put(downloadedFile, KeyType.SHA256); + assertThat(cacheKey).isEqualTo(downloadedFileSha256); + + Path cacheEntry = + KeyType.SHA256.getCachePath(contentAddressableCachePath).getChild(downloadedFileSha256); + Path cacheValue = cacheEntry.getChild(RepositoryCache.DEFAULT_CACHE_FILENAME); + + assertThat(FileSystemUtils.readContent(downloadedFile, Charset.defaultCharset())) + .isEqualTo(FileSystemUtils.readContent(cacheValue, Charset.defaultCharset())); + } + + /** * Test that the put method is idempotent, i.e. two successive put calls * should not affect the final state in the cache. */ |