2020-07-13 16:48:56 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-11-21 17:08:41 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-03-20 10:40:46 +00:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/thumb"
|
2020-07-13 16:48:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfig_HttpServerHost2(t *testing.T) {
|
2020-07-13 18:25:47 +00:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-12-18 08:11:42 +00:00
|
|
|
assert.Equal(t, "0.0.0.0", c.HttpHost())
|
2020-12-18 19:42:12 +00:00
|
|
|
c.options.HttpHost = "test"
|
2020-12-18 08:11:42 +00:00
|
|
|
assert.Equal(t, "test", c.HttpHost())
|
2020-07-13 16:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpServerPort2(t *testing.T) {
|
2020-07-13 18:25:47 +00:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-12-18 08:11:42 +00:00
|
|
|
assert.Equal(t, int(2342), c.HttpPort())
|
2020-12-18 19:42:12 +00:00
|
|
|
c.options.HttpPort = int(1234)
|
2020-12-18 08:11:42 +00:00
|
|
|
assert.Equal(t, int(1234), c.HttpPort())
|
2020-07-13 16:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpServerMode2(t *testing.T) {
|
2020-07-13 18:25:47 +00:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2022-10-13 21:44:51 +00:00
|
|
|
assert.Equal(t, HttpModeProd, c.HttpMode())
|
2020-12-18 19:42:12 +00:00
|
|
|
c.options.Debug = true
|
2022-10-13 21:44:51 +00:00
|
|
|
assert.Equal(t, HttpModeDebug, c.HttpMode())
|
2020-12-18 19:42:12 +00:00
|
|
|
c.options.HttpMode = "test"
|
2020-12-18 08:11:42 +00:00
|
|
|
assert.Equal(t, "test", c.HttpMode())
|
2020-07-13 16:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TemplateName(t *testing.T) {
|
2020-07-13 18:25:47 +00:00
|
|
|
c := NewConfig(CliTestContext())
|
2020-10-08 06:52:03 +00:00
|
|
|
c.initSettings()
|
2020-07-13 18:25:47 +00:00
|
|
|
|
2022-10-18 12:21:23 +00:00
|
|
|
assert.Equal(t, "index.gohtml", c.TemplateName())
|
|
|
|
c.settings.Templates.Default = "rainbow.gohtml"
|
|
|
|
assert.Equal(t, "rainbow.gohtml", c.TemplateName())
|
2020-07-13 17:25:27 +00:00
|
|
|
c.settings.Templates.Default = "xxx"
|
2022-10-18 12:21:23 +00:00
|
|
|
assert.Equal(t, "index.gohtml", c.TemplateName())
|
2020-07-13 17:25:27 +00:00
|
|
|
|
2020-07-13 16:48:56 +00:00
|
|
|
}
|
2021-02-22 10:07:00 +00:00
|
|
|
|
|
|
|
func TestConfig_HttpCompression(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "", c.HttpCompression())
|
|
|
|
}
|
2023-03-20 10:40:46 +00:00
|
|
|
|
2023-03-20 19:37:07 +00:00
|
|
|
func TestConfig_HttpCacheMaxAge(t *testing.T) {
|
2023-03-20 10:40:46 +00:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2023-03-20 19:37:07 +00:00
|
|
|
assert.Equal(t, thumb.MaxAge(2592000), c.HttpCacheMaxAge())
|
|
|
|
c.Options().HttpCacheMaxAge = 23
|
|
|
|
assert.Equal(t, thumb.MaxAge(23), c.HttpCacheMaxAge())
|
|
|
|
c.Options().HttpCacheMaxAge = 0
|
|
|
|
assert.Equal(t, thumb.MaxAge(2592000), c.HttpCacheMaxAge())
|
2023-03-20 10:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
}
|