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

Function TestImageTypes

env/types_test.go:327–365  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

325}
326
327func TestImageTypes(t *testing.T) {
328 tests := []struct {
329 input string
330 want []imagetype.Type
331 wantErr bool
332 errSubstr string
333 }{
334 {
335 input: "jpg,png,webp",
336 want: []imagetype.Type{imagetype.JPEG, imagetype.PNG, imagetype.WEBP},
337 },
338 {
339 input: " jpg , png , webp ",
340 want: []imagetype.Type{imagetype.JPEG, imagetype.PNG, imagetype.WEBP},
341 },
342 {input: "jpg,unknown,png", wantErr: true, errSubstr: "unknown image format"},
343 {input: "", want: nil},
344 }
345
346 for _, tt := range tests {
347 t.Run(tt.input, func(t *testing.T) {
348 t.Setenv(testVar, tt.input)
349 desc := env.ImageTypes(testVar)
350
351 var result []imagetype.Type
352 err := desc.Parse(&result)
353
354 if tt.wantErr {
355 require.Error(t, err)
356 if tt.errSubstr != "" {
357 assert.Contains(t, err.Error(), tt.errSubstr)
358 }
359 } else {
360 require.NoError(t, err)
361 assert.ElementsMatch(t, tt.want, result)
362 }
363 })
364 }
365}
366
367func TestImageTypesQuality(t *testing.T) {
368 tests := []struct {

Callers

nothing calls this directly

Calls 4

ImageTypesFunction · 0.92
RunMethod · 0.80
ParseMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected