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-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) {
|
|
|
|
log = logrus.StandardLogger()
|
|
|
|
log.SetLevel(logrus.DebugLevel)
|
|
|
|
|
|
|
|
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())
|
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
|
|
|
|
|
|
|
func TestConfig_Name(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
name := c.Name()
|
|
|
|
assert.Equal(t, "config.test", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_Version(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
version := c.Version()
|
2020-04-28 18:20:33 +02:00
|
|
|
assert.Equal(t, "test", version)
|
2019-07-09 16:57:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TensorFlowVersion(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
version := c.TensorFlowOff()
|
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) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
copyright := c.Copyright()
|
|
|
|
assert.Equal(t, "", copyright)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ConfigFile(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.Contains(t, c.ConfigFile(), "/storage/testdata/settings/photoprism.yml")
|
2019-07-09 16:57:37 +02:00
|
|
|
}
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
func TestConfig_SettingsPath(t *testing.T) {
|
2019-07-09 16:57:37 +02:00
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.Contains(t, c.SettingsPath(), "/storage/testdata/settings")
|
2019-07-09 16:57:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_PIDFilename(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
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) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
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) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
detachServer := c.DetachServer()
|
|
|
|
assert.Equal(t, false, detachServer)
|
|
|
|
}
|
|
|
|
|
2019-07-09 17:43:34 +02:00
|
|
|
func TestConfig_HttpServerHost(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
host := c.HttpServerHost()
|
|
|
|
assert.Equal(t, "0.0.0.0", host)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpServerPort(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
port := c.HttpServerPort()
|
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) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
mode := c.HttpServerMode()
|
|
|
|
assert.Equal(t, "release", mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpServerPassword(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
password := c.HttpServerPassword()
|
|
|
|
assert.Equal(t, "", password)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_OriginalsPath(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
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) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
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_SipsBin(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
bin := c.SipsBin()
|
|
|
|
assert.Equal(t, "", bin)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_DarktableBin(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
bin := c.DarktableBin()
|
|
|
|
assert.Equal(t, "/usr/bin/darktable-cli", bin)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HeifConvertBin(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
bin := c.HeifConvertBin()
|
|
|
|
assert.Equal(t, "/usr/bin/heif-convert", bin)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ExifToolBin(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
bin := c.ExifToolBin()
|
|
|
|
assert.Equal(t, "/usr/bin/exiftool", bin)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_DatabaseDriver(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
driver := c.DatabaseDriver()
|
2020-05-30 14:52:47 +02:00
|
|
|
assert.Equal(t, SQLite, driver)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_DatabaseDsn(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
dsn := c.DatabaseDriver()
|
2020-05-30 14:52:47 +02:00
|
|
|
assert.Equal(t, SQLite, dsn)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_CachePath(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
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) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-05-05 17:04:13 +02:00
|
|
|
assert.True(t, strings.HasPrefix(c.ThumbPath(), "/"))
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.True(t, strings.HasSuffix(c.ThumbPath(), "storage/testdata/cache/thumbnails"))
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_AssetsPath(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.True(t, strings.HasSuffix(c.AssetsPath(), "/assets"))
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
2020-01-13 16:48:32 +01:00
|
|
|
func TestConfig_DetectNSFW(t *testing.T) {
|
2019-12-22 19:21:30 +01:00
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-01-13 16:48:32 +01:00
|
|
|
result := c.DetectNSFW()
|
|
|
|
assert.Equal(t, true, result)
|
2019-12-22 19:21:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_AdminPassword(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
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) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
assert.Contains(t, c.NSFWModelPath(), "/assets/nsfw")
|
2019-12-22 19:21:30 +01:00
|
|
|
}
|
|
|
|
|
2019-07-09 17:43:34 +02:00
|
|
|
func TestConfig_ExamplesPath(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpTemplatesPath(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpFaviconsPath(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
path := c.FaviconsPath()
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/static/favicons", path)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpStaticPath(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
path := c.StaticPath()
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/static", path)
|
2019-07-09 17:43:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_HttpStaticBuildPath(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
path := c.StaticBuildPath()
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/static/build", 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
|
|
|
|
|
|
|
cc := c.ClientConfig()
|
2020-05-27 19:38:40 +02:00
|
|
|
|
|
|
|
assert.IsType(t, ClientConfig{}, cc)
|
|
|
|
assert.NotEmpty(t, cc.Name)
|
|
|
|
assert.NotEmpty(t, cc.Version)
|
|
|
|
assert.NotEmpty(t, cc.Copyright)
|
|
|
|
assert.NotEmpty(t, cc.Thumbnails)
|
|
|
|
assert.NotEmpty(t, cc.JSHash)
|
|
|
|
assert.NotEmpty(t, cc.CSSHash)
|
|
|
|
assert.Equal(t, true, cc.Debug)
|
|
|
|
assert.Equal(t, false, cc.ReadOnly)
|
2019-07-10 09:10:02 +02:00
|
|
|
}
|
|
|
|
|
2020-01-02 00:03:07 +01:00
|
|
|
func TestConfig_Workers(t *testing.T) {
|
|
|
|
ctx := CliTestContext()
|
|
|
|
c := NewConfig(ctx)
|
|
|
|
|
|
|
|
assert.GreaterOrEqual(t, c.Workers(), 1)
|
|
|
|
}
|