Skip to content

Commit

Permalink
Add failing redownload test
Browse files Browse the repository at this point in the history
We tested that modified last modified time on the server cause a
redownload, but we did not test that after a redownload we update the
cache, so the next attempt will used the cached download.

Add a failing test verifying the issue.

Part-of: #2902
Signed-off-by: Nir Soffer <[email protected]>
  • Loading branch information
nirs committed Nov 13, 2024
1 parent 77cbbda commit b54ca9a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,26 @@ func TestRedownloadRemote(t *testing.T) {
assert.NilError(t, os.Chtimes(remoteFile, time.Now(), time.Now().Add(-time.Hour)))
opt := []Opt{cacheOpt}

// Download on the first call
r, err := Download(context.Background(), filepath.Join(downloadDir, "digest-less1.txt"), ts.URL+"/digest-less.txt", opt...)
assert.NilError(t, err)
assert.Equal(t, StatusDownloaded, r.Status)

// Next download will use the cached download
r, err = Download(context.Background(), filepath.Join(downloadDir, "digest-less2.txt"), ts.URL+"/digest-less.txt", opt...)
assert.NilError(t, err)
assert.Equal(t, StatusUsedCache, r.Status)

// modifying remote file will cause redownload
// Modifying remote file will cause redownload
assert.NilError(t, os.Chtimes(remoteFile, time.Now(), time.Now()))
r, err = Download(context.Background(), filepath.Join(downloadDir, "digest-less3.txt"), ts.URL+"/digest-less.txt", opt...)
assert.NilError(t, err)
assert.Equal(t, StatusDownloaded, r.Status)

// Next download will use the cached download
r, err = Download(context.Background(), filepath.Join(downloadDir, "digest-less4.txt"), ts.URL+"/digest-less.txt", opt...)
assert.NilError(t, err)
assert.Equal(t, StatusUsedCache, r.Status)
})

t.Run("has-digest", func(t *testing.T) {
Expand Down

0 comments on commit b54ca9a

Please sign in to comment.