mirror of https://github.com/ory/hydra
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// Copyright © 2022 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cmd_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/tidwall/gjson"
|
|
|
|
"github.com/ory/hydra/v2/cmd"
|
|
"github.com/ory/x/cmdx"
|
|
"github.com/ory/x/snapshotx"
|
|
)
|
|
|
|
func TestGetClient(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
c := cmd.NewGetClientsCmd()
|
|
reg := setup(t, c)
|
|
|
|
expected := createClient(t, reg, nil)
|
|
t.Run("case=gets client", func(t *testing.T) {
|
|
actual := gjson.Parse(cmdx.ExecNoErr(t, c, expected.GetID()))
|
|
assert.NotEmpty(t, actual.Get("client_id").String())
|
|
assert.Empty(t, actual.Get("client_secret").String())
|
|
|
|
expected, err := reg.ClientManager().GetClient(t.Context(), actual.Get("client_id").String())
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, expected.GetID(), actual.Get("client_id").String())
|
|
snapshotx.SnapshotT(t, json.RawMessage(actual.Raw), snapshotExcludedClientFields...)
|
|
})
|
|
|
|
t.Run("case=gets multiple clients", func(t *testing.T) {
|
|
actual := gjson.Parse(cmdx.ExecNoErr(t, c, expected.GetID(), expected.ID))
|
|
snapshotx.SnapshotT(t, json.RawMessage(actual.Raw), snapshotExcludedClientFields...)
|
|
})
|
|
}
|