first commit
This commit is contained in:
44
pkg/images/processor_test.go
Normal file
44
pkg/images/processor_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package images
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeOptionsDefaults(t *testing.T) {
|
||||
opts, err := NormalizeOptions(ProcessOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if opts.Quality != DefaultQuality {
|
||||
t.Fatalf("expected default quality %d, got %d", DefaultQuality, opts.Quality)
|
||||
}
|
||||
if opts.Format != DefaultFormat {
|
||||
t.Fatalf("expected default format %q, got %q", DefaultFormat, opts.Format)
|
||||
}
|
||||
if opts.Width != 0 || opts.Height != 0 {
|
||||
t.Fatalf("expected width/height to stay 0 when not provided")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeOptionsJPGAlias(t *testing.T) {
|
||||
opts, err := NormalizeOptions(ProcessOptions{Format: "jpg", Quality: 10})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if opts.Format != "jpeg" {
|
||||
t.Fatalf("expected jpeg alias, got %q", opts.Format)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeOptionsRejectsInvalidValues(t *testing.T) {
|
||||
cases := []ProcessOptions{
|
||||
{Width: -1, Quality: 90, Format: "avif"},
|
||||
{Height: -1, Quality: 90, Format: "avif"},
|
||||
{Quality: 101, Format: "avif"},
|
||||
{Quality: 90, Format: "gif"},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
if _, err := NormalizeOptions(tc); err == nil {
|
||||
t.Fatalf("expected error for case: %+v", tc)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user