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
|
|
|
|
2023-08-15 11:06:43 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/ttl"
|
2020-07-13 18:48:56 +02:00
|
|
|
)
|
|
|
|
|
2023-08-16 10:14:19 +02:00
|
|
|
func TestConfig_HttpServerHost(t *testing.T) {
|
2023-08-14 10:00:35 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2023-08-16 10:14:19 +02:00
|
|
|
assert.Equal(t, "0.0.0.0", c.HttpHost())
|
|
|
|
c.options.HttpHost = "test"
|
|
|
|
assert.Equal(t, "test", c.HttpHost())
|
2023-08-14 10:00:35 +02:00
|
|
|
c.options.HttpHost = "unix:/tmp/photoprism.sock"
|
2023-08-16 10:14:19 +02:00
|
|
|
assert.Equal(t, "unix:/tmp/photoprism.sock", c.HttpHost())
|
2023-08-14 10:00:35 +02:00
|
|
|
}
|
|
|
|
|
2023-08-16 10:14:19 +02:00
|
|
|
func TestConfig_HttpSocket(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2023-08-16 10:14:19 +02:00
|
|
|
assert.Equal(t, "", c.HttpSocket())
|
2023-08-14 10:00:35 +02:00
|
|
|
c.options.HttpHost = "unix:/tmp/photoprism.sock"
|
2023-08-16 10:14:19 +02:00
|
|
|
assert.Equal(t, "/tmp/photoprism.sock", c.HttpSocket())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
|
|
|
|
2023-08-16 10:14:19 +02:00
|
|
|
func TestConfig_HttpServerPort(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2023-08-16 10:14:19 +02:00
|
|
|
assert.Equal(t, 2342, c.HttpPort())
|
|
|
|
c.options.HttpPort = 1234
|
|
|
|
assert.Equal(t, 1234, c.HttpPort())
|
2020-07-13 18:48:56 +02:00
|
|
|
}
|
|
|
|
|
2023-08-16 10:14:19 +02:00
|
|
|
func TestConfig_HttpServerMode(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
|
|
|
|
2023-03-20 20:37:07 +01:00
|
|
|
func TestConfig_HttpCacheMaxAge(t *testing.T) {
|
2023-03-20 11:40:46 +01:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2023-08-15 11:06:43 +02:00
|
|
|
assert.Equal(t, ttl.Duration(2592000), c.HttpCacheMaxAge())
|
2023-03-20 20:37:07 +01:00
|
|
|
c.Options().HttpCacheMaxAge = 23
|
2023-08-15 11:06:43 +02:00
|
|
|
assert.Equal(t, ttl.Duration(23), c.HttpCacheMaxAge())
|
|
|
|
c.Options().HttpCacheMaxAge = 41536000
|
|
|
|
assert.Equal(t, ttl.Limit, c.HttpCacheMaxAge())
|
2023-03-20 20:37:07 +01:00
|
|
|
c.Options().HttpCacheMaxAge = 0
|
2023-08-15 11:06:43 +02:00
|
|
|
assert.Equal(t, ttl.Duration(2592000), c.HttpCacheMaxAge())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpVideoMaxAge(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, ttl.Video, c.HttpVideoMaxAge())
|
|
|
|
c.Options().HttpVideoMaxAge = 23
|
|
|
|
assert.Equal(t, ttl.Duration(23), c.HttpVideoMaxAge())
|
|
|
|
c.Options().HttpVideoMaxAge = 41536000
|
|
|
|
assert.Equal(t, ttl.Limit, c.HttpVideoMaxAge())
|
|
|
|
c.Options().HttpVideoMaxAge = 0
|
|
|
|
assert.Equal(t, ttl.Video, c.HttpVideoMaxAge())
|
2023-03-20 11:40:46 +01: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())
|
|
|
|
}
|