MCPcopy
hub / github.com/cshum/imagor / TestColorImagePath

Function TestColorImagePath

imagor_test.go:2252–2377  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2250}
2251
2252func TestColorImagePath(t *testing.T) {
2253 t.Run("color image skips loader", func(t *testing.T) {
2254 loaderCalled := false
2255 app := New(
2256 WithUnsafe(true),
2257 WithDebug(true),
2258 WithLogger(zap.NewExample()),
2259 WithLoaders(loaderFunc(func(r *http.Request, image string) (*Blob, error) {
2260 loaderCalled = true
2261 return nil, ErrNotFound
2262 })),
2263 WithProcessors(processorFunc(func(ctx context.Context, blob *Blob, p imagorpath.Params, load LoadFunc) (*Blob, error) {
2264 assert.Nil(t, blob, "blob should be nil for color image")
2265 assert.Equal(t, "color:red", p.Image)
2266 return NewBlobFromBytes([]byte("processed")), nil
2267 })),
2268 )
2269 w := httptest.NewRecorder()
2270 app.ServeHTTP(w, httptest.NewRequest(
2271 http.MethodGet, "https://example.com/unsafe/200x200/color:red", nil))
2272 assert.Equal(t, 200, w.Code)
2273 assert.Equal(t, "processed", w.Body.String())
2274 assert.False(t, loaderCalled, "loader should not be called for color image")
2275 })
2276
2277 t.Run("color image with filters", func(t *testing.T) {
2278 app := New(
2279 WithUnsafe(true),
2280 WithDebug(true),
2281 WithLogger(zap.NewExample()),
2282 WithProcessors(processorFunc(func(ctx context.Context, blob *Blob, p imagorpath.Params, load LoadFunc) (*Blob, error) {
2283 assert.Nil(t, blob)
2284 assert.Equal(t, "color:ff0000", p.Image)
2285 assert.Equal(t, 100, p.Width)
2286 assert.Equal(t, 100, p.Height)
2287 assert.Len(t, p.Filters, 1)
2288 assert.Equal(t, "format", p.Filters[0].Name)
2289 assert.Equal(t, "png", p.Filters[0].Args)
2290 return NewBlobFromBytes([]byte("color-png")), nil
2291 })),
2292 )
2293 w := httptest.NewRecorder()
2294 app.ServeHTTP(w, httptest.NewRequest(
2295 http.MethodGet, "https://example.com/unsafe/100x100/filters:format(png)/color:ff0000", nil))
2296 assert.Equal(t, 200, w.Code)
2297 assert.Equal(t, "color-png", w.Body.String())
2298 })
2299
2300 t.Run("color image does not save to storage", func(t *testing.T) {
2301 store := newMapStore()
2302 app := New(
2303 WithUnsafe(true),
2304 WithDebug(true),
2305 WithLogger(zap.NewExample()),
2306 WithStorages(store),
2307 WithProcessors(processorFunc(func(ctx context.Context, blob *Blob, p imagorpath.Params, load LoadFunc) (*Blob, error) {
2308 return NewBlobFromBytes([]byte("color-result")), nil
2309 })),

Callers

nothing calls this directly

Calls 15

NewDefaultSignerFunction · 0.92
WithUnsafeFunction · 0.85
WithLoadersFunction · 0.85
WithProcessorsFunction · 0.85
processorFuncFuncType · 0.85
NewBlobFromBytesFunction · 0.85
newMapStoreFunction · 0.85
WithStoragesFunction · 0.85
WithSignerFunction · 0.85
RunMethod · 0.80
ServeHTTPMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected