2020-07-13 18:48:56 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-11-21 18:08:41 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-03-20 11:40:46 +01:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/thumb"
|
2020-07-13 18:48:56 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfig_HttpServerHost2(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
assert.Equal(t, "0.0.0.0", c.HttpHost())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.HttpHost = "test"
|
2020-12-18 09:11:42 +01:00
|
|
|
assert.Equal(t, "test", c.HttpHost())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpServerPort2(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
assert.Equal(t, int(2342), c.HttpPort())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.HttpPort = int(1234)
|
2020-12-18 09:11:42 +01:00
|
|
|
assert.Equal(t, int(1234), c.HttpPort())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpServerMode2(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2022-10-13 23:44:51 +02:00
|
|
|
assert.Equal(t, HttpModeProd, c.HttpMode())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.Debug = true
|
2022-10-13 23:44:51 +02:00
|
|
|
assert.Equal(t, HttpModeDebug, c.HttpMode())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.HttpMode = "test"
|
2020-12-18 09:11:42 +01:00
|
|
|
assert.Equal(t, "test", c.HttpMode())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TemplateName(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2020-10-08 08:52:03 +02:00
|
|
|
c.initSettings()
|
2020-07-13 20:25:47 +02:00
|
|
|
|
2022-10-18 14:21:23 +02:00
|
|
|
assert.Equal(t, "index.gohtml", c.TemplateName())
|
|
|
|
c.settings.Templates.Default = "rainbow.gohtml"
|
|
|
|
assert.Equal(t, "rainbow.gohtml", c.TemplateName())
|
2020-07-13 19:25:27 +02:00
|
|
|
c.settings.Templates.Default = "xxx"
|
2022-10-18 14:21:23 +02:00
|
|
|
assert.Equal(t, "index.gohtml", c.TemplateName())
|
2020-07-13 19:25:27 +02:00
|
|
|
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
2021-02-22 11:07:00 +01:00
|
|
|
|
|
|
|
func TestConfig_HttpCompression(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "", c.HttpCompression())
|
|
|
|
}
|
2023-03-20 11:40:46 +01:00
|
|
|
|
|
|
|
func TestConfig_HttpCacheTTL(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, thumb.MaxAge(2630000), c.HttpCacheTTL())
|
|
|
|
c.Options().HttpCacheTTL = 23
|
|
|
|
assert.Equal(t, thumb.MaxAge(23), c.HttpCacheTTL())
|
|
|
|
c.Options().HttpCacheTTL = 0
|
|
|
|
assert.Equal(t, thumb.MaxAge(2630000), c.HttpCacheTTL())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpCachePublic(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.False(t, c.HttpCachePublic())
|
|
|
|
c.Options().CdnUrl = "https://cdn.com/"
|
|
|
|
assert.True(t, c.HttpCachePublic())
|
|
|
|
c.Options().CdnUrl = ""
|
|
|
|
assert.False(t, c.HttpCachePublic())
|
|
|
|
c.Options().HttpCachePublic = true
|
|
|
|
assert.True(t, c.HttpCachePublic())
|
|
|
|
c.Options().HttpCachePublic = false
|
|
|
|
assert.False(t, c.HttpCachePublic())
|
|
|
|
}
|