2020-07-13 18:05:10 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2020-11-21 18:08:41 +01:00
|
|
|
"testing"
|
|
|
|
|
2020-10-09 11:35:05 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/rnd"
|
2020-07-13 18:05:10 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfig_FindExecutable(t *testing.T) {
|
|
|
|
assert.Equal(t, "", findExecutable("yyy", "xxx"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_SidecarJson(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2020-12-18 09:11:42 +01:00
|
|
|
|
|
|
|
assert.Equal(t, true, c.ExifToolJson())
|
|
|
|
assert.Equal(t, c.DisableExifTool(), !c.ExifToolJson())
|
|
|
|
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.DisableExifTool = true
|
2020-12-18 09:11:42 +01:00
|
|
|
|
|
|
|
assert.Equal(t, false, c.ExifToolJson())
|
|
|
|
assert.Equal(t, c.DisableExifTool(), !c.ExifToolJson())
|
2020-07-13 18:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_SidecarYaml(t *testing.T) {
|
2020-07-13 20:25:47 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2020-12-11 19:17:07 +01:00
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
assert.Equal(t, true, c.BackupYaml())
|
|
|
|
assert.Equal(t, c.DisableBackups(), !c.BackupYaml())
|
|
|
|
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.DisableBackups = true
|
2020-12-18 09:11:42 +01:00
|
|
|
|
|
|
|
assert.Equal(t, false, c.BackupYaml())
|
|
|
|
assert.Equal(t, c.DisableBackups(), !c.BackupYaml())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
2020-07-13 18:05:10 +02:00
|
|
|
assert.Equal(t, "/usr/bin/ffmpeg", c.FFmpegBin())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TempPath(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/temp", c.TempPath())
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.TempPath = ""
|
2020-07-14 09:18:24 +02:00
|
|
|
assert.Equal(t, "/tmp/photoprism", c.TempPath())
|
2020-07-13 18:05:10 +02:00
|
|
|
}
|
|
|
|
|
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) {
|
2020-10-09 11:35:05 +02:00
|
|
|
testConfigMutex.Lock()
|
|
|
|
defer testConfigMutex.Unlock()
|
|
|
|
|
|
|
|
c := &Config{
|
2020-12-18 20:42:12 +01:00
|
|
|
options: NewTestOptions(),
|
|
|
|
token: rnd.Token(8),
|
2020-10-09 11:35:05 +02:00
|
|
|
}
|
2020-07-14 08:46:20 +02:00
|
|
|
|
2020-10-09 11:35:05 +02:00
|
|
|
if err := c.CreateDirectories(); err != nil {
|
2020-07-14 08:46:20 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ConfigFile2(t *testing.T) {
|
2020-07-14 09:18:24 +02:00
|
|
|
c := NewConfig(CliTestContext())
|
2021-02-22 11:07:00 +01:00
|
|
|
assert.Contains(t, c.ConfigFile(), "options.yml")
|
2020-12-18 20:42:12 +01:00
|
|
|
c.options.ConfigFile = "/go/src/github.com/photoprism/photoprism/internal/config/testdata/config.yml"
|
2020-07-14 09:18:24 +02:00
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/internal/config/testdata/config.yml", c.ConfigFile())
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = ""
|
2020-07-14 09:18:24 +02:00
|
|
|
assert.Equal(t, "", c.OriginalsPath())
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = ""
|
2020-07-14 09:18:24 +02:00
|
|
|
assert.Equal(t, "", c.ImportPath())
|
2020-07-14 08:46:20 +02:00
|
|
|
}
|
2021-02-18 14:39:08 +01:00
|
|
|
|
2021-02-22 11:07:00 +01:00
|
|
|
/*func TestConfig_ConfigPath(t *testing.T) {
|
2021-02-18 14:39:08 +01:00
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/config", c.ConfigPath())
|
|
|
|
c.options.ConfigPath = ""
|
|
|
|
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/config", c.ConfigPath())
|
2021-02-22 11:07:00 +01: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 = ""
|
|
|
|
assert.Equal(t, "", c.AssetsPath())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_MysqlBin(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Contains(t, c.MysqlBin(), "mysql")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_MysqldumpBin(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Contains(t, c.MysqldumpBin(), "mysqldump")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_SqliteBin(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Contains(t, c.SqliteBin(), "sqlite")
|
|
|
|
}
|