Skip to content

Commit

Permalink
fixing mock okta test to add a user before testing if it remove user …
Browse files Browse the repository at this point in the history
…removes it
  • Loading branch information
pputman-clabs committed Jan 8, 2023
1 parent 323dab2 commit 2576f1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 17 additions & 0 deletions mockokta.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (client *MockClient) ListGroups(ctx context.Context, qp *query.Params) ([]*
return client.Group.ListGroups(ctx, qp)
}

func (client *MockClient) ListGroupUsers(ctx context.Context, groupId string, qp *query.Params) ([]*okta.User, *okta.Response, error) {
return client.Group.ListGroupUsers(ctx, groupId, qp)
}

func (client *MockClient) ListGroupAssignedRoles(ctx context.Context, groupId string, qp *query.Params) ([]*okta.Role, *okta.Response, error) {
return client.Group.ListGroupAssignedRoles(ctx, groupId, qp)
}
Expand Down Expand Up @@ -173,6 +177,19 @@ func (g *GroupResource) GroupContainsRole(group okta.Group, roleType string) boo
return false
}

func (g *GroupResource) ListGroupUsers(ctx context.Context, groupId string, qp *query.Params) ([]*okta.User, *okta.Response, error) {
group, err := g.GetGroupById(groupId)
if err != nil {
return nil, nil, err
}
var users []*okta.User
for _, user := range g.GroupUsers[group.Profile.Name] {
user, _ := g.Client.User.GetUserByEmail(user)
users = append(users, user)
}
return users, nil, nil
}

func (g *GroupResource) GroupContainsUser(group okta.Group, userEmail string) bool {
for _, groupUser := range g.GroupUsers[group.Profile.Name] {
if groupUser == userEmail {
Expand Down
5 changes: 3 additions & 2 deletions mockokta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/rand"
"reflect"
"testing"
"log"
"time"

"github.com/okta/okta-sdk-golang/v2/okta"
Expand Down Expand Up @@ -267,7 +268,7 @@ func TestGroupResource_RemoveUserFromGroup(t *testing.T) {
_, err := client.Group.RemoveUserFromGroup(context.TODO(), group.Id, "1")

if err == nil {
t.Errorf("expected error but didn't get one %v", err)
t.Errorf("expected error but didn't get one")
}
})

Expand All @@ -278,6 +279,7 @@ func TestGroupResource_RemoveUserFromGroup(t *testing.T) {
client := NewClient()
group, _, _ := client.Group.CreateGroup(context.TODO(), *NewGroup(groupNameArg))
user, _ := client.User.CreateUser(userEmailArg)
client.Group.AddUserToGroup(context.TODO(), group.Id, user.Id)

client.Group.RemoveUserFromGroup(context.TODO(), group.Id, user.Id)

Expand Down Expand Up @@ -311,7 +313,6 @@ func TestGroupResource_RemoveUserFromGroup(t *testing.T) {
t.Errorf("expected group %v to have %d users but found %d", groupNameArg, want, got)
}
})

}

func TestUserResource_ListUsers(t *testing.T) {
Expand Down

0 comments on commit 2576f1c

Please sign in to comment.