Ejemplo n.º 1
0
        public async Task TestWriteUncompressedWithLayerEntries_retrieveByLayerEntriesAsync()
        {
            LayersCache cache = LayersCache.WithDirectory(temporaryFolder.NewFolder().ToPath());

            await VerifyIsLayer1Async(await cache.WriteUncompressedLayerAsync(layerBlob1, layerEntries1).ConfigureAwait(false)).ConfigureAwait(false);

            Maybe <CachedLayer> layer = await cache.RetrieveAsync(layerEntries1).ConfigureAwait(false);

            await VerifyIsLayer1Async(layer.OrElseThrow(() => new AssertionException(""))).ConfigureAwait(false);

            Assert.IsFalse(cache.Retrieve(layerDigest2).IsPresent());

            // A source file modification results in the cached layer to be out-of-date and not retrieved.
            Files.SetLastModifiedTime(
                layerEntries1[0].SourceFile, FileTime.From(SystemClock.Instance.GetCurrentInstant() + Duration.FromSeconds(1)));
            Maybe <CachedLayer> outOfDateLayer = await cache.RetrieveAsync(layerEntries1).ConfigureAwait(false);

            Assert.IsFalse(outOfDateLayer.IsPresent());
        }
Ejemplo n.º 2
0
        public async Task TestGenerateSelector_fileModifiedAsync()
        {
            SystemPath layerFile = temporaryFolder.NewFolder("testFolder").ToPath().Resolve("file");

            Files.Write(layerFile, Encoding.UTF8.GetBytes("hello"));
            Files.SetLastModifiedTime(layerFile, FileTime.From(Instant.FromUnixTimeSeconds(0)));
            LayerEntry       layerEntry       = DefaultLayerEntry(layerFile, AbsoluteUnixPath.Get("/extraction/path"));
            DescriptorDigest expectedSelector =
                await GenerateSelectorAsync(ImmutableArray.Create(layerEntry)).ConfigureAwait(false);

            // Verify that changing modified time generates a different selector
            Files.SetLastModifiedTime(layerFile, FileTime.From(Instant.FromUnixTimeSeconds(1)));
            Assert.AreNotEqual(
                expectedSelector, await GenerateSelectorAsync(ImmutableArray.Create(layerEntry)).ConfigureAwait(false));

            // Verify that changing modified time back generates same selector
            Files.SetLastModifiedTime(layerFile, FileTime.From(Instant.FromUnixTimeSeconds(0)));
            Assert.AreEqual(
                expectedSelector,
                await GenerateSelectorAsync(ImmutableArray.Create(layerEntry)).ConfigureAwait(false));
        }