photoprism/internal/config/config_filepaths_test.go

335 lines
9.1 KiB
Go
Raw Normal View History

package config
import (
"strings"
2020-11-21 18:08:41 +01:00
"testing"
"github.com/photoprism/photoprism/pkg/rnd"
"github.com/stretchr/testify/assert"
)
func TestConfig_FindExecutable(t *testing.T) {
assert.Equal(t, "", findExecutable("yyy", "xxx"))
}
func TestConfig_SidecarPath(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Contains(t, c.SidecarPath(), "testdata/sidecar")
c.options.SidecarPath = ".photoprism"
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())
}
func TestConfig_SidecarPathIsAbs(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, true, c.SidecarPathIsAbs())
c.options.SidecarPath = ".photoprism"
assert.Equal(t, false, c.SidecarPathIsAbs())
}
func TestConfig_SidecarWritable(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, true, c.SidecarWritable())
}
func TestConfig_FFmpegBin(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "/usr/bin/ffmpeg", c.FFmpegBin())
}
func TestConfig_TempPath(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/temp", c.TempPath())
c.options.TempPath = ""
if dir := c.TempPath(); dir == "" {
t.Fatal("temp path is empty")
} else if !strings.HasPrefix(dir, "/tmp/photoprism") {
t.Fatalf("unexpected temp path: %s", dir)
}
}
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)
}
}
func TestConfig_CachePath2(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/cache", c.CachePath())
c.options.CachePath = ""
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/cache", c.CachePath())
}
func TestConfig_StoragePath(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata", c.StoragePath())
c.options.StoragePath = ""
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/originals/.photoprism/storage", c.StoragePath())
}
func TestConfig_TestdataPath(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/testdata", c.TestdataPath())
}
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())
}
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{
options: NewTestOptions("config"),
token: rnd.GenerateToken(8),
2021-08-24 19:09:09 +02:00
}
if err := c.CreateDirectories(); err != nil {
t.Fatal(err)
}
})
}
/* 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(),
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")
}
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(),
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")
}
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(),
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")
}
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(),
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")
}
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(),
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")
}
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(),
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")
}
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(),
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")
}
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(),
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")
}
assert.Contains(t, err2.Error(), "check config and permissions")
2021-08-24 19:09:09 +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())
c.options.PIDFilename = "/go/src/github.com/photoprism/photoprism/internal/config/testdata/test.pid"
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())
c.options.LogFilename = "/go/src/github.com/photoprism/photoprism/internal/config/testdata/test.log"
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())
c.options.OriginalsPath = ""
if s := c.OriginalsPath(); s != "" && s != "/photoprism/originals" {
t.Errorf("unexpected originals path: %s", s)
}
}
func TestConfig_ImportPath2(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/import", c.ImportPath())
c.options.ImportPath = ""
if s := c.ImportPath(); s != "" && s != "/photoprism/import" {
t.Errorf("unexpected import path: %s", s)
}
}
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 = ""
if s := c.AssetsPath(); s != "" && s != "/opt/photoprism/assets" {
t.Errorf("unexpected assets path: %s", s)
}
2021-02-18 14:39:08 +01:00
}
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")
}