-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathoption_test.go
66 lines (62 loc) · 1.77 KB
/
option_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package vips
import (
"context"
"github.com/cshum/imagor"
"github.com/stretchr/testify/assert"
"runtime"
"testing"
)
func TestWithOption(t *testing.T) {
t.Run("options", func(t *testing.T) {
v := NewProcessor(
WithConcurrency(2),
WithMaxFilterOps(167),
WithMaxCacheSize(500),
WithMaxCacheMem(501),
WithMaxCacheFiles(10),
WithMaxWidth(999),
WithMaxHeight(998),
WithMaxResolution(1666667),
WithMozJPEG(true),
WithAvifSpeed(9),
WithStripMetadata(true),
WithDebug(true),
WithMaxAnimationFrames(3),
WithDisableFilters("rgb", "fill, watermark"),
WithFilter("noop", func(ctx context.Context, img *Image, load imagor.LoadFunc, args ...string) (err error) {
return nil
}),
)
assert.Equal(t, 2, v.Concurrency)
assert.Equal(t, 167, v.MaxFilterOps)
assert.Equal(t, 500, v.MaxCacheSize)
assert.Equal(t, 501, v.MaxCacheMem)
assert.Equal(t, 10, v.MaxCacheFiles)
assert.Equal(t, 999, v.MaxWidth)
assert.Equal(t, 998, v.MaxHeight)
assert.Equal(t, 1666667, v.MaxResolution)
assert.Equal(t, 3, v.MaxAnimationFrames)
assert.Equal(t, true, v.MozJPEG)
assert.Equal(t, true, v.StripMetadata)
assert.Equal(t, 9, v.AvifSpeed)
assert.Equal(t, []string{"rgb", "fill", "watermark"}, v.DisableFilters)
})
t.Run("edge options", func(t *testing.T) {
v := NewProcessor(
WithConcurrency(-1),
)
assert.Equal(t, runtime.NumCPU(), v.Concurrency)
})
}
func TestImportParamsOptionString(t *testing.T) {
p := NewImportParams()
p.FailOnError.Set(true)
p.AutoRotate.set(false)
p.Density.Set(13)
p.Page.Set(167)
p.HeifThumbnail.Set(true)
p.SvgUnlimited.Set(false)
p.JpegShrinkFactor.Set(12)
p.HeifThumbnail.Set(true)
assert.Equal(t, "page=167,dpi=13,fail=TRUE,shrink=12,autorotate=FALSE,unlimited=FALSE,thumbnail=TRUE", p.OptionString())
}