check / check (push) Waiting to run
The new package internal/providers builds the cache, the fetcher, the processor, the image service, the session manager and the encrypted URL generator from the config. pixad's fx graph provides them with providers.Constructors(), and handlers.New receives them built. The server tests build the same graph, with only the fetcher's dial function replaced. database.New opens the database, so these parts can read it while fx builds them; the cache's stop hook still runs before the database's. Each setting's default is declared in internal/config, and internal/providers works out the default cache_max_bytes. The cache's MaxBytes is the one value for the disk cache limit, and 0 turns the disk cache off. The fetcher and the processor take explicit values. Model: opus-5-5
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package imageprocessor
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"testing"
|
|
|
|
"sneak.berlin/go/pixa/internal/imagerequest"
|
|
)
|
|
|
|
// TestImageProcessor_LoadsEachSourceFormat verifies that an image in each of
|
|
// the six source formats, saved by the processor itself, is loaded and saved
|
|
// again in its own format (orig).
|
|
func TestImageProcessor_LoadsEachSourceFormat(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
proc := New(Params{MaxInputBytes: 50 << 20, MaxConcurrentProcessing: 1})
|
|
|
|
for _, format := range []imagerequest.Format{
|
|
imagerequest.FormatJPEG, imagerequest.FormatPNG, imagerequest.FormatGIF,
|
|
imagerequest.FormatWebP, imagerequest.FormatAVIF, imagerequest.FormatJXL,
|
|
} {
|
|
saved, err := proc.Process(t.Context(),
|
|
bytes.NewReader(createTestPNG(t, 20, 20)),
|
|
&imagerequest.Transform{Format: format})
|
|
if err != nil {
|
|
t.Fatalf("saving the test image as %s: %v", format, err)
|
|
}
|
|
|
|
source, err := io.ReadAll(saved.Content)
|
|
if err != nil {
|
|
t.Fatalf("reading the %s image: %v", format, err)
|
|
}
|
|
|
|
result, err := proc.Process(t.Context(), bytes.NewReader(source),
|
|
&imagerequest.Transform{Format: imagerequest.FormatOriginal})
|
|
if err != nil {
|
|
t.Errorf("orig of the %s image: %v", format, err)
|
|
|
|
continue
|
|
}
|
|
|
|
t.Logf("orig of the %s image: %s", format, result.ContentType)
|
|
|
|
if result.ContentType != FormatToMIME(format) {
|
|
t.Errorf("orig of the %s image is %s, want %s",
|
|
format, result.ContentType, FormatToMIME(format))
|
|
}
|
|
}
|
|
}
|