2019-05-06 23:18:10 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2020-05-08 18:35:19 +02:00
|
|
|
"os"
|
2020-01-31 15:29:06 +01:00
|
|
|
"strings"
|
2019-05-06 23:18:10 +02:00
|
|
|
"testing"
|
2020-07-13 17:37:43 +02:00
|
|
|
"time"
|
2019-05-06 23:18:10 +02:00
|
|
|
|
2020-01-12 14:00:56 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/fs"
|
2020-05-08 18:35:19 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2019-05-06 23:18:10 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-08 18:35:19 +02:00
|
|
|
func TestMain(m *testing.M) {
|
2022-04-22 17:38:40 +02:00
|
|
|
_ = os.Setenv("PHOTOPRISM_TEST", "true")
|
2020-05-08 18:35:19 +02:00
|
|
|
log = logrus.StandardLogger()
|
2022-03-02 12:20:02 +01:00
|
|
|
log.SetLevel(logrus.TraceLevel)
|
2020-05-08 18:35:19 +02:00
|
|
|
|
|
|
|
c := TestConfig()
|
|
|
|
|
|
|
|
code := m.Run()
|
|
|
|
|
|
|
|
_ = c.CloseDb()
|
|
|
|
|
|
|
|
os.Exit(code)
|
|
|
|
}
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
func TestNewConfig(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
|
|
|
|
assert.True(t, ctx.IsSet("assets-path"))
|
|
|
|
assert.False(t, ctx.Bool("debug"))
|
|
|
|
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
assert.IsType(t, new(Config), c)
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
assert.Equal(t, fs.Abs("../../assets"), c.AssetsPath())
|
2022-08-31 18:53:04 +02:00
|
|
|
assert.False(t, c.Prod())
|
2019-05-06 23:18:10 +02:00
|
|
|
assert.False(t, c.Debug())
|
|
|
|
assert.False(t, c.ReadOnly())
|
|
|
|
}
|
2019-07-09 16:57:37 +02:00
|
|
|
|
2022-08-31 18:53:04 +02:00
|
|
|
func TestConfig_Prod(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.False(t, c.Prod())
|
|
|
|
assert.False(t, c.Debug())
|
|
|
|
assert.False(t, c.Trace())
|
|
|
|
c.options.Prod = true
|
|
|
|
c.options.Debug = true
|
|
|
|
assert.True(t, c.Prod())
|
|
|
|
assert.False(t, c.Debug())
|
|
|
|
assert.False(t, c.Trace())
|
|
|
|
c.options.Prod = false
|
|
|
|
assert.True(t, c.Debug())
|
|
|
|
assert.False(t, c.Trace())
|
|
|
|
c.options.Debug = false
|
|
|
|
assert.False(t, c.Debug())
|
|
|
|
assert.False(t, c.Debug())
|
|
|
|
assert.False(t, c.Trace())
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:57:37 +02:00
|
|
|
func TestConfig_Name(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 16:57:37 +02:00
|
|
|
|
|
|
|
name := c.Name()
|
2022-05-20 15:41:18 +02:00
|
|
|
assert.Equal(t, "PhotoPrism", name)
|
2019-07-09 16:57:37 +02:00
|
|
|
}
|
|
|
|
|
2022-05-20 19:27:33 +02:00
|
|
|
func TestConfig_Edition(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
name := c.Edition()
|
|
|
|
assert.Equal(t, "PhotoPrism® Dev", name)
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:57:37 +02:00
|
|
|
func TestConfig_Version(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 16:57:37 +02:00
|
|
|
|
|
|
|
version := c.Version()
|
2020-11-16 19:39:40 +01:00
|
|
|
assert.Equal(t, "0.0.0", version)
|
2019-07-09 16:57:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TensorFlowVersion(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 16:57:37 +02:00
|
|
|
|
|
|
|
version := c.TensorFlowVersion()
|
2020-04-22 10:33:47 +02:00
|
|
|
assert.IsType(t, "1.15.0", version)
|
2019-07-09 16:57:37 +02:00
|
|
|
}
|
|
|
|
|
2020-01-19 13:27:15 +01:00
|
|
|
func TestConfig_TensorFlowDisabled(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2020-01-19 13:27:15 +01:00
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
version := c.DisableTensorFlow()
|
2020-01-19 13:27:15 +01:00
|
|
|
assert.Equal(t, false, version)
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:57:37 +02:00
|
|
|
func TestConfig_Copyright(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 16:57:37 +02:00
|
|
|
|
|
|
|
copyright := c.Copyright()
|
|
|
|
assert.Equal(t, "", copyright)
|
|
|
|
}
|
|
|
|
|
2022-04-13 22:43:49 +02:00
|
|
|
func TestConfig_OptionsYaml(t *testing.T) {
|
|
|
|
t.Run("Default", func(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Contains(t, c.OptionsYaml(), "options.yml")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("ChangePath", func(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Contains(t, c.OptionsYaml(), "options.yml")
|
|
|
|
c.options.ConfigPath = "/go/src/github.com/photoprism/photoprism/internal/config/testdata/"
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/internal/config/testdata/options.yml", c.OptionsYaml())
|
|
|
|
})
|
2019-07-09 16:57:37 +02:00
|
|
|
}
|
|
|
|
|
2020-12-04 11:02:19 +01:00
|
|
|
func TestConfig_BackupPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Contains(t, c.BackupPath(), "/storage/testdata/backup")
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:57:37 +02:00
|
|
|
func TestConfig_PIDFilename(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 16:57:37 +02:00
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.Contains(t, c.PIDFilename(), "/storage/testdata/photoprism.pid")
|
2019-07-09 16:57:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_LogFilename(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 16:57:37 +02:00
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.Contains(t, c.LogFilename(), "/storage/testdata/photoprism.log")
|
2019-07-09 16:57:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_DetachServer(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 16:57:37 +02:00
|
|
|
|
|
|
|
detachServer := c.DetachServer()
|
|
|
|
assert.Equal(t, false, detachServer)
|
|
|
|
}
|
|
|
|
|
2019-07-09 17:43:34 +02:00
|
|
|
func TestConfig_HttpServerHost(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
host := c.HttpHost()
|
2019-07-09 17:43:34 +02:00
|
|
|
assert.Equal(t, "0.0.0.0", host)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpServerPort(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
port := c.HttpPort()
|
2019-07-10 09:10:02 +02:00
|
|
|
assert.Equal(t, 2342, port)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpServerMode(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
mode := c.HttpMode()
|
2019-07-09 17:43:34 +02:00
|
|
|
assert.Equal(t, "release", mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_OriginalsPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
result := c.OriginalsPath()
|
|
|
|
assert.True(t, strings.HasPrefix(result, "/"))
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.True(t, strings.HasSuffix(result, "/storage/testdata/originals"))
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ImportPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
result := c.ImportPath()
|
|
|
|
assert.True(t, strings.HasPrefix(result, "/"))
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.True(t, strings.HasSuffix(result, "/storage/testdata/import"))
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_CachePath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.True(t, strings.HasSuffix(c.CachePath(), "storage/testdata/cache"))
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ThumbnailsPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2022-04-18 13:55:17 +02:00
|
|
|
assert.True(t, strings.HasPrefix(c.ThumbCachePath(), "/"))
|
|
|
|
assert.True(t, strings.HasSuffix(c.ThumbCachePath(), "storage/testdata/cache/thumbnails"))
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_AssetsPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.True(t, strings.HasSuffix(c.AssetsPath(), "/assets"))
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
2022-07-05 23:13:34 +02:00
|
|
|
func TestConfig_CustomAssetsPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "", c.CustomAssetsPath())
|
|
|
|
}
|
|
|
|
|
2020-01-13 16:48:32 +01:00
|
|
|
func TestConfig_DetectNSFW(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-12-22 19:21:30 +01:00
|
|
|
|
2020-01-13 16:48:32 +01:00
|
|
|
result := c.DetectNSFW()
|
|
|
|
assert.Equal(t, true, result)
|
2019-12-22 19:21:30 +01:00
|
|
|
}
|
|
|
|
|
2022-09-02 21:30:50 +02:00
|
|
|
func TestConfig_AdminUser(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
c.options.AdminUser = "foo "
|
|
|
|
assert.Equal(t, "foo", c.AdminUser())
|
|
|
|
c.options.AdminUser = " Admin"
|
|
|
|
assert.Equal(t, "admin", c.AdminUser())
|
|
|
|
}
|
|
|
|
|
2019-12-22 19:21:30 +01:00
|
|
|
func TestConfig_AdminPassword(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-12-22 19:21:30 +01:00
|
|
|
|
2020-01-13 16:48:32 +01:00
|
|
|
result := c.AdminPassword()
|
|
|
|
assert.Equal(t, "photoprism", result)
|
2019-12-22 19:21:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_NSFWModelPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-12-22 19:21:30 +01:00
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.Contains(t, c.NSFWModelPath(), "/assets/nsfw")
|
2019-12-22 19:21:30 +01:00
|
|
|
}
|
|
|
|
|
2021-07-16 14:34:05 +02:00
|
|
|
func TestConfig_FaceNetModelPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Contains(t, c.FaceNetModelPath(), "/assets/facenet")
|
|
|
|
}
|
|
|
|
|
2019-07-09 17:43:34 +02:00
|
|
|
func TestConfig_ExamplesPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
|
|
|
path := c.ExamplesPath()
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/examples", path)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TensorFlowModelPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
|
|
|
path := c.TensorFlowModelPath()
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/nasnet", path)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
func TestConfig_TemplatesPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
path := c.TemplatesPath()
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/templates", path)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
2022-07-05 23:13:34 +02:00
|
|
|
func TestConfig_CustomTemplatesPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
path := c.CustomTemplatesPath()
|
|
|
|
assert.Equal(t, "", path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TemplatesFiles(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
files := c.TemplateFiles()
|
|
|
|
|
|
|
|
t.Logf("TemplateFiles: %#v", files)
|
|
|
|
}
|
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
func TestConfig_StaticPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
path := c.StaticPath()
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/static", path)
|
2022-06-24 06:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_StaticFile(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
path := c.StaticFile("video/404.mp4")
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/static/video/404.mp4", path)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
func TestConfig_BuildPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
path := c.BuildPath()
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/static/build", path)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
func TestConfig_ImgPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2019-07-09 17:43:34 +02:00
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
path := c.ImgPath()
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/static/img", path)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
2019-07-10 09:10:02 +02:00
|
|
|
|
|
|
|
func TestConfig_ClientConfig(t *testing.T) {
|
2020-01-06 02:14:17 +01:00
|
|
|
c := TestConfig()
|
2019-07-15 21:19:11 +02:00
|
|
|
|
2020-06-25 01:20:58 +02:00
|
|
|
cc := c.UserConfig()
|
2020-05-27 19:38:40 +02:00
|
|
|
|
|
|
|
assert.IsType(t, ClientConfig{}, cc)
|
2022-02-19 17:20:48 +01:00
|
|
|
|
|
|
|
if cc.JsUri == "" {
|
|
|
|
t.Error("the JavaScript asset URI must not be empty, make sure that the frontend has been built")
|
|
|
|
}
|
|
|
|
|
|
|
|
if cc.CssUri == "" {
|
|
|
|
t.Error("the CSS asset URI must not be empty, make sure that the frontend has been built")
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:38:40 +02:00
|
|
|
assert.NotEmpty(t, cc.Name)
|
|
|
|
assert.NotEmpty(t, cc.Version)
|
|
|
|
assert.NotEmpty(t, cc.Copyright)
|
2020-07-13 17:25:27 +02:00
|
|
|
assert.NotEmpty(t, cc.Thumbs)
|
2022-01-18 12:26:33 +01:00
|
|
|
assert.NotEmpty(t, cc.ManifestUri)
|
2020-05-27 19:38:40 +02:00
|
|
|
assert.Equal(t, true, cc.Debug)
|
2020-12-18 10:59:21 +01:00
|
|
|
assert.Equal(t, false, cc.Demo)
|
2021-11-12 05:09:17 +01:00
|
|
|
assert.Equal(t, true, cc.Sponsor)
|
2020-05-27 19:38:40 +02:00
|
|
|
assert.Equal(t, false, cc.ReadOnly)
|
2021-11-30 12:37:43 +01:00
|
|
|
|
|
|
|
// Counts.
|
|
|
|
assert.NotEmpty(t, cc.Count.All)
|
|
|
|
assert.NotEmpty(t, cc.Count.Photos)
|
|
|
|
assert.LessOrEqual(t, 20, cc.Count.Photos)
|
|
|
|
assert.LessOrEqual(t, 1, cc.Count.Live)
|
|
|
|
assert.LessOrEqual(t, 4, cc.Count.Videos)
|
|
|
|
assert.LessOrEqual(t, cc.Count.Photos+cc.Count.Live+cc.Count.Videos, cc.Count.All)
|
|
|
|
assert.LessOrEqual(t, 6, cc.Count.Cameras)
|
|
|
|
assert.LessOrEqual(t, 1, cc.Count.Lenses)
|
|
|
|
assert.LessOrEqual(t, 13, cc.Count.Review)
|
|
|
|
assert.LessOrEqual(t, 1, cc.Count.Private)
|
|
|
|
assert.LessOrEqual(t, 4, cc.Count.Albums)
|
2019-07-10 09:10:02 +02:00
|
|
|
}
|
|
|
|
|
2020-01-02 00:03:07 +01:00
|
|
|
func TestConfig_Workers(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2020-01-02 00:03:07 +01:00
|
|
|
|
|
|
|
assert.GreaterOrEqual(t, c.Workers(), 1)
|
|
|
|
}
|
2020-07-13 17:37:43 +02:00
|
|
|
|
|
|
|
func TestConfig_WakeupInterval(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2022-04-22 18:24:59 +02:00
|
|
|
i := c.WakeupInterval()
|
|
|
|
assert.Equal(t, "1h34m9s", c.WakeupInterval().String())
|
|
|
|
c.options.WakeupInterval = 45
|
|
|
|
assert.Equal(t, "1m0s", c.WakeupInterval().String())
|
|
|
|
c.options.WakeupInterval = 0
|
|
|
|
assert.Equal(t, "15m0s", c.WakeupInterval().String())
|
|
|
|
c.options.WakeupInterval = 150
|
|
|
|
assert.Equal(t, "2m30s", c.WakeupInterval().String())
|
|
|
|
c.options.WakeupInterval = i
|
2022-04-03 14:51:58 +02:00
|
|
|
assert.Equal(t, "1h34m9s", c.WakeupInterval().String())
|
2020-07-13 17:37:43 +02:00
|
|
|
}
|
|
|
|
|
2021-01-02 18:56:15 +01:00
|
|
|
func TestConfig_AutoIndex(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, time.Duration(0), c.AutoIndex())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_AutoImport(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, 2*time.Hour, c.AutoImport())
|
|
|
|
}
|
|
|
|
|
2020-12-05 00:13:44 +01:00
|
|
|
func TestConfig_GeoApi(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-12-05 00:13:44 +01:00
|
|
|
assert.Equal(t, "places", c.GeoApi())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.DisablePlaces = true
|
2020-12-18 09:11:42 +01:00
|
|
|
assert.Equal(t, "", c.GeoApi())
|
2020-07-13 17:37:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_OriginalsLimit(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2022-04-02 18:04:02 +02:00
|
|
|
assert.Equal(t, -1, c.OriginalsLimit())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.OriginalsLimit = 800
|
2022-04-02 18:04:02 +02:00
|
|
|
assert.Equal(t, 800, c.OriginalsLimit())
|
2022-04-01 21:14:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_OriginalsLimitBytes(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, int64(-1), c.OriginalsLimitBytes())
|
|
|
|
c.options.OriginalsLimit = 800
|
|
|
|
assert.Equal(t, int64(838860800), c.OriginalsLimitBytes())
|
|
|
|
}
|
|
|
|
|
2022-04-02 18:04:02 +02:00
|
|
|
func TestConfig_ResolutionLimit(t *testing.T) {
|
2022-04-01 21:14:22 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2022-04-02 18:04:02 +02:00
|
|
|
assert.Equal(t, -1, c.ResolutionLimit())
|
|
|
|
c.options.ResolutionLimit = 800
|
|
|
|
assert.Equal(t, 800, c.ResolutionLimit())
|
|
|
|
c.options.ResolutionLimit = 950
|
|
|
|
assert.Equal(t, 900, c.ResolutionLimit())
|
|
|
|
c.options.ResolutionLimit = 0
|
|
|
|
assert.Equal(t, -1, c.ResolutionLimit())
|
|
|
|
c.options.ResolutionLimit = -1
|
|
|
|
assert.Equal(t, -1, c.ResolutionLimit())
|
2022-07-05 23:13:34 +02:00
|
|
|
c.options.Sponsor = false
|
2022-09-18 14:06:13 +02:00
|
|
|
assert.Equal(t, 150, c.ResolutionLimit())
|
2022-07-05 23:13:34 +02:00
|
|
|
c.options.Sponsor = true
|
|
|
|
assert.Equal(t, -1, c.ResolutionLimit())
|
2020-07-13 19:25:27 +02:00
|
|
|
}
|
|
|
|
|
2021-07-05 16:41:43 +02:00
|
|
|
func TestConfig_BaseUri(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "", c.BaseUri(""))
|
|
|
|
c.options.SiteUrl = "http://superhost:2342/"
|
|
|
|
assert.Equal(t, "", c.BaseUri(""))
|
2022-01-17 18:52:35 +01:00
|
|
|
c.options.SiteUrl = "http://foo:2342/foo bar/"
|
|
|
|
assert.Equal(t, "/foo%20bar", c.BaseUri(""))
|
|
|
|
assert.Equal(t, "/foo%20bar/baz", c.BaseUri("/baz"))
|
2021-07-05 16:41:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_StaticUri(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "/static", c.StaticUri())
|
|
|
|
c.options.SiteUrl = "http://superhost:2342/"
|
|
|
|
assert.Equal(t, "/static", c.StaticUri())
|
|
|
|
c.options.SiteUrl = "http://foo:2342/foo/"
|
|
|
|
assert.Equal(t, "/foo/static", c.StaticUri())
|
|
|
|
c.options.CdnUrl = "http://foo:2342/bar"
|
|
|
|
assert.Equal(t, "http://foo:2342/bar/foo"+StaticUri, c.StaticUri())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ApiUri(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, ApiUri, c.ApiUri())
|
|
|
|
c.options.SiteUrl = "http://superhost:2342/"
|
|
|
|
assert.Equal(t, ApiUri, c.ApiUri())
|
|
|
|
c.options.SiteUrl = "http://foo:2342/foo/"
|
|
|
|
assert.Equal(t, "/foo"+ApiUri, c.ApiUri())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_CdnUrl(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "", c.CdnUrl(""))
|
|
|
|
c.options.SiteUrl = "http://superhost:2342/"
|
|
|
|
assert.Equal(t, "/", c.CdnUrl("/"))
|
|
|
|
c.options.CdnUrl = "http://foo:2342/foo/"
|
|
|
|
assert.Equal(t, "http://foo:2342/foo", c.CdnUrl(""))
|
|
|
|
assert.Equal(t, "http://foo:2342/foo/", c.CdnUrl("/"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ContentUri(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, ApiUri, c.ContentUri())
|
|
|
|
c.options.SiteUrl = "http://superhost:2342/"
|
|
|
|
assert.Equal(t, ApiUri, c.ContentUri())
|
|
|
|
c.options.CdnUrl = "http://foo:2342//"
|
|
|
|
assert.Equal(t, "http://foo:2342"+ApiUri, c.ContentUri())
|
|
|
|
}
|
|
|
|
|
2020-07-13 19:25:27 +02:00
|
|
|
func TestConfig_SiteUrl(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-07-13 19:25:27 +02:00
|
|
|
assert.Equal(t, "http://localhost:2342/", c.SiteUrl())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.SiteUrl = "http://superhost:2342/"
|
2020-07-13 19:25:27 +02:00
|
|
|
assert.Equal(t, "http://superhost:2342/", c.SiteUrl())
|
2021-07-05 16:41:43 +02:00
|
|
|
c.options.SiteUrl = "http://superhost"
|
|
|
|
assert.Equal(t, "http://superhost/", c.SiteUrl())
|
2020-07-13 19:25:27 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 15:47:30 +01:00
|
|
|
func TestConfig_SiteDomain(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "localhost", c.SiteDomain())
|
|
|
|
c.options.SiteUrl = "https://foo.bar.com:2342/"
|
|
|
|
assert.Equal(t, "foo.bar.com", c.SiteDomain())
|
|
|
|
c.options.SiteUrl = ""
|
|
|
|
assert.Equal(t, "localhost", c.SiteDomain())
|
|
|
|
}
|
|
|
|
|
2020-07-13 19:25:27 +02:00
|
|
|
func TestConfig_SitePreview(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2020-07-13 19:25:27 +02:00
|
|
|
assert.Equal(t, "http://localhost:2342/static/img/preview.jpg", c.SitePreview())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.SitePreview = "http://preview.jpg"
|
2020-07-13 19:25:27 +02:00
|
|
|
assert.Equal(t, "http://preview.jpg", c.SitePreview())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.SitePreview = "preview123.jpg"
|
2020-07-13 19:25:27 +02:00
|
|
|
assert.Equal(t, "http://localhost:2342/preview123.jpg", c.SitePreview())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_SiteTitle(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2022-05-20 15:41:18 +02:00
|
|
|
assert.Equal(t, "PhotoPrism", c.SiteTitle())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.SiteTitle = "Cats"
|
2020-07-13 19:25:27 +02:00
|
|
|
assert.Equal(t, "Cats", c.SiteTitle())
|
2020-07-13 17:37:43 +02:00
|
|
|
}
|
2021-01-02 15:08:39 +01:00
|
|
|
|
|
|
|
func TestConfig_Serial(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
result := c.Serial()
|
|
|
|
|
|
|
|
t.Logf("Serial: %s", result)
|
|
|
|
|
|
|
|
assert.NotEmpty(t, result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_SerialChecksum(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
result := c.SerialChecksum()
|
|
|
|
|
|
|
|
t.Logf("SerialChecksum: %s", result)
|
|
|
|
|
|
|
|
assert.NotEmpty(t, result)
|
|
|
|
}
|
2021-02-18 11:41:51 +01:00
|
|
|
|
2022-07-30 12:34:57 +02:00
|
|
|
func TestConfig_Public(t *testing.T) {
|
2021-02-18 11:41:51 +01:00
|
|
|
c := NewConfig(CliTestContext())
|
2022-07-30 12:34:57 +02:00
|
|
|
c.options.Demo = false
|
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "public"
|
|
|
|
assert.True(t, c.Public())
|
|
|
|
c.options.Demo = true
|
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "public"
|
|
|
|
assert.True(t, c.Public())
|
|
|
|
c.options.Demo = true
|
|
|
|
c.options.Public = true
|
|
|
|
c.options.AuthMode = "public"
|
|
|
|
assert.True(t, c.Public())
|
|
|
|
c.options.Demo = false
|
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "other"
|
|
|
|
assert.False(t, c.Public())
|
|
|
|
c.options.Demo = false
|
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "password"
|
|
|
|
assert.False(t, c.Public())
|
|
|
|
c.options.Demo = false
|
|
|
|
c.options.Public = true
|
|
|
|
c.options.AuthMode = "password"
|
|
|
|
assert.True(t, c.Public())
|
2021-02-18 11:41:51 +01:00
|
|
|
c.options.Demo = true
|
2022-07-30 12:34:57 +02:00
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "password"
|
2021-02-18 11:41:51 +01:00
|
|
|
assert.True(t, c.Public())
|
|
|
|
}
|
|
|
|
|
2022-07-30 12:34:57 +02:00
|
|
|
func TestConfig_Auth(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
c.options.Demo = false
|
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "public"
|
|
|
|
assert.False(t, c.Auth())
|
|
|
|
c.options.Demo = true
|
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "public"
|
|
|
|
assert.False(t, c.Auth())
|
|
|
|
c.options.Demo = true
|
|
|
|
c.options.Public = true
|
|
|
|
c.options.AuthMode = "public"
|
|
|
|
assert.False(t, c.Auth())
|
|
|
|
c.options.Demo = false
|
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "other"
|
|
|
|
assert.True(t, c.Auth())
|
|
|
|
c.options.Demo = false
|
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "password"
|
|
|
|
assert.True(t, c.Auth())
|
|
|
|
c.options.Demo = false
|
|
|
|
c.options.Public = true
|
|
|
|
c.options.AuthMode = "password"
|
|
|
|
assert.False(t, c.Auth())
|
|
|
|
c.options.Demo = true
|
|
|
|
c.options.Public = false
|
|
|
|
c.options.AuthMode = "password"
|
|
|
|
assert.False(t, c.Auth())
|
|
|
|
}
|
|
|
|
|
2021-02-18 11:41:51 +01:00
|
|
|
func TestConfigOptions(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
r := c.Options()
|
|
|
|
assert.False(t, r.DisableExifTool)
|
|
|
|
assert.Equal(t, r.AutoImport, 7200)
|
|
|
|
assert.Equal(t, r.AutoIndex, -1)
|
|
|
|
|
|
|
|
c.options = nil
|
|
|
|
r2 := c.Options()
|
|
|
|
assert.Equal(t, r2.AutoImport, 0)
|
|
|
|
assert.Equal(t, r2.AutoIndex, 0)
|
|
|
|
}
|