mirror of
https://github.com/photoprism/photoprism.git
synced 2026-07-17 16:49:04 +00:00
Commands: Prevent config command tests from polluting the originals directory
This commit is contained in:
parent
924c80f78c
commit
89a0bd7399
8 changed files with 42 additions and 53 deletions
|
|
@ -47,6 +47,13 @@ func TestMain(m *testing.M) {
|
|||
return c, c.Init()
|
||||
}
|
||||
|
||||
// Init core config (no database) using the shared test config so commands
|
||||
// like "show config" and "faces config" don't fall back to a storage path
|
||||
// derived from the real originals directory.
|
||||
InitCoreConfig = func(ctx *cli.Context, quiet bool) (*config.Config, error) {
|
||||
return c, c.InitCore()
|
||||
}
|
||||
|
||||
// Run unit tests.
|
||||
code := m.Run()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/service/hub"
|
||||
)
|
||||
|
||||
// InitConfig initializes the command config.
|
||||
|
|
@ -13,3 +15,16 @@ var InitConfig = func(ctx *cli.Context) (*config.Config, error) {
|
|||
get.SetConfig(c)
|
||||
return c, c.Init()
|
||||
}
|
||||
|
||||
// InitCoreConfig initializes the command core config without connecting to the
|
||||
// database. When quiet is true, the log level is raised to fatal so only the
|
||||
// command's own output is printed (used by the config report commands).
|
||||
var InitCoreConfig = func(ctx *cli.Context, quiet bool) (*config.Config, error) {
|
||||
c := config.NewConfig(ctx)
|
||||
if quiet {
|
||||
c.SetLogLevel(logrus.FatalLevel)
|
||||
}
|
||||
get.SetConfig(c)
|
||||
hub.Disable()
|
||||
return c, c.InitCore()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/manifoldco/promptui"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/entity/query"
|
||||
"github.com/photoprism/photoprism/internal/photoprism"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
|
|
@ -126,13 +125,12 @@ func facesStatsAction(ctx *cli.Context) error {
|
|||
func facesAuditAction(ctx *cli.Context) error {
|
||||
start := time.Now()
|
||||
|
||||
conf := config.NewConfig(ctx)
|
||||
get.SetConfig(conf)
|
||||
conf, err := InitConfig(ctx)
|
||||
|
||||
_, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := conf.Init(); err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -171,13 +169,12 @@ func facesResetAction(ctx *cli.Context) error {
|
|||
|
||||
start := time.Now()
|
||||
|
||||
conf := config.NewConfig(ctx)
|
||||
get.SetConfig(conf)
|
||||
conf, err := InitConfig(ctx)
|
||||
|
||||
_, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := conf.Init(); err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -217,13 +214,12 @@ func facesResetAllAction(ctx *cli.Context) error {
|
|||
|
||||
start := time.Now()
|
||||
|
||||
conf := config.NewConfig(ctx)
|
||||
get.SetConfig(conf)
|
||||
conf, err := InitConfig(ctx)
|
||||
|
||||
_, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := conf.Init(); err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -245,13 +241,12 @@ func facesResetAllAction(ctx *cli.Context) error {
|
|||
func facesIndexAction(ctx *cli.Context) error {
|
||||
start := time.Now()
|
||||
|
||||
conf := config.NewConfig(ctx)
|
||||
get.SetConfig(conf)
|
||||
conf, err := InitConfig(ctx)
|
||||
|
||||
_, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := conf.Init(); err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -316,13 +311,12 @@ func facesIndexAction(ctx *cli.Context) error {
|
|||
func facesUpdateAction(ctx *cli.Context) error {
|
||||
start := time.Now()
|
||||
|
||||
conf := config.NewConfig(ctx)
|
||||
get.SetConfig(conf)
|
||||
conf, err := InitConfig(ctx)
|
||||
|
||||
_, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := conf.Init(); err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -350,13 +344,12 @@ func facesUpdateAction(ctx *cli.Context) error {
|
|||
func facesOptimizeAction(ctx *cli.Context) error {
|
||||
start := time.Now()
|
||||
|
||||
conf := config.NewConfig(ctx)
|
||||
get.SetConfig(conf)
|
||||
conf, err := InitConfig(ctx)
|
||||
|
||||
_, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := conf.Init(); err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,9 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/service/hub"
|
||||
"github.com/photoprism/photoprism/pkg/txt/report"
|
||||
)
|
||||
|
||||
|
|
@ -32,11 +30,9 @@ var FacesConfigReports = []Report{
|
|||
|
||||
// facesConfigAction prints face-related config option names and values.
|
||||
func facesConfigAction(ctx *cli.Context) error {
|
||||
conf := config.NewConfig(ctx)
|
||||
conf.SetLogLevel(logrus.FatalLevel)
|
||||
hub.Disable()
|
||||
conf, err := InitCoreConfig(ctx, true)
|
||||
|
||||
if err := conf.InitCore(); err != nil {
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ import (
|
|||
)
|
||||
|
||||
func TestFacesConfigCommand(t *testing.T) {
|
||||
// "faces config" calls InitCore, which creates storage dirs and an index database under
|
||||
// ".photoprism" in the working directory when no storage path is set; run from a temp
|
||||
// dir so the test does not leave files in the repository.
|
||||
t.Chdir(t.TempDir())
|
||||
|
||||
output, err := RunWithTestContext(FacesConfigCommand, []string{})
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -33,11 +28,6 @@ func TestFacesConfigCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFacesConfigCommandJSON(t *testing.T) {
|
||||
// "faces config" calls InitCore, which creates storage dirs and an index database under
|
||||
// ".photoprism" in the working directory when no storage path is set; run from a temp
|
||||
// dir so the test does not leave files in the repository.
|
||||
t.Chdir(t.TempDir())
|
||||
|
||||
output, err := RunWithTestContext(FacesConfigCommand, []string{"config", "--json"})
|
||||
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/entity/migrate"
|
||||
"github.com/photoprism/photoprism/pkg/txt/report"
|
||||
)
|
||||
|
|
@ -148,12 +147,12 @@ func migrationsRunAction(ctx *cli.Context) error {
|
|||
|
||||
start := time.Now()
|
||||
|
||||
conf := config.NewConfig(ctx)
|
||||
conf, err := InitConfig(ctx)
|
||||
|
||||
_, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := conf.Init(); err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,9 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/service/hub"
|
||||
"github.com/photoprism/photoprism/pkg/txt/report"
|
||||
)
|
||||
|
||||
|
|
@ -34,12 +31,9 @@ var ConfigReports = []Report{
|
|||
|
||||
// showConfigAction displays global config option names and values.
|
||||
func showConfigAction(ctx *cli.Context) error {
|
||||
conf := config.NewConfig(ctx)
|
||||
conf.SetLogLevel(logrus.FatalLevel)
|
||||
get.SetConfig(conf)
|
||||
hub.Disable()
|
||||
conf, err := InitCoreConfig(ctx, true)
|
||||
|
||||
if err := conf.InitCore(); err != nil {
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,6 @@ import (
|
|||
"github.com/sevlyar/go-daemon"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
"github.com/photoprism/photoprism/internal/service/hub"
|
||||
"github.com/photoprism/photoprism/pkg/clean"
|
||||
)
|
||||
|
||||
|
|
@ -24,11 +21,9 @@ var StopCommand = &cli.Command{
|
|||
|
||||
// stopAction stops the daemon if it is running.
|
||||
func stopAction(ctx *cli.Context) error {
|
||||
conf := config.NewConfig(ctx)
|
||||
get.SetConfig(conf)
|
||||
hub.Disable()
|
||||
conf, err := InitCoreConfig(ctx, false)
|
||||
|
||||
if err := conf.InitCore(); err != nil {
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue