MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestDetect

Function TestDetect

imagetype/type_test.go:33–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestDetect(t *testing.T) {
34 tests := []struct {
35 name string
36 file string
37 want imagetype.Type
38 }{
39 {"JPEG", "../testdata/test-images/jpg/jpg.jpg", imagetype.JPEG},
40 {"JXL", "../testdata/test-images/jxl/jxl.jxl", imagetype.JXL},
41 {"PNG", "../testdata/test-images/png/png.png", imagetype.PNG},
42 {"WEBP", "../testdata/test-images/webp/webp.webp", imagetype.WEBP},
43 {"GIF", "../testdata/test-images/gif/gif.gif", imagetype.GIF},
44 {"ICO", "../testdata/test-images/ico/png-256x256.ico", imagetype.ICO},
45 {"SVG", "../testdata/test-images/svg/svg.svg", imagetype.SVG},
46 {"HEIC", "../testdata/test-images/heif/heif.heif", imagetype.HEIC},
47 {"BMP", "../testdata/test-images/bmp/24-bpp.bmp", imagetype.BMP},
48 {"TIFF", "../testdata/test-images/tiff/tiff.tiff", imagetype.TIFF},
49 {"SVG", "../testdata/test-images/svg/svg.svg", imagetype.SVG},
50 {"RAW", "../testdata/test-images/raw/RAW_CANON_1DM2.CR2", imagetype.Unknown}, // RAW is not supported
51 }
52
53 for _, tt := range tests {
54 t.Run(tt.name, func(t *testing.T) {
55 f, err := os.Open(tt.file)
56 require.NoError(t, err)
57 defer f.Close()
58
59 got, err := imagetype.Detect(f, "", path.Ext(tt.file))
60 if tt.want == imagetype.Unknown {
61 require.Error(t, err)
62 } else {
63 require.NoError(t, err)
64 }
65 require.Equal(t, tt.want, got)
66 })
67 }
68}

Callers

nothing calls this directly

Calls 5

DetectFunction · 0.92
RunMethod · 0.80
ExtMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected