2020-07-13 18:05:10 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2022-04-18 13:55:17 +02:00
|
|
|
"strings"
|
2020-11-21 18:08:41 +01:00
|
|
|
"testing"
|
|
|
|
|
2020-07-13 18:05:10 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-10-11 22:44:11 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/rnd"
|
2020-07-13 18:05:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfig_FindExecutable(t *testing.T) {
|
2022-10-12 18:39:30 +02:00
|
|
|
assert.Equal(t, "", findBin("yyy", "xxx"))
|
2020-07-13 18:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_SidecarPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2020-12-11 19:17:07 +01:00
|
|
|
|
|
|
|
assert.Contains(t, c.SidecarPath(), "testdata/sidecar")
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.SidecarPath = ".photoprism"
|
2020-07-13 18:05:10 +02:00
|
|
|
assert.Equal(t, ".photoprism", c.SidecarPath())
|
2021-02-18 14:39:08 +01:00
|
|
|
c.options.SidecarPath = ""
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/sidecar", c.SidecarPath())
|
2020-07-13 18:05:10 +02:00
|
|
|
}
|
|
|
|
|
2022-10-17 19:07:38 +02:00
|
|
|
func TestConfig_UsersPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
2023-03-14 21:47:14 +01:00
|
|
|
assert.Contains(t, c.UsersPath(), "users")
|
2022-10-17 19:07:38 +02:00
|
|
|
}
|
|
|
|
|
2023-03-14 23:17:12 +01:00
|
|
|
func TestConfig_UsersOriginalsPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Contains(t, c.UsersOriginalsPath(), "users")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_UsersStoragePath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Contains(t, c.UsersStoragePath(), "users")
|
|
|
|
}
|
|
|
|
|
2023-03-14 21:47:14 +01:00
|
|
|
func TestConfig_UserStoragePath(t *testing.T) {
|
2022-10-17 19:07:38 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2023-03-14 21:47:14 +01:00
|
|
|
assert.Equal(t, "", c.UserStoragePath(""))
|
|
|
|
assert.Equal(t, "", c.UserStoragePath("etaetyget"))
|
|
|
|
assert.Contains(t, c.UserStoragePath("urjult03ceelhw6k"), "users/urjult03ceelhw6k")
|
2022-10-17 19:07:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_UserUploadPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
if dir, err := c.UserUploadPath("", ""); err == nil {
|
|
|
|
t.Error("error expected")
|
|
|
|
} else {
|
|
|
|
assert.Equal(t, "", dir)
|
|
|
|
}
|
|
|
|
if dir, err := c.UserUploadPath("etaetyget", ""); err == nil {
|
|
|
|
t.Error("error expected")
|
|
|
|
} else {
|
|
|
|
assert.Equal(t, "", dir)
|
|
|
|
}
|
|
|
|
if dir, err := c.UserUploadPath("urjult03ceelhw6k", ""); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
2023-03-14 21:47:14 +01:00
|
|
|
assert.Contains(t, dir, "users/urjult03ceelhw6k/upload")
|
2022-10-17 19:07:38 +02:00
|
|
|
}
|
|
|
|
if dir, err := c.UserUploadPath("urjult03ceelhw6k", "foo"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
2023-03-14 21:47:14 +01:00
|
|
|
assert.Contains(t, dir, "users/urjult03ceelhw6k/upload/foo")
|
2022-10-17 19:07:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 18:05:10 +02:00
|
|
|
func TestConfig_SidecarPathIsAbs(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-12-11 19:17:07 +01:00
|
|
|
assert.Equal(t, true, c.SidecarPathIsAbs())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.SidecarPath = ".photoprism"
|
2020-07-13 18:05:10 +02:00
|
|
|
assert.Equal(t, false, c.SidecarPathIsAbs())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_SidecarWritable(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-07-13 18:05:10 +02:00
|
|
|
assert.Equal(t, true, c.SidecarWritable())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_FFmpegBin(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2022-09-02 16:19:18 +02:00
|
|
|
|
|
|
|
assert.True(t, strings.Contains(c.FFmpegBin(), "/bin/ffmpeg"))
|
2020-07-13 18:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TempPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2022-07-19 20:41:36 +02:00
|
|
|
|
|
|
|
d0 := c.tempPath()
|
|
|
|
|
|
|
|
t.Logf("c.options.TempPath: '%s'", c.options.TempPath)
|
|
|
|
t.Logf("c.tempPath(): '%s'", d0)
|
|
|
|
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/temp", c.tempPath())
|
|
|
|
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.TempPath = ""
|
2022-04-18 13:55:17 +02:00
|
|
|
|
2022-07-19 20:41:36 +02:00
|
|
|
d1 := c.tempPath()
|
|
|
|
|
|
|
|
if d1 == "" {
|
2022-04-18 13:55:17 +02:00
|
|
|
t.Fatal("temp path is empty")
|
2022-07-19 20:41:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasPrefix(d1, "/tmp/photoprism_") {
|
|
|
|
t.Fatalf("unexpected temp path: %s", d1)
|
|
|
|
}
|
|
|
|
|
|
|
|
d2 := c.tempPath()
|
|
|
|
|
|
|
|
if d2 == "" {
|
|
|
|
t.Fatal("temp path is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasPrefix(d2, "/tmp/photoprism_") {
|
|
|
|
t.Fatalf("unexpected temp path: %s", d2)
|
|
|
|
}
|
|
|
|
|
|
|
|
if d1 != d2 {
|
|
|
|
t.Fatalf("temp paths should match: '%s' <=> '%s'", d1, d2)
|
|
|
|
} else {
|
|
|
|
t.Logf("temp paths match: '%s' == '%s'", d1, d2)
|
|
|
|
}
|
|
|
|
|
|
|
|
if d4 := c.TempPath(); d4 != d0 {
|
|
|
|
t.Fatalf("temp paths should match: '%s' <=> '%s'", d4, d0)
|
|
|
|
} else {
|
|
|
|
t.Logf("temp paths match: '%s' == '%s'", d4, d0)
|
2022-04-18 13:55:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_CmdCachePath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
if dir := c.CmdCachePath(); dir == "" {
|
|
|
|
t.Fatal("cmd cache path is empty")
|
|
|
|
} else if !strings.HasPrefix(dir, c.CachePath()) {
|
|
|
|
t.Fatalf("unexpected cmd cache path: %s", dir)
|
|
|
|
}
|
2020-07-13 18:05:10 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 18:51:28 +02:00
|
|
|
func TestConfig_CmdLibPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
if dir := c.CmdLibPath(); dir == "" {
|
|
|
|
t.Fatal("cmd lib path is empty")
|
|
|
|
} else if !strings.HasPrefix(dir, "/usr") {
|
|
|
|
t.Fatalf("unexpected cmd lib path: %s", dir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 09:18:24 +02:00
|
|
|
func TestConfig_CachePath2(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2020-07-14 09:18:24 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/cache", c.CachePath())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.CachePath = ""
|
2020-07-14 09:18:24 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/cache", c.CachePath())
|
|
|
|
}
|
2020-07-13 20:25:47 +02:00
|
|
|
|
2020-07-14 09:18:24 +02:00
|
|
|
func TestConfig_StoragePath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
2020-07-13 18:05:10 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata", c.StoragePath())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.StoragePath = ""
|
2020-07-14 09:18:24 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/originals/.photoprism/storage", c.StoragePath())
|
2020-07-13 18:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TestdataPath(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2020-07-13 18:05:10 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/testdata", c.TestdataPath())
|
|
|
|
}
|
2020-07-14 08:46:20 +02:00
|
|
|
|
2021-02-21 15:48:46 +01:00
|
|
|
func TestConfig_AlbumsPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/albums", c.AlbumsPath())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_OriginalsAlbumsPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/originals/albums", c.OriginalsAlbumsPath())
|
|
|
|
}
|
|
|
|
|
2020-07-14 08:46:20 +02:00
|
|
|
func TestConfig_CreateDirectories(t *testing.T) {
|
2021-08-24 19:09:09 +02:00
|
|
|
t.Run("no error", func(t *testing.T) {
|
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
|
|
|
|
c := &Config{
|
2022-03-31 17:55:40 +02:00
|
|
|
options: NewTestOptions("config"),
|
2022-04-15 09:42:07 +02:00
|
|
|
token: rnd.GenerateToken(8),
|
2021-08-24 19:09:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := c.CreateDirectories(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-07-14 08:46:20 +02:00
|
|
|
|
2021-08-29 16:32:22 +02:00
|
|
|
/* TODO Doesn't fail on https://drone.photoprism.app/!
|
|
|
|
--- FAIL: TestConfig_CreateDirectories2 (0.00s)
|
|
|
|
--- FAIL: TestConfig_CreateDirectories2/asset_path_not_found (0.00s)
|
|
|
|
fs_test.go:142: error expected
|
|
|
|
|
2021-08-24 19:09:09 +02:00
|
|
|
func TestConfig_CreateDirectories2(t *testing.T) {
|
|
|
|
t.Run("asset path not found", func(t *testing.T) {
|
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
c := &Config{
|
|
|
|
options: NewTestOptions(),
|
2022-04-15 09:42:07 +02:00
|
|
|
token: rnd.GenerateToken(8),
|
2021-08-24 19:09:09 +02:00
|
|
|
}
|
|
|
|
c.options.AssetsPath = ""
|
|
|
|
|
|
|
|
err := c.CreateDirectories()
|
2021-08-25 13:41:51 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2021-08-24 19:09:09 +02:00
|
|
|
assert.Contains(t, err.Error(), "assets path not found")
|
2021-08-25 13:41:51 +02:00
|
|
|
|
|
|
|
c.options.AssetsPath = "/-*&^%$#@!`~"
|
|
|
|
err2 := c.CreateDirectories()
|
|
|
|
|
|
|
|
if err2 == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2022-03-02 12:20:02 +01:00
|
|
|
assert.Contains(t, err2.Error(), "check config and permissions")
|
2021-08-24 19:09:09 +02:00
|
|
|
})
|
2021-08-26 18:02:53 +02:00
|
|
|
|
2021-08-25 13:41:51 +02:00
|
|
|
t.Run("storage path error", func(t *testing.T) {
|
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
c := &Config{
|
|
|
|
options: NewTestOptions(),
|
2022-04-15 09:42:07 +02:00
|
|
|
token: rnd.GenerateToken(8),
|
2021-08-25 13:41:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
c.options.StoragePath = "/-*&^%$#@!`~"
|
|
|
|
err2 := c.CreateDirectories()
|
|
|
|
|
|
|
|
if err2 == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2022-03-02 12:20:02 +01:00
|
|
|
assert.Contains(t, err2.Error(), "check config and permissions")
|
2021-08-25 13:41:51 +02:00
|
|
|
})
|
2021-08-26 18:02:53 +02:00
|
|
|
|
2021-08-25 13:41:51 +02:00
|
|
|
t.Run("originals path not found", func(t *testing.T) {
|
2021-08-24 19:09:09 +02:00
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
c := &Config{
|
|
|
|
options: NewTestOptions(),
|
2022-04-15 09:42:07 +02:00
|
|
|
token: rnd.GenerateToken(8),
|
2021-08-24 19:09:09 +02:00
|
|
|
}
|
|
|
|
c.options.OriginalsPath = ""
|
|
|
|
|
|
|
|
err := c.CreateDirectories()
|
2021-08-25 13:41:51 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
|
|
|
|
2021-08-24 19:09:09 +02:00
|
|
|
assert.Contains(t, err.Error(), "originals path not found")
|
2021-08-25 13:41:51 +02:00
|
|
|
|
|
|
|
c.options.OriginalsPath = "/-*&^%$#@!`~"
|
|
|
|
err2 := c.CreateDirectories()
|
|
|
|
|
|
|
|
if err2 == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2022-03-02 12:20:02 +01:00
|
|
|
assert.Contains(t, err2.Error(), "check config and permissions")
|
2021-08-25 13:41:51 +02:00
|
|
|
})
|
2021-08-26 18:02:53 +02:00
|
|
|
|
2021-08-25 13:41:51 +02:00
|
|
|
t.Run("import path not found", func(t *testing.T) {
|
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
c := &Config{
|
|
|
|
options: NewTestOptions(),
|
2022-04-15 09:42:07 +02:00
|
|
|
token: rnd.GenerateToken(8),
|
2021-08-25 13:41:51 +02:00
|
|
|
}
|
|
|
|
c.options.ImportPath = ""
|
|
|
|
|
|
|
|
err := c.CreateDirectories()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Contains(t, err.Error(), "import path not found")
|
|
|
|
|
|
|
|
c.options.ImportPath = "/-*&^%$#@!`~"
|
|
|
|
err2 := c.CreateDirectories()
|
|
|
|
|
|
|
|
if err2 == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2022-03-02 12:20:02 +01:00
|
|
|
assert.Contains(t, err2.Error(), "check config and permissions")
|
2021-08-25 13:41:51 +02:00
|
|
|
})
|
2021-08-26 18:02:53 +02:00
|
|
|
|
2021-08-25 13:41:51 +02:00
|
|
|
t.Run("sidecar path error", func(t *testing.T) {
|
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
c := &Config{
|
|
|
|
options: NewTestOptions(),
|
2022-04-15 09:42:07 +02:00
|
|
|
token: rnd.GenerateToken(8),
|
2021-08-25 13:41:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
c.options.SidecarPath = "/-*&^%$#@!`~"
|
|
|
|
err2 := c.CreateDirectories()
|
|
|
|
|
|
|
|
if err2 == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2022-03-02 12:20:02 +01:00
|
|
|
assert.Contains(t, err2.Error(), "check config and permissions")
|
2021-08-25 13:41:51 +02:00
|
|
|
})
|
2021-08-26 18:02:53 +02:00
|
|
|
|
2021-08-25 13:41:51 +02:00
|
|
|
t.Run("cache path error", func(t *testing.T) {
|
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
c := &Config{
|
|
|
|
options: NewTestOptions(),
|
2022-04-15 09:42:07 +02:00
|
|
|
token: rnd.GenerateToken(8),
|
2021-08-25 13:41:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
c.options.CachePath = "/-*&^%$#@!`~"
|
|
|
|
err2 := c.CreateDirectories()
|
|
|
|
|
|
|
|
if err2 == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2022-03-02 12:20:02 +01:00
|
|
|
assert.Contains(t, err2.Error(), "check config and permissions")
|
2021-08-25 13:41:51 +02:00
|
|
|
})
|
2021-08-26 18:02:53 +02:00
|
|
|
|
2021-08-25 13:41:51 +02:00
|
|
|
t.Run("config path error", func(t *testing.T) {
|
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
c := &Config{
|
|
|
|
options: NewTestOptions(),
|
2022-04-15 09:42:07 +02:00
|
|
|
token: rnd.GenerateToken(8),
|
2021-08-25 13:41:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
c.options.ConfigPath = "/-*&^%$#@!`~"
|
|
|
|
err2 := c.CreateDirectories()
|
|
|
|
|
|
|
|
if err2 == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2022-03-02 12:20:02 +01:00
|
|
|
assert.Contains(t, err2.Error(), "check config and permissions")
|
2021-08-25 13:41:51 +02:00
|
|
|
})
|
2021-08-26 18:02:53 +02:00
|
|
|
|
2021-08-25 13:41:51 +02:00
|
|
|
t.Run("temp path error", func(t *testing.T) {
|
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
c := &Config{
|
|
|
|
options: NewTestOptions(),
|
2022-04-15 09:42:07 +02:00
|
|
|
token: rnd.GenerateToken(8),
|
2021-08-25 13:41:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
c.options.TempPath = "/-*&^%$#@!`~"
|
|
|
|
err2 := c.CreateDirectories()
|
|
|
|
|
|
|
|
if err2 == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2022-03-02 12:20:02 +01:00
|
|
|
assert.Contains(t, err2.Error(), "check config and permissions")
|
2021-08-24 19:09:09 +02:00
|
|
|
})
|
2020-07-14 08:46:20 +02:00
|
|
|
}
|
2021-08-29 16:32:22 +02:00
|
|
|
*/
|
2020-07-14 08:46:20 +02:00
|
|
|
|
2020-07-14 09:18:24 +02:00
|
|
|
func TestConfig_PIDFilename2(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/photoprism.pid", c.PIDFilename())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.PIDFilename = "/go/src/github.com/photoprism/photoprism/internal/config/testdata/test.pid"
|
2020-07-14 09:18:24 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/internal/config/testdata/test.pid", c.PIDFilename())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_LogFilename2(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/photoprism.log", c.LogFilename())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.LogFilename = "/go/src/github.com/photoprism/photoprism/internal/config/testdata/test.log"
|
2020-07-14 09:18:24 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/internal/config/testdata/test.log", c.LogFilename())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_OriginalsPath2(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/originals", c.OriginalsPath())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.OriginalsPath = ""
|
2022-02-19 17:12:39 +01:00
|
|
|
if s := c.OriginalsPath(); s != "" && s != "/photoprism/originals" {
|
|
|
|
t.Errorf("unexpected originals path: %s", s)
|
|
|
|
}
|
2020-07-14 09:18:24 +02:00
|
|
|
}
|
|
|
|
|
2022-07-21 20:23:00 +02:00
|
|
|
func TestConfig_OriginalsDeletable(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
c.Settings().Features.Delete = true
|
|
|
|
c.options.ReadOnly = false
|
|
|
|
|
|
|
|
assert.True(t, c.OriginalsDeletable())
|
|
|
|
}
|
|
|
|
|
2020-07-14 09:18:24 +02:00
|
|
|
func TestConfig_ImportPath2(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/import", c.ImportPath())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.ImportPath = ""
|
2022-02-19 17:12:39 +01:00
|
|
|
if s := c.ImportPath(); s != "" && s != "/photoprism/import" {
|
|
|
|
t.Errorf("unexpected import path: %s", s)
|
|
|
|
}
|
2020-07-14 08:46:20 +02:00
|
|
|
}
|
2021-02-18 14:39:08 +01:00
|
|
|
|
|
|
|
func TestConfig_AssetsPath2(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets", c.AssetsPath())
|
|
|
|
c.options.AssetsPath = ""
|
2022-02-19 17:12:39 +01:00
|
|
|
if s := c.AssetsPath(); s != "" && s != "/opt/photoprism/assets" {
|
|
|
|
t.Errorf("unexpected assets path: %s", s)
|
|
|
|
}
|
2021-02-18 14:39:08 +01:00
|
|
|
}
|
|
|
|
|
2023-06-02 17:07:10 +02:00
|
|
|
func TestConfig_MariadbBin(t *testing.T) {
|
2021-02-18 14:39:08 +01:00
|
|
|
c := NewConfig(CliTestContext())
|
2023-06-02 17:07:10 +02:00
|
|
|
assert.Contains(t, c.MariadbBin(), "mariadb")
|
2021-02-18 14:39:08 +01:00
|
|
|
}
|
|
|
|
|
2023-06-02 17:07:10 +02:00
|
|
|
func TestConfig_MariadbDumpBin(t *testing.T) {
|
2021-02-18 14:39:08 +01:00
|
|
|
c := NewConfig(CliTestContext())
|
2023-06-02 17:07:10 +02:00
|
|
|
assert.Contains(t, c.MariadbDumpBin(), "mariadb-dump")
|
2021-02-18 14:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_SqliteBin(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Contains(t, c.SqliteBin(), "sqlite")
|
|
|
|
}
|
2023-01-30 14:56:31 +01:00
|
|
|
|
|
|
|
func TestConfig_SettingsYamlDefaults(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
name1 := c.SettingsYamlDefaults(c.SettingsYaml())
|
|
|
|
t.Logf("(1) DefaultsYaml: %s", c.DefaultsYaml())
|
|
|
|
t.Logf("(1) SettingsYaml: %s", c.SettingsYaml())
|
|
|
|
t.Logf("(1) SettingsYamlDefaults: %s", name1)
|
|
|
|
assert.Equal(t, c.SettingsYaml(), name1)
|
|
|
|
c.options.ConfigPath = "/tmp/012345678ABC"
|
|
|
|
c.options.DefaultsYaml = "testdata/etc/defaults.yml"
|
|
|
|
name2 := c.SettingsYamlDefaults("")
|
|
|
|
t.Logf("(2) DefaultsYaml: %s", c.DefaultsYaml())
|
|
|
|
t.Logf("(2) SettingsYaml: %s", c.SettingsYaml())
|
|
|
|
t.Logf("(2) SettingsYamlDefaults: %s", name2)
|
|
|
|
assert.True(t, strings.HasSuffix(name2, "testdata/etc/settings.yml"))
|
|
|
|
name3 := c.SettingsYamlDefaults(c.SettingsYaml())
|
|
|
|
t.Logf("(3) DefaultsYaml: %s", c.DefaultsYaml())
|
|
|
|
t.Logf("(3) SettingsYaml: %s", c.SettingsYaml())
|
|
|
|
t.Logf("(3) SettingsYamlDefaults: %s", name3)
|
|
|
|
assert.True(t, strings.HasSuffix(name3, "testdata/etc/settings.yml"))
|
|
|
|
assert.NotEqual(t, c.SettingsYaml(), name1)
|
|
|
|
assert.NotEqual(t, c.SettingsYaml(), name3)
|
|
|
|
}
|