Split internal/imgcache into the image proxy and the cache (closes #317)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The new package internal/imageproxy holds Proxy, which was imgcache.Service, with its Config, ImageResponse, CacheStatus and errors. imageproxy.New makes and registers the counters of upstream fetches and transforms. internal/imgcache holds the cache only, with its hit and miss counters, and imgcache.CacheConfig is imgcache.Config. The cache reads and writes each kind it keeps with one pair of methods: Variant and PutVariant, Source and PutSource, Failure and PutFailure. Source replaces LookupSource followed by GetSourceContent. imgcache.go and module.go are gone. The proxy's tests moved with it. The cache's tests check that the reconciliation pass removes an empty or cut file and its row. The proxy's tests remove them by hand, then check that Get fetches or converts again. Model: opus-5-5
This commit was merged in pull request #334.
This commit is contained in:
@@ -10,11 +10,11 @@ import (
|
||||
"sneak.berlin/go/pixa/internal/imagerequest"
|
||||
)
|
||||
|
||||
// TestStoreSource_StoresIdenticalBytesOfTwoURLsTwice stores the same bytes
|
||||
// TestPutSource_StoresIdenticalBytesOfTwoURLsTwice stores the same bytes
|
||||
// for two source URLs and checks that each URL has a source_content row of
|
||||
// its own and a file of its own, named by its source key under
|
||||
// cache/sources/<ab>/<cd>/.
|
||||
func TestStoreSource_StoresIdenticalBytesOfTwoURLsTwice(t *testing.T) {
|
||||
func TestPutSource_StoresIdenticalBytesOfTwoURLsTwice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cache, stateDir := newEvictionTestCache(t, 1<<30)
|
||||
@@ -84,18 +84,12 @@ func TestEvictSourceBlob_LeavesSourceWithIdenticalBytesServed(t *testing.T) {
|
||||
t.Errorf("the evicted source still has %d source_content rows", n)
|
||||
}
|
||||
|
||||
kept, err := cache.LookupSource(t.Context(), &imagerequest.Request{
|
||||
Source: imagerequest.Source{Host: testHostCDN, Path: "/kept.jpg"},
|
||||
})
|
||||
t.Logf("LookupSource() of the kept source = %q, error %v", kept, err)
|
||||
reader, _, err := cache.Source(t.Context(),
|
||||
imagerequest.Source{Host: testHostCDN, Path: "/kept.jpg"})
|
||||
t.Logf("Source() of the kept source: error %v", err)
|
||||
|
||||
if err != nil || kept == "" {
|
||||
t.Fatalf("LookupSource() of the kept source = %q, %v; want it cached", kept, err)
|
||||
}
|
||||
|
||||
reader, _, err := cache.GetSourceContent(kept)
|
||||
if err != nil {
|
||||
t.Fatalf("GetSourceContent() of the kept source error = %v", err)
|
||||
t.Fatalf("Source() of the kept source error = %v; want it cached", err)
|
||||
}
|
||||
|
||||
defer func() { _ = reader.Close() }()
|
||||
@@ -111,10 +105,10 @@ func TestEvictSourceBlob_LeavesSourceWithIdenticalBytesServed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestStoreSource_FailedRowWriteLeavesNoFile drops source_content, so that
|
||||
// StoreSource cannot write the source's row, and checks that the store fails
|
||||
// TestPutSource_FailedRowWriteLeavesNoFile drops source_content, so that
|
||||
// PutSource cannot write the source's row, and checks that the store fails
|
||||
// and leaves no file under the source's key.
|
||||
func TestStoreSource_FailedRowWriteLeavesNoFile(t *testing.T) {
|
||||
func TestPutSource_FailedRowWriteLeavesNoFile(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cache, _ := newEvictionTestCache(t, 1<<30)
|
||||
@@ -127,12 +121,12 @@ func TestStoreSource_FailedRowWriteLeavesNoFile(t *testing.T) {
|
||||
req := &imagerequest.Request{
|
||||
Source: imagerequest.Source{Host: testHostCDN, Path: testPathCat},
|
||||
}
|
||||
key, err := cache.StoreSource(t.Context(), req,
|
||||
key, err := cache.PutSource(t.Context(), req.Source,
|
||||
bytes.NewReader([]byte("source bytes")))
|
||||
t.Logf("StoreSource() = %q, error = %v", key, err)
|
||||
t.Logf("PutSource() = %q, error = %v", key, err)
|
||||
|
||||
if err == nil {
|
||||
t.Error("StoreSource() error = nil, want the failed row write")
|
||||
t.Error("PutSource() error = nil, want the failed row write")
|
||||
}
|
||||
|
||||
if cache.srcContent.Exists(req.Source.Key()) {
|
||||
|
||||
Reference in New Issue
Block a user