detect_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package imagedetect
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/imgproxy/imgproxy/v3/imagetype_new"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestDetect(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. file string
  12. want imagetype_new.Type
  13. }{
  14. {"JPEG", "../testdata/test-images/jpg/jpg.jpg", imagetype_new.JPEG},
  15. {"JXL", "../testdata/test-images/jxl/jxl.jxl", imagetype_new.JXL},
  16. {"PNG", "../testdata/test-images/png/png.png", imagetype_new.PNG},
  17. {"WEBP", "../testdata/test-images/webp/webp.webp", imagetype_new.WEBP},
  18. {"GIF", "../testdata/test-images/gif/gif.gif", imagetype_new.GIF},
  19. {"ICO", "../testdata/test-images/ico/png-256x256.ico", imagetype_new.ICO},
  20. {"SVG", "../testdata/test-images/svg/svg.svg", imagetype_new.SVG},
  21. {"HEIC", "../testdata/test-images/heif/heif.heif", imagetype_new.HEIC},
  22. {"BMP", "../testdata/test-images/bmp/24-bpp.bmp", imagetype_new.BMP},
  23. {"TIFF", "../testdata/test-images/tiff/tiff.tiff", imagetype_new.TIFF},
  24. {"SVG", "../testdata/test-images/svg/svg.svg", imagetype_new.SVG},
  25. }
  26. for _, tt := range tests {
  27. t.Run(tt.name, func(t *testing.T) {
  28. f, err := os.Open(tt.file)
  29. require.NoError(t, err)
  30. defer f.Close()
  31. got, err := Detect(f)
  32. require.NoError(t, err)
  33. require.Equal(t, tt.want, got)
  34. })
  35. }
  36. }