summaryrefslogtreecommitdiff
path: root/internal/image/test_helpers_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/image/test_helpers_test.go')
-rw-r--r--internal/image/test_helpers_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/image/test_helpers_test.go b/internal/image/test_helpers_test.go
new file mode 100644
index 0000000..31bf30c
--- /dev/null
+++ b/internal/image/test_helpers_test.go
@@ -0,0 +1,38 @@
+package image
+
+import (
+ "bytes"
+ "image"
+ "image/color"
+ "image/jpeg"
+ "image/png"
+ "testing"
+)
+
+func mustPNGBytes(t *testing.T) []byte {
+ t.Helper()
+
+ img := image.NewRGBA(image.Rect(0, 0, 1, 1))
+ img.Set(0, 0, color.RGBA{R: 255, A: 255})
+
+ var buf bytes.Buffer
+ if err := png.Encode(&buf, img); err != nil {
+ t.Fatalf("png.Encode() error = %v", err)
+ }
+
+ return buf.Bytes()
+}
+
+func mustJPEGBytes(t *testing.T) []byte {
+ t.Helper()
+
+ img := image.NewRGBA(image.Rect(0, 0, 1, 1))
+ img.Set(0, 0, color.RGBA{G: 255, A: 255})
+
+ var buf bytes.Buffer
+ if err := jpeg.Encode(&buf, img, &jpeg.Options{Quality: 90}); err != nil {
+ t.Fatalf("jpeg.Encode() error = %v", err)
+ }
+
+ return buf.Bytes()
+}