photoprism/internal/form/client_test.go

41 lines
900 B
Go
Raw Normal View History

package form
import (
2024-01-16 18:10:42 +01:00
"flag"
"testing"
2024-01-16 18:10:42 +01:00
"github.com/urfave/cli"
"github.com/photoprism/photoprism/pkg/authn"
"github.com/stretchr/testify/assert"
)
func TestNewClient(t *testing.T) {
t.Run("Defaults", func(t *testing.T) {
client := NewClient()
assert.Equal(t, authn.MethodOAuth2, client.Method())
assert.Equal(t, "", client.Scope())
2024-01-16 16:51:49 +01:00
assert.Equal(t, "", client.Name())
})
}
2024-01-16 18:10:42 +01:00
func TestNewClientFromCli(t *testing.T) {
t.Run("Success", func(t *testing.T) {
globalSet := flag.NewFlagSet("test", 0)
globalSet.String("name", "Test", "")
globalSet.String("scope", "*", "")
globalSet.String("method", "totp", "")
app := cli.NewApp()
app.Version = "0.0.0"
c := cli.NewContext(app, globalSet, nil)
client := NewClientFromCli(c)
assert.Equal(t, authn.Method2FA, client.Method())
assert.Equal(t, "webdav", client.Scope())
assert.Equal(t, "Test", client.Name())
})
}