mirror of
https://github.com/photoprism/photoprism.git
synced 2026-04-22 16:07:25 +08:00
a2b7615c93
Run `go fix ./...` and keep mechanical modernization updates.
- Replace `interface{}` with `any` in signatures and local types
- Apply formatter/style cleanups from go1.26 tooling
- Keep `omitempty` behavior-preserving simplifications suggested by fix
- No functional feature changes intended
Validation:
- go test ./... -run '^$' -count=1 (Go 1.26.0)
- GOTOOLCHAIN=go1.24.10 go test ./... -run '^$' -count=1
Signed-off-by: Michael Mayer <michael@photoprism.app>
45 lines
970 B
Go
45 lines
970 B
Go
package config
|
|
|
|
import (
|
|
"flag"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
type durationTarget struct {
|
|
Interval time.Duration `flag:"interval"`
|
|
}
|
|
|
|
func TestApplyCliContext_Duration(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected time.Duration
|
|
}{
|
|
{name: "WithUnits", input: "1h30m", expected: 90 * time.Minute},
|
|
{name: "NumericSeconds", input: "30", expected: 30 * time.Second},
|
|
{name: "Invalid", input: "not-a-duration", expected: 0},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
flags := flag.NewFlagSet("test", flag.ContinueOnError)
|
|
flags.String("interval", "", "doc")
|
|
app := cli.NewApp()
|
|
ctx := cli.NewContext(app, flags, nil)
|
|
_ = ctx.Set("interval", tc.input)
|
|
|
|
target := &durationTarget{}
|
|
err := ApplyCliContext(target, ctx)
|
|
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, tc.expected, target.Interval)
|
|
})
|
|
}
|
|
}
|