package imageprocessor import ( "bytes" "io" "testing" ) // 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{}) for _, format := range []Format{ FormatJPEG, FormatPNG, FormatGIF, FormatWebP, FormatAVIF, FormatJXL, } { saved, err := proc.Process(t.Context(), bytes.NewReader(createTestPNG(t, 20, 20)), &Request{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), &Request{Format: 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)) } } }