(t *testing.T)
| 31 | } |
| 32 | |
| 33 | func TestImportClient(t *testing.T) { |
| 34 | t.Context() |
| 35 | |
| 36 | c := cmd.NewImportClientCmd() |
| 37 | reg := setup(t, c) |
| 38 | |
| 39 | file1 := writeTempFile(t, []hydra.OAuth2Client{{Scope: new("foo")}, {Scope: new("bar"), ClientSecret: new("some-secret")}}) |
| 40 | file2 := writeTempFile(t, []hydra.OAuth2Client{{Scope: new("baz")}, {Scope: new("zab"), ClientSecret: new("some-secret")}}) |
| 41 | |
| 42 | t.Run("case=imports clients from single file", func(t *testing.T) { |
| 43 | actual := gjson.Parse(cmdx.ExecNoErr(t, c, file1)) |
| 44 | require.Len(t, actual.Array(), 2) |
| 45 | assert.NotEmpty(t, actual.Get("0.client_id").String()) |
| 46 | assert.NotEmpty(t, actual.Get("0.client_secret").String()) |
| 47 | assert.Equal(t, "some-secret", actual.Get("1.client_secret").String()) |
| 48 | |
| 49 | _, err := reg.ClientManager().GetClient(t.Context(), actual.Get("0.client_id").String()) |
| 50 | require.NoError(t, err) |
| 51 | |
| 52 | _, err = reg.ClientManager().GetClient(t.Context(), actual.Get("1.client_id").String()) |
| 53 | require.NoError(t, err) |
| 54 | |
| 55 | snapshotx.SnapshotT(t, json.RawMessage(actual.Raw), snapshotExcludedClientFields...) |
| 56 | }) |
| 57 | |
| 58 | t.Run("case=imports clients from multiple files", func(t *testing.T) { |
| 59 | actual := gjson.Parse(cmdx.ExecNoErr(t, c, file1, file2)) |
| 60 | require.Len(t, actual.Array(), 4) |
| 61 | |
| 62 | for _, v := range []string{ |
| 63 | "foo", "bar", "baz", "zab", |
| 64 | } { |
| 65 | found := false |
| 66 | for _, j := range actual.Array() { |
| 67 | if j.Get("scope").String() == v { |
| 68 | found = true |
| 69 | break |
| 70 | } |
| 71 | } |
| 72 | assert.True(t, found, "missing client with scope %s", v) |
| 73 | } |
| 74 | }) |
| 75 | |
| 76 | t.Run("case=imports clients from multiple files and stdin", func(t *testing.T) { |
| 77 | var stdin bytes.Buffer |
| 78 | require.NoError(t, json.NewEncoder(&stdin).Encode([]hydra.OAuth2Client{{Scope: new("oof")}, {Scope: new("rab"), ClientSecret: new("some-secret")}})) |
| 79 | |
| 80 | stdout, _, err := cmdx.Exec(t, c, &stdin, file1, file2) |
| 81 | require.NoError(t, err) |
| 82 | actual := gjson.Parse(stdout) |
| 83 | require.Len(t, actual.Array(), 6) |
| 84 | var found bool |
| 85 | for _, v := range actual.Array() { |
| 86 | if v.Get("scope").String() == "oof" { |
| 87 | found = true |
| 88 | } |
| 89 | } |
| 90 | assert.True(t, found) |
nothing calls this directly
no test coverage detected