Skip to content

Commit b54ca9a

Browse files
committed
Add failing redownload test
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 <nsoffer@redhat.com>
1 parent 77cbbda commit b54ca9a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/downloader/downloader_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,26 @@ func TestRedownloadRemote(t *testing.T) {
203203
assert.NilError(t, os.Chtimes(remoteFile, time.Now(), time.Now().Add(-time.Hour)))
204204
opt := []Opt{cacheOpt}
205205

206+
// Download on the first call
206207
r, err := Download(context.Background(), filepath.Join(downloadDir, "digest-less1.txt"), ts.URL+"/digest-less.txt", opt...)
207208
assert.NilError(t, err)
208209
assert.Equal(t, StatusDownloaded, r.Status)
210+
211+
// Next download will use the cached download
209212
r, err = Download(context.Background(), filepath.Join(downloadDir, "digest-less2.txt"), ts.URL+"/digest-less.txt", opt...)
210213
assert.NilError(t, err)
211214
assert.Equal(t, StatusUsedCache, r.Status)
212215

213-
// modifying remote file will cause redownload
216+
// Modifying remote file will cause redownload
214217
assert.NilError(t, os.Chtimes(remoteFile, time.Now(), time.Now()))
215218
r, err = Download(context.Background(), filepath.Join(downloadDir, "digest-less3.txt"), ts.URL+"/digest-less.txt", opt...)
216219
assert.NilError(t, err)
217220
assert.Equal(t, StatusDownloaded, r.Status)
221+
222+
// Next download will use the cached download
223+
r, err = Download(context.Background(), filepath.Join(downloadDir, "digest-less4.txt"), ts.URL+"/digest-less.txt", opt...)
224+
assert.NilError(t, err)
225+
assert.Equal(t, StatusUsedCache, r.Status)
218226
})
219227

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

0 commit comments

Comments
 (0)