mirror of
https://github.com/photoprism/photoprism.git
synced 2026-01-23 02:24:24 +00:00
Backend: move internal/functions to pkg
This commit is contained in:
parent
00cc10e252
commit
b181ff2e5c
61 changed files with 248 additions and 200 deletions
|
|
@ -7,12 +7,12 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
func TestOptions(t *testing.T) {
|
||||
var configPath = fs.Abs("testdata/" + functions.PhotoPrismTestToFolderName())
|
||||
var configPath = fs.Abs("testdata/" + dsn.PhotoPrismTestToFolderName())
|
||||
_ = os.Mkdir(configPath, os.ModePerm)
|
||||
var configFile = filepath.Join(configPath, "vision.yml")
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ import (
|
|||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/form"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/server/limiter"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
"github.com/photoprism/photoprism/pkg/service/http/header"
|
||||
)
|
||||
|
|
@ -40,8 +40,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
// Init test config.
|
||||
c := config.TestConfig()
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -27,8 +27,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
c := config.TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ import (
|
|||
"github.com/urfave/cli/v2"
|
||||
|
||||
cfg "github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/service/cluster"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestClusterRegister_HTTPHappyPath(t *testing.T) {
|
||||
|
|
@ -49,8 +49,8 @@ func TestClusterRegister_HTTPHappyPath(t *testing.T) {
|
|||
assert.Equal(t, "pp-node-02", gjson.Get(out, "node.name").String())
|
||||
assert.Equal(t, cluster.ExampleClientSecret, gjson.Get(out, "secrets.clientSecret").String())
|
||||
assert.Equal(t, "pwd", gjson.Get(out, "database.password").String())
|
||||
dsn := gjson.Get(out, "database.dsn").String()
|
||||
parsed := functions.NewDSN(dsn)
|
||||
dsname := gjson.Get(out, "database.dsn").String()
|
||||
parsed := dsn.NewDSN(dsname)
|
||||
assert.Equal(t, "user", parsed.User)
|
||||
assert.Equal(t, "pwd", parsed.Password)
|
||||
assert.Equal(t, "tcp", parsed.Net)
|
||||
|
|
@ -134,8 +134,8 @@ func TestClusterNodesRotate_HTTPJson(t *testing.T) {
|
|||
assert.Equal(t, "pp-node-04", gjson.Get(out, "node.name").String())
|
||||
assert.Equal(t, secret, gjson.Get(out, "secrets.clientSecret").String())
|
||||
assert.Equal(t, "pwd3", gjson.Get(out, "database.password").String())
|
||||
dsn := gjson.Get(out, "database.dsn").String()
|
||||
parsed := functions.NewDSN(dsn)
|
||||
dsname := gjson.Get(out, "database.dsn").String()
|
||||
parsed := dsn.NewDSN(dsname)
|
||||
assert.Equal(t, "user", parsed.User)
|
||||
assert.Equal(t, "pwd3", parsed.Password)
|
||||
assert.Equal(t, "tcp", parsed.Net)
|
||||
|
|
@ -186,8 +186,8 @@ func TestClusterNodesRotate_DBOnly_JSON(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, "pp-node-05", gjson.Get(out, "node.name").String())
|
||||
assert.Equal(t, "pwd4", gjson.Get(out, "database.password").String())
|
||||
dsn := gjson.Get(out, "database.dsn").String()
|
||||
parsed := functions.NewDSN(dsn)
|
||||
dsname := gjson.Get(out, "database.dsn").String()
|
||||
parsed := dsn.NewDSN(dsname)
|
||||
assert.Equal(t, "pp_user", parsed.User)
|
||||
assert.Equal(t, "pwd4", parsed.Password)
|
||||
assert.Equal(t, "tcp", parsed.Net)
|
||||
|
|
@ -448,8 +448,8 @@ func TestClusterRegister_RotateDatabase_JSON(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, "pp-node-07", gjson.Get(out, "node.name").String())
|
||||
assert.Equal(t, "pwd7", gjson.Get(out, "database.password").String())
|
||||
dsn := gjson.Get(out, "database.dsn").String()
|
||||
parsed := functions.NewDSN(dsn)
|
||||
dsname := gjson.Get(out, "database.dsn").String()
|
||||
parsed := dsn.NewDSN(dsname)
|
||||
assert.Equal(t, "pp_user", parsed.User)
|
||||
assert.Equal(t, "pwd7", parsed.Password)
|
||||
assert.Equal(t, "tcp", parsed.Net)
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ import (
|
|||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -46,8 +46,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "commands-test")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestMigrationCommand(t *testing.T) {
|
||||
|
|
@ -64,7 +64,7 @@ func TestMigrationCommand(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("RunTraceAndFailed", func(t *testing.T) {
|
||||
dbDrv, dbDSN := functions.PhotoPrismTestToDriverDsn(0)
|
||||
dbDrv, dbDSN := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
// Run command with test context.
|
||||
appArgs := []string{"photoprism",
|
||||
"--database-driver", dbDrv,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestResetCommand(t *testing.T) {
|
||||
|
|
@ -24,7 +24,7 @@ func TestResetCommand(t *testing.T) {
|
|||
}
|
||||
assert.Greater(t, count, int64(0))
|
||||
|
||||
dbDrv, dbDSN := functions.PhotoPrismTestToDriverDsn(0)
|
||||
dbDrv, dbDSN := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
// Run command with test context.
|
||||
appArgs := []string{"photoprism",
|
||||
"--database-driver", dbDrv,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestUsersResetCommand(t *testing.T) {
|
||||
|
|
@ -52,7 +52,7 @@ func TestUsersResetCommand(t *testing.T) {
|
|||
}
|
||||
assert.Greater(t, count, int64(3)) // Make sure we have a populated database
|
||||
|
||||
dbDrv, dbDSN := functions.PhotoPrismTestToDriverDsn(0)
|
||||
dbDrv, dbDSN := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
// Run command with test context.
|
||||
appArgs := []string{"photoprism",
|
||||
"--database-driver", dbDrv,
|
||||
|
|
|
|||
|
|
@ -5,18 +5,18 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestConfig_BackupPath(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
expected := "/storage/testdata/" + functions.PhotoPrismTestToFolderName() + "/backup"
|
||||
expected := "/storage/testdata/" + dsn.PhotoPrismTestToFolderName() + "/backup"
|
||||
assert.Contains(t, c.BackupPath(""), expected)
|
||||
}
|
||||
|
||||
func TestConfig_BackupBasePath(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
expected := "/storage/testdata/" + functions.PhotoPrismTestToFolderName() + "/backup"
|
||||
expected := "/storage/testdata/" + dsn.PhotoPrismTestToFolderName() + "/backup"
|
||||
assert.Contains(t, c.BackupBasePath(), expected)
|
||||
path := c.options.BackupPath
|
||||
c.options.BackupPath = "./"
|
||||
|
|
@ -63,7 +63,7 @@ func TestConfig_BackupDatabasePath(t *testing.T) {
|
|||
// Ensure DB defaults (SQLite) so path resolves to sqlite backup path
|
||||
c.options.DatabaseDriver = ""
|
||||
c.options.DatabaseDSN = ""
|
||||
expected := "/storage/testdata/" + functions.PhotoPrismTestToFolderName() + "/backup/sqlite"
|
||||
expected := "/storage/testdata/" + dsn.PhotoPrismTestToFolderName() + "/backup/sqlite"
|
||||
assert.Contains(t, c.BackupDatabasePath(), expected)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/entity/migrate"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/mutex"
|
||||
"github.com/photoprism/photoprism/pkg/clean"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
// SQL Databases.
|
||||
|
|
@ -169,7 +169,7 @@ func (c *Config) ParseDatabaseDSN() {
|
|||
return
|
||||
}
|
||||
|
||||
d := functions.NewDSN(c.options.DatabaseDSN)
|
||||
d := dsn.NewDSN(c.options.DatabaseDSN)
|
||||
|
||||
c.options.DatabaseName = d.Name
|
||||
c.options.DatabaseServer = d.Server
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestConfig_DatabaseDriver(t *testing.T) {
|
||||
|
|
@ -120,7 +120,7 @@ func TestConfig_DatabaseName(t *testing.T) {
|
|||
c := NewConfig(CliTestContext())
|
||||
c.options.DatabaseDriver = ""
|
||||
c.options.DatabaseDSN = ""
|
||||
expected := "/go/src/github.com/photoprism/photoprism/storage/testdata/" + functions.PhotoPrismTestToFolderName() + "/index.db?_busy_timeout=5000&_foreign_keys=on"
|
||||
expected := "/go/src/github.com/photoprism/photoprism/storage/testdata/" + dsn.PhotoPrismTestToFolderName() + "/index.db?_busy_timeout=5000&_foreign_keys=on"
|
||||
assert.Equal(t, expected, c.DatabaseName())
|
||||
}
|
||||
|
||||
|
|
@ -158,13 +158,13 @@ func TestConfig_DatabaseDSN(t *testing.T) {
|
|||
c.options.DatabaseDriver = "MariaDB"
|
||||
assert.Equal(t, "photoprism:@tcp(localhost)/photoprism?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", c.DatabaseDSN())
|
||||
c.options.DatabaseDriver = "tidb"
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/index.db?_busy_timeout=5000&_foreign_keys=on", c.DatabaseDSN())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/index.db?_busy_timeout=5000&_foreign_keys=on", c.DatabaseDSN())
|
||||
c.options.DatabaseDriver = "Postgres"
|
||||
assert.Equal(t, "postgresql://photoprism:@localhost:5432/photoprism?TimeZone=UTC&connect_timeout=15&lock_timeout=50000&sslmode=disable", c.DatabaseDSN())
|
||||
c.options.DatabaseDriver = "SQLite"
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/index.db?_busy_timeout=5000&_foreign_keys=on", c.DatabaseDSN())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/index.db?_busy_timeout=5000&_foreign_keys=on", c.DatabaseDSN())
|
||||
c.options.DatabaseDriver = ""
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/index.db?_busy_timeout=5000&_foreign_keys=on", c.DatabaseDSN())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/index.db?_busy_timeout=5000&_foreign_keys=on", c.DatabaseDSN())
|
||||
}
|
||||
|
||||
func TestConfig_DatabaseFile(t *testing.T) {
|
||||
|
|
@ -179,8 +179,8 @@ func TestConfig_DatabaseFile(t *testing.T) {
|
|||
driver := c.DatabaseDriver()
|
||||
assert.Equal(t, SQLite3, driver)
|
||||
c.options.DatabaseDSN = ""
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/index.db", c.DatabaseFile())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/index.db?_busy_timeout=5000&_foreign_keys=on", c.DatabaseDSN())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/index.db", c.DatabaseFile())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/index.db?_busy_timeout=5000&_foreign_keys=on", c.DatabaseDSN())
|
||||
}
|
||||
|
||||
func TestConfig_DatabaseTimeout(t *testing.T) {
|
||||
|
|
@ -222,7 +222,7 @@ func TestConfig_DatabaseConnsIdle(t *testing.T) {
|
|||
|
||||
func TestImportSQL(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
c.options.DatabaseDriver, c.options.DatabaseDSN = functions.PhotoPrismTestToDriverDsn(0)
|
||||
c.options.DatabaseDriver, c.options.DatabaseDSN = dsn.PhotoPrismTestToDriverDsn(0)
|
||||
|
||||
if err := c.connectDb(); err != nil {
|
||||
assert.Empty(t, err)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
"github.com/photoprism/photoprism/pkg/rnd"
|
||||
)
|
||||
|
|
@ -25,11 +25,11 @@ func TestConfig_FindBin(t *testing.T) {
|
|||
func TestConfig_SidecarPath(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
|
||||
assert.Contains(t, c.SidecarPath(), "testdata/"+functions.PhotoPrismTestToFolderName()+"/sidecar")
|
||||
assert.Contains(t, c.SidecarPath(), "testdata/"+dsn.PhotoPrismTestToFolderName()+"/sidecar")
|
||||
c.options.SidecarPath = ".photoprism"
|
||||
assert.Equal(t, ".photoprism", c.SidecarPath())
|
||||
c.options.SidecarPath = ""
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/sidecar", c.SidecarPath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/sidecar", c.SidecarPath())
|
||||
}
|
||||
|
||||
func TestConfig_SidecarYaml(t *testing.T) {
|
||||
|
|
@ -134,7 +134,7 @@ func TestConfig_TempPath(t *testing.T) {
|
|||
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/"+functions.PhotoPrismTestToFolderName()+"/temp", c.tempPath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/temp", c.tempPath())
|
||||
|
||||
c.options.TempPath = ""
|
||||
|
||||
|
|
@ -191,22 +191,22 @@ func TestConfig_CmdLibPath(t *testing.T) {
|
|||
|
||||
func TestConfig_CachePath2(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/cache", c.CachePath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/cache", c.CachePath())
|
||||
c.options.CachePath = ""
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/cache", c.CachePath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/cache", c.CachePath())
|
||||
}
|
||||
|
||||
func TestConfig_StoragePath(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName(), c.StoragePath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName(), c.StoragePath())
|
||||
c.options.StoragePath = ""
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/originals/.photoprism/storage", c.StoragePath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/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/"+functions.PhotoPrismTestToFolderName()+"/testdata", c.TestdataPath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/testdata", c.TestdataPath())
|
||||
}
|
||||
|
||||
func TestConfig_AlbumsPath(t *testing.T) {
|
||||
|
|
@ -217,13 +217,13 @@ func TestConfig_AlbumsPath(t *testing.T) {
|
|||
// If this test fails, please manually move “albums” to the “backup” folder
|
||||
// in the “storage/testdata” directory within your development environment:
|
||||
// https://github.com/photoprism/photoprism/discussions/4520
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/backup/albums", c.BackupAlbumsPath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/backup/albums", c.BackupAlbumsPath())
|
||||
}
|
||||
|
||||
func TestConfig_OriginalsAlbumsPath(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/originals/albums", c.OriginalsAlbumsPath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/originals/albums", c.OriginalsAlbumsPath())
|
||||
}
|
||||
|
||||
func TestConfig_CreateDirectories(t *testing.T) {
|
||||
|
|
@ -416,21 +416,21 @@ func TestConfig_CreateDirectories2(t *testing.T) {
|
|||
|
||||
func TestConfig_PIDFilename2(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/photoprism.pid", c.PIDFilename())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/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/"+functions.PhotoPrismTestToFolderName()+"/photoprism.log", c.LogFilename())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/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/"+functions.PhotoPrismTestToFolderName()+"/originals", c.OriginalsPath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/originals", c.OriginalsPath())
|
||||
c.options.OriginalsPath = ""
|
||||
if s := c.OriginalsPath(); s != "" && s != "/photoprism/originals" {
|
||||
t.Errorf("unexpected originals path: %s", s)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/service/hub"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -34,8 +34,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
c := TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
|
@ -151,14 +151,14 @@ func TestConfig_OptionsYaml(t *testing.T) {
|
|||
|
||||
func TestConfig_PIDFilename(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
expected := "/storage/testdata/" + functions.PhotoPrismTestToFolderName() + "/photoprism.pid"
|
||||
expected := "/storage/testdata/" + dsn.PhotoPrismTestToFolderName() + "/photoprism.pid"
|
||||
assert.Contains(t, c.PIDFilename(), expected)
|
||||
}
|
||||
|
||||
func TestConfig_LogFilename(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
|
||||
assert.Contains(t, c.LogFilename(), "/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/photoprism.log")
|
||||
assert.Contains(t, c.LogFilename(), "/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/photoprism.log")
|
||||
}
|
||||
|
||||
func TestConfig_DetachServer(t *testing.T) {
|
||||
|
|
@ -173,17 +173,17 @@ func TestConfig_OriginalsPath(t *testing.T) {
|
|||
|
||||
result := c.OriginalsPath()
|
||||
assert.True(t, strings.HasPrefix(result, "/"))
|
||||
assert.True(t, strings.HasSuffix(result, "/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/originals"))
|
||||
assert.True(t, strings.HasSuffix(result, "/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/originals"))
|
||||
}
|
||||
|
||||
func TestConfig_ImportPath(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
c.AssertTestData(t)
|
||||
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/import", c.ImportPath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/import", c.ImportPath())
|
||||
result := c.ImportPath()
|
||||
assert.True(t, strings.HasPrefix(result, "/"))
|
||||
assert.True(t, strings.HasSuffix(result, "/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/import"))
|
||||
assert.True(t, strings.HasSuffix(result, "/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/import"))
|
||||
|
||||
c.options.ImportPath = ""
|
||||
if s := c.ImportPath(); s != "" && s != "/photoprism/import" {
|
||||
|
|
@ -196,14 +196,14 @@ func TestConfig_ImportPath(t *testing.T) {
|
|||
func TestConfig_CachePath(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
|
||||
assert.True(t, strings.HasSuffix(c.CachePath(), "storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/cache"))
|
||||
assert.True(t, strings.HasSuffix(c.CachePath(), "storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/cache"))
|
||||
}
|
||||
|
||||
func TestConfig_MediaCachePath(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
|
||||
assert.True(t, strings.HasPrefix(c.MediaCachePath(), "/"))
|
||||
assert.True(t, strings.HasSuffix(c.MediaCachePath(), "storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/cache/media"))
|
||||
assert.True(t, strings.HasSuffix(c.MediaCachePath(), "storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/cache/media"))
|
||||
}
|
||||
|
||||
func TestConfig_MediaFileCachePath(t *testing.T) {
|
||||
|
|
@ -218,7 +218,7 @@ func TestConfig_ThumbCachePath(t *testing.T) {
|
|||
c := NewConfig(CliTestContext())
|
||||
|
||||
assert.True(t, strings.HasPrefix(c.ThumbCachePath(), "/"))
|
||||
assert.True(t, strings.HasSuffix(c.ThumbCachePath(), "storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/cache/thumbnails"))
|
||||
assert.True(t, strings.HasSuffix(c.ThumbCachePath(), "storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/cache/thumbnails"))
|
||||
}
|
||||
|
||||
func TestConfig_AdminUser(t *testing.T) {
|
||||
|
|
@ -290,12 +290,12 @@ func TestConfig_ImgPath(t *testing.T) {
|
|||
func TestConfig_ThemePath(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
|
||||
expected := "/go/src/github.com/photoprism/photoprism/storage/testdata/" + functions.PhotoPrismTestToFolderName() + "/config/theme"
|
||||
expected := "/go/src/github.com/photoprism/photoprism/storage/testdata/" + dsn.PhotoPrismTestToFolderName() + "/config/theme"
|
||||
assert.Equal(t, expected, c.ThemePath())
|
||||
c.SetThemePath("testdata/static/img/wallpaper")
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/internal/config/testdata/static/img/wallpaper", c.ThemePath())
|
||||
c.SetThemePath("")
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/config/theme", c.ThemePath())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/config/theme", c.ThemePath())
|
||||
}
|
||||
|
||||
func TestConfig_IndexWorkers(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -7,13 +7,12 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/ai/vision"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestConfig_VisionYaml(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/config/vision.yml", c.VisionYaml())
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/config/vision.yml", c.VisionYaml())
|
||||
}
|
||||
|
||||
func TestConfig_VisionApi(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestNewSettings(t *testing.T) {
|
||||
|
|
@ -89,15 +89,15 @@ func TestSettings_Save(t *testing.T) {
|
|||
assert.Equal(t, "onyx", s.UI.Theme)
|
||||
assert.Equal(t, "de", s.UI.Language)
|
||||
|
||||
_ = os.Mkdir("testdata/"+functions.PhotoPrismTestToFolderName(), os.ModePerm)
|
||||
if err := s.Save("testdata/" + functions.PhotoPrismTestToFolderName() + "/settings_tmp.yml"); err != nil {
|
||||
_ = os.Mkdir("testdata/"+dsn.PhotoPrismTestToFolderName(), os.ModePerm)
|
||||
if err := s.Save("testdata/" + dsn.PhotoPrismTestToFolderName() + "/settings_tmp.yml"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := os.Remove("testdata/" + functions.PhotoPrismTestToFolderName() + "/settings_tmp.yml"); err != nil {
|
||||
if err := os.Remove("testdata/" + dsn.PhotoPrismTestToFolderName() + "/settings_tmp.yml"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = os.Remove("testdata/" + functions.PhotoPrismTestToFolderName())
|
||||
_ = os.Remove("testdata/" + dsn.PhotoPrismTestToFolderName())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ import (
|
|||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config/customize"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/service/hub"
|
||||
"github.com/photoprism/photoprism/internal/thumb"
|
||||
"github.com/photoprism/photoprism/pkg/authn"
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/photoprism/photoprism/pkg/clean"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
"github.com/photoprism/photoprism/pkg/rnd"
|
||||
"github.com/photoprism/photoprism/pkg/txt/report"
|
||||
|
|
@ -58,7 +58,7 @@ func NewTestOptions(dbName string) *Options {
|
|||
storagePath = fs.Abs("../../storage")
|
||||
}
|
||||
|
||||
dataPath := filepath.Join(storagePath, fs.TestdataDir, functions.PhotoPrismTestToFolderName())
|
||||
dataPath := filepath.Join(storagePath, fs.TestdataDir, dsn.PhotoPrismTestToFolderName())
|
||||
|
||||
return NewTestOptionsForPath(dbName, dataPath)
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ func NewTestOptionsForPath(dbName, dataPath string) *Options {
|
|||
}
|
||||
|
||||
// enforce folder separation for testdata folders to prevent parallel tests of DBMS' clashing
|
||||
dataPath = filepath.Join(storagePath, fs.TestdataDir, functions.PhotoPrismTestToFolderName())
|
||||
dataPath = filepath.Join(storagePath, fs.TestdataDir, dsn.PhotoPrismTestToFolderName())
|
||||
}
|
||||
|
||||
// Enable test mode in dependencies.
|
||||
|
|
@ -119,7 +119,7 @@ func NewTestOptionsForPath(dbName, dataPath string) *Options {
|
|||
// Example PHOTOPRISM_TEST_DSN for MariaDB / MySQL:
|
||||
// - "photoprism:photoprism@tcp(mariadb:4001)/photoprism?parseTime=true"
|
||||
dbName = PkgNameRegexp.ReplaceAllString(dbName, "")
|
||||
driver, dsn := functions.PhotoPrismTestToDriverDsn(0)
|
||||
driver, dsn := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
|
||||
// Config example for MySQL / MariaDB:
|
||||
// driver = MySQL,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -62,12 +62,12 @@ func TestAlbum_SaveAsYaml(t *testing.T) {
|
|||
m = *found
|
||||
}
|
||||
|
||||
backupPath := fs.Abs("testdata/" + functions.PhotoPrismTestToFolderName() + "/TestAlbum_SaveAsYaml")
|
||||
backupPath := fs.Abs("testdata/" + dsn.PhotoPrismTestToFolderName() + "/TestAlbum_SaveAsYaml")
|
||||
|
||||
fileName, relName, err := m.YamlFileName(backupPath)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, strings.HasSuffix(fileName, "internal/entity/testdata/"+functions.PhotoPrismTestToFolderName()+"/TestAlbum_SaveAsYaml/album/as6sg6bxpogaaba9.yml"))
|
||||
assert.True(t, strings.HasSuffix(fileName, "internal/entity/testdata/"+dsn.PhotoPrismTestToFolderName()+"/TestAlbum_SaveAsYaml/album/as6sg6bxpogaaba9.yml"))
|
||||
assert.Equal(t, "album/as6sg6bxpogaaba9.yml", relName)
|
||||
|
||||
if err = m.SaveAsYaml(fileName); err != nil {
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"github.com/dustin/go-humanize/english"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/authn"
|
||||
"github.com/photoprism/photoprism/pkg/convert"
|
||||
"github.com/photoprism/photoprism/pkg/rnd"
|
||||
"github.com/photoprism/photoprism/pkg/time/unix"
|
||||
)
|
||||
|
|
@ -92,7 +92,7 @@ func DeleteClientSessions(client *Client, authMethod authn.MethodType, limit int
|
|||
}
|
||||
|
||||
// NOTE: this loses precision of the token limit. But I think int64 does not make sense for that limit type anyway.
|
||||
q = q.Order("created_at DESC").Limit(1000000000).Offset(functions.SafeInt64toint(limit))
|
||||
q = q.Order("created_at DESC").Limit(1000000000).Offset(convert.SafeInt64toint(limit))
|
||||
|
||||
found := Sessions{}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/clean"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
var log = event.Log
|
||||
|
|
@ -41,28 +41,28 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
driver, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
driver, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
// Set default test database driver.
|
||||
if driver == "test" || driver == "sqlite" || driver == "" || dsn == "" {
|
||||
if driver == "test" || driver == "sqlite" || driver == "" || dsname == "" {
|
||||
driver = entity.SQLite3
|
||||
}
|
||||
|
||||
// Set default database DSN.
|
||||
if driver == entity.SQLite3 {
|
||||
if dsn == "" {
|
||||
dsn = entity.SQLiteMemoryDSN
|
||||
} else if dsn != entity.SQLiteTestDB {
|
||||
if dsname == "" {
|
||||
dsname = entity.SQLiteMemoryDSN
|
||||
} else if dsname != entity.SQLiteTestDB {
|
||||
// Continue.
|
||||
} else if err := os.Remove(dsn); err == nil {
|
||||
log.Debugf("sqlite: test file %s removed", clean.Log(dsn))
|
||||
} else if err := os.Remove(dsname); err == nil {
|
||||
log.Debugf("sqlite: test file %s removed", clean.Log(dsname))
|
||||
}
|
||||
}
|
||||
|
||||
db := entity.InitTestDb(
|
||||
driver,
|
||||
dsn)
|
||||
dsname)
|
||||
|
||||
defer db.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/convert"
|
||||
)
|
||||
|
||||
// Count returns the number of records for a given a model and key values.
|
||||
|
|
@ -36,5 +36,5 @@ func Count(m interface{}, keys []string, values []interface{}) int {
|
|||
return -1
|
||||
}
|
||||
|
||||
return functions.SafeInt64toint(count)
|
||||
return convert.SafeInt64toint(count)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
driver, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
driver, dsn := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
db := InitTestDb(
|
||||
driver,
|
||||
dsn)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/ai/face"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/convert"
|
||||
"github.com/photoprism/photoprism/pkg/rnd"
|
||||
)
|
||||
|
||||
|
|
@ -479,6 +479,6 @@ func ValidFaceCount(fileUid string) (c int) {
|
|||
log.Errorf("file: %s (count faces)", err)
|
||||
return 0
|
||||
} else {
|
||||
return functions.SafeInt64toint(cValue)
|
||||
return convert.SafeInt64toint(cValue)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
|
|
@ -19,7 +19,7 @@ import (
|
|||
)
|
||||
|
||||
func TestDialectMysql(t *testing.T) {
|
||||
driver, _ := functions.PhotoPrismTestToDriverDsn(0)
|
||||
driver, _ := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
if driver != "mysql" {
|
||||
t.Skip("skipping test as not MariaDB")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
|
|
@ -19,7 +19,7 @@ import (
|
|||
)
|
||||
|
||||
func TestDialectPostgreSQL(t *testing.T) {
|
||||
driver, _ := functions.PhotoPrismTestToDriverDsn(0)
|
||||
driver, _ := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
if driver != "postgres" {
|
||||
t.Skip("skipping test as not PostgreSQL")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ import (
|
|||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
func TestDialectSQLite3(t *testing.T) {
|
||||
driver, _ := functions.PhotoPrismTestToDriverDsn(0)
|
||||
driver, _ := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
if driver != "sqlite" {
|
||||
t.Skip("skipping test as not SQLite")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ func TestPhoto_SaveAsYaml(t *testing.T) {
|
|||
m := PhotoFixtures.Get("Photo01")
|
||||
m.PreloadFiles()
|
||||
|
||||
fileName := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName(), ".photoprism_test.yml")
|
||||
fileName := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName(), ".photoprism_test.yml")
|
||||
|
||||
if err := m.SaveAsYaml(fileName); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -86,7 +86,7 @@ func TestPhoto_SaveSidecarYaml(t *testing.T) {
|
|||
m := PhotoFixtures.Get("Photo01")
|
||||
m.PreloadFiles()
|
||||
|
||||
basePath := fs.Abs(functions.PhotoPrismTestToFolderName() + "/testdata/yaml")
|
||||
basePath := fs.Abs(dsn.PhotoPrismTestToFolderName() + "/testdata/yaml")
|
||||
originalsPath := filepath.Join(basePath, "originals")
|
||||
sidecarPath := filepath.Join(basePath, "sidecar")
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ func TestPhoto_SaveSidecarYaml(t *testing.T) {
|
|||
m := Photo{}
|
||||
m.PreloadFiles()
|
||||
|
||||
basePath := fs.Abs(functions.PhotoPrismTestToFolderName() + "/testdata/yaml")
|
||||
basePath := fs.Abs(dsn.PhotoPrismTestToFolderName() + "/testdata/yaml")
|
||||
originalsPath := filepath.Join(basePath, "originals")
|
||||
sidecarPath := filepath.Join(basePath, "sidecar")
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ func TestPhoto_SaveSidecarYaml(t *testing.T) {
|
|||
m := Photo{PhotoName: "testphoto"}
|
||||
m.PreloadFiles()
|
||||
|
||||
basePath := fs.Abs(functions.PhotoPrismTestToFolderName() + "/testdata/yaml")
|
||||
basePath := fs.Abs(dsn.PhotoPrismTestToFolderName() + "/testdata/yaml")
|
||||
originalsPath := filepath.Join(basePath, "originals")
|
||||
sidecarPath := filepath.Join(basePath, "sidecar")
|
||||
|
||||
|
|
@ -181,7 +181,7 @@ func TestPhoto_LoadFromYaml(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("GormV1Format", func(t *testing.T) {
|
||||
filePath := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName())
|
||||
filePath := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName())
|
||||
|
||||
if err := os.MkdirAll(filePath, fs.ModeDir); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -213,7 +213,7 @@ func TestPhoto_LoadFromYaml(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("GormV2Format", func(t *testing.T) {
|
||||
filePath := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName())
|
||||
filePath := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName())
|
||||
|
||||
if err := os.MkdirAll(filePath, fs.ModeDir); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -245,7 +245,7 @@ func TestPhoto_LoadFromYaml(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("GormV1Format_Bad", func(t *testing.T) {
|
||||
filePath := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName())
|
||||
filePath := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName())
|
||||
|
||||
if err := os.MkdirAll(filePath, fs.ModeDir); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -279,7 +279,7 @@ func TestPhoto_LoadFromYaml(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("GormV2Format_Bad", func(t *testing.T) {
|
||||
filePath := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName())
|
||||
filePath := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName())
|
||||
|
||||
if err := os.MkdirAll(filePath, fs.ModeDir); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/ai/face"
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/mutex"
|
||||
"github.com/photoprism/photoprism/pkg/clean"
|
||||
"github.com/photoprism/photoprism/pkg/convert"
|
||||
)
|
||||
|
||||
// IDs represents a list of identifier strings.
|
||||
|
|
@ -181,7 +181,7 @@ func CountNewFaceMarkers(size, score int) (n int) {
|
|||
log.Errorf("faces: %s (count new markers)", err)
|
||||
}
|
||||
|
||||
return functions.SafeInt64toint(nData)
|
||||
return convert.SafeInt64toint(nData)
|
||||
}
|
||||
|
||||
// PurgeOrphanFaces removes unused faces from the index.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/convert"
|
||||
)
|
||||
|
||||
// HashMap records the existence of hashes for originals or thumbnails.
|
||||
|
|
@ -20,7 +20,7 @@ func CountFileHashes() (count int) {
|
|||
log.Errorf("files: %s (count hashes)", err)
|
||||
}
|
||||
|
||||
return functions.SafeInt64toint(countData)
|
||||
return convert.SafeInt64toint(countData)
|
||||
}
|
||||
|
||||
// FetchHashMap populates a hash map from the database.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/ai/face"
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/convert"
|
||||
)
|
||||
|
||||
// MarkerByUID returns a Marker based on the UID.
|
||||
|
|
@ -264,7 +264,7 @@ func CountUnmatchedFaceMarkers() (n int) {
|
|||
log.Errorf("faces: %s (count unmatched markers)", err)
|
||||
}
|
||||
|
||||
return functions.SafeInt64toint(nData)
|
||||
return convert.SafeInt64toint(nData)
|
||||
}
|
||||
|
||||
// CountMarkers counts the number of face markers in the index.
|
||||
|
|
@ -280,7 +280,7 @@ func CountMarkers(markerType string) (n int) {
|
|||
log.Errorf("faces: %s (count markers)", err)
|
||||
}
|
||||
|
||||
return functions.SafeInt64toint(nData)
|
||||
return convert.SafeInt64toint(nData)
|
||||
}
|
||||
|
||||
// RemoveOrphanMarkers removes markers without an existing file.
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
driver, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
driver, dsn := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
db := entity.InitTestDb(
|
||||
driver,
|
||||
dsn)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/clean"
|
||||
"github.com/photoprism/photoprism/pkg/convert"
|
||||
)
|
||||
|
||||
// People returns the sorted names of the first 2000 people.
|
||||
|
|
@ -31,7 +31,7 @@ func PeopleCount() (count int, err error) {
|
|||
Where("subj_type = ?", entity.SubjPerson).
|
||||
Count(&countData).Error
|
||||
|
||||
return functions.SafeInt64toint(countData), err
|
||||
return convert.SafeInt64toint(countData), err
|
||||
}
|
||||
|
||||
// Subjects returns subjects from the index.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/convert"
|
||||
"github.com/photoprism/photoprism/pkg/rnd"
|
||||
"github.com/photoprism/photoprism/pkg/txt"
|
||||
)
|
||||
|
|
@ -45,7 +45,7 @@ func CountUsers(registered, active bool, roles, excludeRoles []string) (count in
|
|||
log.Errorf("users: %s (count)", err)
|
||||
}
|
||||
|
||||
return functions.SafeInt64toint(countData)
|
||||
return convert.SafeInt64toint(countData)
|
||||
}
|
||||
|
||||
// Users finds user accounts based on the specified parameters.
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
driver, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
driver, dsn := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
db := entity.InitTestDb(
|
||||
driver,
|
||||
dsn)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/ffmpeg/encode"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -20,11 +20,11 @@ func RunCommandTest(t *testing.T, encoder encode.Encoder, srcName, destName stri
|
|||
cmd.Stdout = &out
|
||||
cmd.Stderr = &stderr
|
||||
cmd.Env = append(cmd.Env, []string{
|
||||
fmt.Sprintf("HOME=%s", fs.Abs("./testdata/"+functions.PhotoPrismTestToFolderName())),
|
||||
fmt.Sprintf("HOME=%s", fs.Abs("./testdata/"+dsn.PhotoPrismTestToFolderName())),
|
||||
}...)
|
||||
|
||||
// create required folder
|
||||
_ = os.Mkdir("./testdata/"+functions.PhotoPrismTestToFolderName(), os.ModePerm)
|
||||
_ = os.Mkdir("./testdata/"+dsn.PhotoPrismTestToFolderName(), os.ModePerm)
|
||||
|
||||
// Transcode source media file to AVC.
|
||||
start := time.Now()
|
||||
|
|
@ -60,6 +60,6 @@ func RunCommandTest(t *testing.T, encoder encode.Encoder, srcName, destName stri
|
|||
t.Fatalf("%s: failed to remove %s after successful test (%s)", encoder, srcName, removeErr)
|
||||
}
|
||||
// remove created folder
|
||||
_ = os.Remove("./testdata/" + functions.PhotoPrismTestToFolderName())
|
||||
_ = os.Remove("./testdata/" + dsn.PhotoPrismTestToFolderName())
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
func BenchmarkMigration_SQLite(b *testing.B) {
|
||||
driver, _ := functions.PhotoPrismTestToDriverDsn(0)
|
||||
driver, _ := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
if driver != "sqlite" {
|
||||
b.Skip("skipping benchmark as not SQLite")
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ func BenchmarkMigration_SQLite(b *testing.B) {
|
|||
}
|
||||
|
||||
func BenchmarkMigration_MySQL(b *testing.B) {
|
||||
driver, _ := functions.PhotoPrismTestToDriverDsn(0)
|
||||
driver, _ := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
if driver != "mysql" {
|
||||
b.Skip("skipping benchmark as not MariaDB")
|
||||
}
|
||||
|
|
@ -147,7 +147,7 @@ func BenchmarkMigration_MySQL(b *testing.B) {
|
|||
}
|
||||
|
||||
func BenchmarkMigration_PostgreSQL(b *testing.B) {
|
||||
driver, _ := functions.PhotoPrismTestToDriverDsn(0)
|
||||
driver, _ := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
if driver != "postgres" {
|
||||
b.Skip("skipping benchmark as not PostgreSQL")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/photoprism"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -29,8 +29,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
c := config.TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/thumb"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs/fastwalk"
|
||||
"github.com/photoprism/photoprism/pkg/media/colors"
|
||||
)
|
||||
|
|
@ -18,7 +18,7 @@ import (
|
|||
func TestMediaFile_Colors_Testdata(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
thumbsPath := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName(), "TestMediaFile_Colors_Testdata")
|
||||
thumbsPath := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName(), "TestMediaFile_Colors_Testdata")
|
||||
defer os.RemoveAll(thumbsPath)
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -21,8 +21,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "internal-photoprism-get")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -28,8 +28,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
c := config.NewTestConfig("photoprism")
|
||||
SetConfig(c)
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/thumb"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestResample_Start(t *testing.T) {
|
||||
|
|
@ -64,7 +64,7 @@ func TestThumb_Filename(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.True(t, strings.HasSuffix(filename, "/storage/testdata/"+functions.PhotoPrismTestToFolderName()+"/cache/_tmp/9/9/9/99988_150x150_fit.jpg"))
|
||||
assert.True(t, strings.HasSuffix(filename, "/storage/testdata/"+dsn.PhotoPrismTestToFolderName()+"/cache/_tmp/9/9/9/99988_150x150_fit.jpg"))
|
||||
})
|
||||
t.Run("InvalidHash", func(t *testing.T) {
|
||||
_, err := thumb.FileName("999", thumbsPath, 150, 150, thumb.ResampleFit, thumb.ResampleNearestNeighbor)
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/server/limiter"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -33,8 +33,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
// Init test config.
|
||||
c := config.TestConfig()
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -30,8 +30,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
// Run unit tests.
|
||||
beforeTimestamp := time.Now().UTC()
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -30,8 +30,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
// Run unit tests.
|
||||
beforeTimestamp := time.Now().UTC()
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -31,8 +31,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
// Run unit tests.
|
||||
beforeTimestamp := time.Now().UTC()
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ import (
|
|||
cfg "github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/service/cluster"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
"github.com/photoprism/photoprism/pkg/rnd"
|
||||
)
|
||||
|
|
@ -35,8 +35,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
// Run unit tests.
|
||||
beforeTimestamp := time.Now().UTC()
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import (
|
|||
"gorm.io/gorm"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/clean"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
// Stores the number of test databases that are supported.
|
||||
|
|
@ -134,7 +134,7 @@ func AcquireDBMutex(log event.Logger, caller string) (dbc *DbConn, dbn int, err
|
|||
|
||||
err = nil
|
||||
|
||||
driver, dsn := functions.PhotoPrismTestToDriverDsn(0)
|
||||
driver, dsn := dsn.PhotoPrismTestToDriverDsn(0)
|
||||
|
||||
// Set default test database driver.
|
||||
if driver == "test" || driver == "sqlite" || driver == "" || dsn == "" {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/photoprism"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -27,8 +27,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "avatar-test")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -25,8 +25,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
c := config.TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/mutex"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestMeta_Start(t *testing.T) {
|
||||
|
|
@ -52,5 +52,5 @@ func TestMeta_originalsPath(t *testing.T) {
|
|||
worker := NewMeta(conf)
|
||||
|
||||
assert.IsType(t, &Meta{}, worker)
|
||||
assert.True(t, strings.HasSuffix(worker.originalsPath(), "testdata/"+functions.PhotoPrismTestToFolderName()+"/originals"))
|
||||
assert.True(t, strings.HasSuffix(worker.originalsPath(), "testdata/"+dsn.PhotoPrismTestToFolderName()+"/originals"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ func TestSync_downloadPath(t *testing.T) {
|
|||
worker := NewSync(conf)
|
||||
|
||||
assert.IsType(t, &Sync{}, worker)
|
||||
assert.True(t, strings.HasSuffix(worker.downloadPath(), "testdata/"+functions.PhotoPrismTestToFolderName()+"/temp/sync"))
|
||||
assert.True(t, strings.HasSuffix(worker.downloadPath(), "testdata/"+dsn.PhotoPrismTestToFolderName()+"/temp/sync"))
|
||||
}
|
||||
|
||||
func TestSync_relatedDownloads(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import (
|
|||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/internal/photoprism"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/testextras"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
|
|
@ -32,8 +32,8 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
defer testextras.UnlockDBMutex(dbc.Db())
|
||||
|
||||
_, dsn := functions.PhotoPrismTestToDriverDsn(dbn)
|
||||
functions.SetDSNToEnv(dsn)
|
||||
_, dsname := dsn.PhotoPrismTestToDriverDsn(dbn)
|
||||
dsn.SetDSNToEnv(dsname)
|
||||
|
||||
c := config.TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
|
|
|||
25
pkg/convert/convert.go
Normal file
25
pkg/convert/convert.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
Package convert centralizes functions that convert from one datatype to another throughout PhotoPrism.
|
||||
|
||||
Copyright (c) 2018 - 2025 PhotoPrism UG. All rights reserved.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
|
||||
<https://docs.photoprism.app/license/agpl>
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
The AGPL is supplemented by our Trademark and Brand Guidelines,
|
||||
which describe how our Brand Assets may be used:
|
||||
<https://www.photoprism.app/trademark>
|
||||
|
||||
Feel free to send an email to hello@photoprism.app if you have questions,
|
||||
want to support our work, or just want to say hello.
|
||||
|
||||
Additional information can be found in our Developer Guide:
|
||||
<https://docs.photoprism.app/developer-guide/>
|
||||
*/
|
||||
package convert
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package functions
|
||||
package convert
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package functions
|
||||
package convert
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
|
@ -1,4 +1,28 @@
|
|||
package functions
|
||||
/*
|
||||
Package dsn centralizes functions that handle dsn parsing and formatting throughout PhotoPrism.
|
||||
|
||||
Copyright (c) 2018 - 2025 PhotoPrism UG. All rights reserved.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
|
||||
<https://docs.photoprism.app/license/agpl>
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
The AGPL is supplemented by our Trademark and Brand Guidelines,
|
||||
which describe how our Brand Assets may be used:
|
||||
<https://www.photoprism.app/trademark>
|
||||
|
||||
Feel free to send an email to hello@photoprism.app if you have questions,
|
||||
want to support our work, or just want to say hello.
|
||||
|
||||
Additional information can be found in our Developer Guide:
|
||||
<https://docs.photoprism.app/developer-guide/>
|
||||
*/
|
||||
package dsn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package functions
|
||||
package dsn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package functions
|
||||
package dsn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package functions
|
||||
package dsn
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
|
@ -10,12 +10,12 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func TestWriteFile(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
dir := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName(), "_WriteFile_Success")
|
||||
dir := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName(), "_WriteFile_Success")
|
||||
filePath := filepath.Join(dir, "notyetexisting.jpg")
|
||||
fileData := []byte("foobar")
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ func TestWriteFile(t *testing.T) {
|
|||
|
||||
func TestWriteString(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
dir := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName(), "_WriteString_Success")
|
||||
dir := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName(), "_WriteString_Success")
|
||||
filePath := filepath.Join(dir, PPIgnoreFilename)
|
||||
fileData := "*"
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ func TestWriteString(t *testing.T) {
|
|||
|
||||
func TestWriteUnixTime(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
dir := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName(), "_WriteUnixTime_Success")
|
||||
dir := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName(), "_WriteUnixTime_Success")
|
||||
filePath := filepath.Join(dir, PPStorageFilename)
|
||||
|
||||
if err := MkdirAll(dir); err != nil {
|
||||
|
|
@ -107,7 +107,7 @@ func TestWriteUnixTime(t *testing.T) {
|
|||
|
||||
func TestWriteFileFromReader(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
dir := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName(), "_WriteFileFromReader_Success")
|
||||
dir := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName(), "_WriteFileFromReader_Success")
|
||||
|
||||
filePath1 := filepath.Join(dir, "1.txt")
|
||||
filePath2 := filepath.Join(dir, "2.txt")
|
||||
|
|
@ -148,7 +148,7 @@ func TestWriteFileFromReader(t *testing.T) {
|
|||
|
||||
func TestCacheFileFromReader(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
dir := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName(), "_CacheFileFromReader_Success")
|
||||
dir := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName(), "_CacheFileFromReader_Success")
|
||||
|
||||
filePath1 := filepath.Join(dir, "1.txt")
|
||||
filePath2 := filepath.Join(dir, "2.txt")
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func writeZip(t *testing.T, path string, entries map[string][]byte) {
|
||||
|
|
@ -152,7 +152,7 @@ func TestUnzip_CreatesDirectoriesAndNestedFiles(t *testing.T) {
|
|||
|
||||
func TestZip(t *testing.T) {
|
||||
t.Run("Compressed", func(t *testing.T) {
|
||||
zipDir := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName(), "pkg/fs")
|
||||
zipDir := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName(), "pkg/fs")
|
||||
zipName := filepath.Join(zipDir, "compressed.zip")
|
||||
unzipDir := filepath.Join(zipDir, "compressed")
|
||||
files := []string{"./testdata/directory/example.jpg"}
|
||||
|
|
@ -185,7 +185,7 @@ func TestZip(t *testing.T) {
|
|||
}
|
||||
})
|
||||
t.Run("Uncompressed", func(t *testing.T) {
|
||||
zipDir := filepath.Join(os.TempDir(), functions.PhotoPrismTestToFolderName(), "pkg/fs")
|
||||
zipDir := filepath.Join(os.TempDir(), dsn.PhotoPrismTestToFolderName(), "pkg/fs")
|
||||
zipName := filepath.Join(zipDir, "uncompressed.zip")
|
||||
unzipDir := filepath.Join(zipDir, "uncompressed")
|
||||
files := []string{"./testdata/directory/example.jpg"}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/functions"
|
||||
"github.com/photoprism/photoprism/pkg/dsn"
|
||||
)
|
||||
|
||||
func writeImage(path string, img image.Image) error {
|
||||
|
|
@ -50,8 +50,8 @@ func TestToSRGB(t *testing.T) {
|
|||
|
||||
imgSRGB := ToSRGB(img, ProfileDisplayP3)
|
||||
|
||||
_ = os.Mkdir("./testdata/"+functions.PhotoPrismTestToFolderName(), os.ModePerm)
|
||||
srgbFile := "./testdata/" + functions.PhotoPrismTestToFolderName() + "/SRGB.jpg"
|
||||
_ = os.Mkdir("./testdata/"+dsn.PhotoPrismTestToFolderName(), os.ModePerm)
|
||||
srgbFile := "./testdata/" + dsn.PhotoPrismTestToFolderName() + "/SRGB.jpg"
|
||||
|
||||
if err := writeImage(srgbFile, imgSRGB); err != nil {
|
||||
t.Error(err)
|
||||
|
|
@ -60,6 +60,6 @@ func TestToSRGB(t *testing.T) {
|
|||
assert.FileExists(t, srgbFile)
|
||||
|
||||
_ = os.Remove(srgbFile)
|
||||
_ = os.Remove("./testdata/" + functions.PhotoPrismTestToFolderName())
|
||||
_ = os.Remove("./testdata/" + dsn.PhotoPrismTestToFolderName())
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue