49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package resize
|
|
|
|
import (
|
|
"bytes"
|
|
"image"
|
|
"image/color"
|
|
"image/jpeg"
|
|
"testing"
|
|
)
|
|
|
|
func createTestImage() []byte {
|
|
img := image.NewRGBA(image.Rect(0, 0, 100, 100))
|
|
for x := 0; x < 100; x++ {
|
|
for y := 0; y < 100; y++ {
|
|
img.Set(x, y, color.RGBA{uint8(x), uint8(y), 255, 255})
|
|
}
|
|
}
|
|
var buf bytes.Buffer
|
|
_ = jpeg.Encode(&buf, img, nil)
|
|
return buf.Bytes()
|
|
}
|
|
|
|
func TestShrink_Success(t *testing.T) {
|
|
testImage := createTestImage()
|
|
result, err := Shrink(string(testImage), 50, 80)
|
|
if err != nil {
|
|
t.Fatalf("expected no error, got %v", err)
|
|
}
|
|
if len(result) == 0 {
|
|
t.Fatalf("expected non-empty result, got empty string")
|
|
}
|
|
}
|
|
|
|
func TestShrink_InvalidImage(t *testing.T) {
|
|
invalidImage := "not-an-image"
|
|
_, err := Shrink(invalidImage, 50, 80)
|
|
if err == nil {
|
|
t.Fatalf("expected an error for invalid image input, got nil")
|
|
}
|
|
}
|
|
|
|
func TestShrink_InvalidQuality(t *testing.T) {
|
|
testImage := createTestImage()
|
|
_, err := Shrink(string(testImage), 50, -10)
|
|
if err == nil {
|
|
t.Fatalf("expected an error for invalid quality, got nil")
|
|
}
|
|
}
|