MCPcopy Create free account
hub / github.com/auth0/auth0-cli / TestGetUserRoles

Function TestGetUserRoles

internal/cli/users_roles_test.go:16–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestGetUserRoles(t *testing.T) {
17 t.Run("gets user roles", func(t *testing.T) {
18 inputs := &userRolesInput{
19 ID: "some-id",
20 Roles: []string{},
21 }
22 userRolesFetcher := func(ctx context.Context, cli *cli, userID string) ([]string, error) {
23 assert.Equal(t, userID, "some-id")
24 return []string{"some-id-1", "some-id-2"}, nil
25 }
26 userRolesSelector := func(options []string) ([]string, error) {
27 assert.Equal(t, options, []string{"some-id-1", "some-id-2"})
28 return []string{"some-id-3 (Name: some-name-3)", "some-id-4 (Name: some-name-4)"}, nil
29 }
30 cli := &cli{}
31 err := cli.getUserRoles(context.Background(), inputs, userRolesFetcher, userRolesSelector)
32
33 assert.Equal(t, inputs.Roles, []string{"some-id-3", "some-id-4"})
34 assert.Nil(t, err)
35 })
36
37 t.Run("returns error when user roles fetcher fails", func(t *testing.T) {
38 inputs := &userRolesInput{Roles: []string{}}
39 userRolesFetcher := func(ctx context.Context, cli *cli, userID string) ([]string, error) {
40 return nil, errors.New("error")
41 }
42 cli := &cli{}
43 err := cli.getUserRoles(context.Background(), inputs, userRolesFetcher, nil)
44
45 assert.Error(t, err)
46 })
47
48 t.Run("returns error when user roles selector fails", func(t *testing.T) {
49 inputs := &userRolesInput{Roles: []string{}}
50 userRolesFetcher := func(ctx context.Context, cli *cli, userID string) ([]string, error) {
51 return []string{}, nil
52 }
53 userRolesSelector := func(options []string) ([]string, error) {
54 return nil, errors.New("error")
55 }
56 cli := &cli{}
57 err := cli.getUserRoles(context.Background(), inputs, userRolesFetcher, userRolesSelector)
58
59 assert.Error(t, err)
60 })
61
62 t.Run("returns error when no roles where selected", func(t *testing.T) {
63 inputs := &userRolesInput{Roles: []string{}}
64 userRolesFetcher := func(ctx context.Context, cli *cli, userID string) ([]string, error) {
65 return []string{"some-id-1", "some-id-2"}, nil
66 }
67 userRolesSelector := func(options []string) ([]string, error) {
68 return []string{}, nil
69 }
70 cli := &cli{}
71 err := cli.getUserRoles(context.Background(), inputs, userRolesFetcher, userRolesSelector)
72
73 assert.ErrorIs(t, err, errNoRolesSelected)

Callers

nothing calls this directly

Calls 2

getUserRolesMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected