Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ff59fd5f6 |
@@ -2,7 +2,9 @@ package imgcache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -438,8 +440,9 @@ func TestService_Get_ServesSourceAndVariantCachedTwoDaysAgo(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
svc, fixtures := SetupTestService(t)
|
svc, fixtures := SetupTestService(t)
|
||||||
|
variant := photoVariant(fixtures, 85, FitCover)
|
||||||
|
|
||||||
resp, err := svc.Get(t.Context(), photoVariant(fixtures, 85, FitCover))
|
resp, err := svc.Get(t.Context(), variant)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Get() first request error = %v", err)
|
t.Fatalf("Get() first request error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -462,7 +465,31 @@ func TestService_Get_ServesSourceAndVariantCachedTwoDaysAgo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err = svc.Get(t.Context(), photoVariant(fixtures, 85, FitCover))
|
// The variant's creation time is also its file's modification time
|
||||||
|
// and the created_at in its .meta file
|
||||||
|
twoDaysAgo := time.Now().AddDate(0, 0, -2)
|
||||||
|
variantPath := svc.cache.variants.keyToPath(CacheKey(variant))
|
||||||
|
|
||||||
|
err = os.Chtimes(variantPath, twoDaysAgo, twoDaysAgo)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("setting the variant file's modification time back: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
meta, err := json.Marshal(VariantMeta{
|
||||||
|
ContentType: resp.ContentType,
|
||||||
|
Size: resp.ContentLength,
|
||||||
|
CreatedAt: twoDaysAgo.Unix(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("encoding .meta file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile(variantPath+".meta", meta, StorageFilePerm)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("writing .meta file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err = svc.Get(t.Context(), variant)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Get() of the cached variant error = %v", err)
|
t.Fatalf("Get() of the cached variant error = %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user