2020-07-13 18:48:56 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2020-11-21 18:08:41 +01:00
|
|
|
"testing"
|
|
|
|
|
2020-07-13 18:48:56 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/thumb"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfig_ConvertSize(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-07-14 14:30:19 +02:00
|
|
|
assert.Equal(t, int(720), c.JpegSize())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.JpegSize = 31000
|
2020-07-14 14:30:19 +02:00
|
|
|
assert.Equal(t, int(30000), c.JpegSize())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.JpegSize = 800
|
2020-07-14 14:30:19 +02:00
|
|
|
assert.Equal(t, int(800), c.JpegSize())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_JpegQuality(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.Equal(t, int(25), c.JpegQuality())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.JpegQuality = 110
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.Equal(t, int(100), c.JpegQuality())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.JpegQuality = 98
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.Equal(t, int(98), c.JpegQuality())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ThumbFilter(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.Equal(t, thumb.ResampleFilter("cubic"), c.ThumbFilter())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.ThumbFilter = "blackman"
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.Equal(t, thumb.ResampleFilter("blackman"), c.ThumbFilter())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.ThumbFilter = "lanczos"
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.Equal(t, thumb.ResampleFilter("lanczos"), c.ThumbFilter())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.ThumbFilter = "linear"
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.Equal(t, thumb.ResampleFilter("linear"), c.ThumbFilter())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.ThumbFilter = "cubic"
|
2020-07-13 19:25:27 +02:00
|
|
|
assert.Equal(t, thumb.ResampleFilter("cubic"), c.ThumbFilter())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ThumbSizeUncached(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.False(t, c.ThumbUncached())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ThumbSize(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
assert.Equal(t, int(720), c.ThumbSizePrecached())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.ThumbSize = 7681
|
2021-09-05 12:32:08 +02:00
|
|
|
assert.Equal(t, int(7680), c.ThumbSizePrecached())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ThumbSizeUncached2(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.Equal(t, int(720), c.ThumbSizeUncached())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.ThumbSizeUncached = 7681
|
2020-07-13 18:48:56 +02:00
|
|
|
assert.Equal(t, int(7680), c.ThumbSizeUncached())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.ThumbSizeUncached = 800
|
|
|
|
c.options.ThumbSize = 900
|
2020-07-13 19:25:27 +02:00
|
|
|
assert.Equal(t, int(900), c.ThumbSizeUncached())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|