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())
|
|
|
|
|
2022-04-01 13:25:25 +02:00
|
|
|
assert.Equal(t, 720, c.JpegSize())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.JpegSize = 31000
|
2022-04-01 13:25:25 +02:00
|
|
|
assert.Equal(t, 30000, c.JpegSize())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.JpegSize = 800
|
2022-04-01 13:25:25 +02:00
|
|
|
assert.Equal(t, 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())
|
|
|
|
|
2022-04-01 13:30:20 +02:00
|
|
|
assert.Equal(t, thumb.QualityDefault, c.JpegQuality())
|
2022-04-01 13:25:25 +02:00
|
|
|
c.options.JpegQuality = "110"
|
2022-04-01 13:30:20 +02:00
|
|
|
assert.Equal(t, thumb.QualityDefault, c.JpegQuality())
|
2022-04-01 13:25:25 +02:00
|
|
|
c.options.JpegQuality = "98"
|
|
|
|
assert.Equal(t, thumb.Quality(98), c.JpegQuality())
|
|
|
|
c.options.JpegQuality = ""
|
2022-04-01 13:30:20 +02:00
|
|
|
assert.Equal(t, thumb.QualityDefault, c.JpegQuality())
|
2022-04-01 13:25:25 +02:00
|
|
|
c.options.JpegQuality = "best "
|
|
|
|
assert.Equal(t, thumb.QualityBest, c.JpegQuality())
|
|
|
|
c.options.JpegQuality = "high"
|
|
|
|
assert.Equal(t, thumb.QualityHigh, c.JpegQuality())
|
|
|
|
c.options.JpegQuality = "medium "
|
2022-04-01 13:30:20 +02:00
|
|
|
assert.Equal(t, thumb.QualityDefault, c.JpegQuality())
|
2022-04-01 13:25:25 +02:00
|
|
|
c.options.JpegQuality = "low "
|
|
|
|
assert.Equal(t, thumb.QualityLow, c.JpegQuality())
|
|
|
|
c.options.JpegQuality = "bad"
|
|
|
|
assert.Equal(t, thumb.QualityBad, c.JpegQuality())
|
|
|
|
c.options.JpegQuality = "worst "
|
|
|
|
assert.Equal(t, thumb.QualityWorst, c.JpegQuality())
|
|
|
|
c.options.JpegQuality = "default"
|
2022-04-01 13:30:20 +02:00
|
|
|
assert.Equal(t, thumb.QualityDefault, c.JpegQuality())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|