Merge remote-tracking branch 'photoprism/develop' into gorm2

This commit is contained in:
Keith Martin
2025-01-31 23:08:27 +10:00
832 changed files with 78500 additions and 76829 deletions

View File

@@ -7,12 +7,13 @@ import (
"time"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/photoprism/get"
"github.com/photoprism/photoprism/internal/testextras"
"github.com/photoprism/photoprism/pkg/capture"
)
func TestMain(m *testing.M) {
@@ -44,20 +45,28 @@ func TestMain(m *testing.M) {
testextras.ReleaseDBMutex(dbc.Db(), log, caller, code)
// Close database connection.
c.CloseDb()
_ = c.CloseDb()
os.Exit(code)
}
// NewTestContext creates a new CLI test context with the flags and arguments provided.
func NewTestContext(args []string) *cli.Context {
// Create new command-line app.
// Create new command-line test app.
app := cli.NewApp()
app.Name = "photoprism"
app.Usage = "PhotoPrism®"
app.Description = ""
app.Version = "test"
app.Copyright = "(c) 2018-2024 PhotoPrism UG. All rights reserved."
app.EnableBashCompletion = true
app.Copyright = "(c) 2018-2025 PhotoPrism UG. All rights reserved."
app.Flags = config.Flags.Cli()
app.Commands = PhotoPrism
app.HelpName = app.Name
app.CustomAppHelpTemplate = ""
app.HideHelp = true
app.HideHelpCommand = true
app.Action = func(*cli.Context) error { return nil }
app.EnableBashCompletion = false
app.Metadata = map[string]interface{}{
"Name": "PhotoPrism",
"About": "PhotoPrism®",
@@ -65,10 +74,27 @@ func NewTestContext(args []string) *cli.Context {
"Version": "test",
}
// Parse command arguments.
flags := flag.NewFlagSet("test", 0)
LogErr(flags.Parse(args))
// Parse command test arguments.
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
LogErr(flagSet.Parse(args))
// Create and return new context.
return cli.NewContext(app, flags, nil)
// Create and return new test context.
return cli.NewContext(app, flagSet, nil)
}
// RunWithTestContext executes a command with a test context and returns its output.
func RunWithTestContext(cmd *cli.Command, args []string) (output string, err error) {
// Create test context with flags and arguments.
ctx := NewTestContext(args)
// TODO: Help output can currently not be generated in test mode due to
// a nil pointer panic in the "github.com/urfave/cli/v2" package.
cmd.HideHelp = true
// Run command with test context.
output = capture.Output(func() {
err = cmd.Run(ctx, args...)
})
return output, err
}