-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding test for add user and remove user
- Loading branch information
1 parent
546494b
commit 323dab2
Showing
2 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,25 +207,23 @@ func TestUserResource_CreateUser(t *testing.T) { | |
func TestGroupResource_AddUserToGroup(t *testing.T) { | ||
t.Run("should err if group doesn't exist", func(t *testing.T) { | ||
userEmailArg := "[email protected]" | ||
groupNameArg := "NonexistentUser" | ||
|
||
client := NewClient() | ||
client.User.CreateUser(userEmailArg) | ||
user, _ := client.User.CreateUser(userEmailArg) | ||
|
||
_, err := client.Group.AddUserToGroup(context.TODO(), groupNameArg, userEmailArg) | ||
_, err := client.Group.AddUserToGroup(context.TODO(), "1", user.Id) | ||
|
||
if err == nil { | ||
t.Errorf("expected error but didn't get one") | ||
} | ||
}) | ||
|
||
t.Run("should err if user doesn't exist", func(t *testing.T) { | ||
userEmailArg := "NonexistentUser" | ||
groupNameArg := "TestGroup" | ||
|
||
client := NewClient() | ||
group, _, _ := client.Group.CreateGroup(context.TODO(), *NewGroup(groupNameArg)) | ||
_, err := client.Group.AddUserToGroup(context.TODO(), group.Id, userEmailArg) | ||
_, err := client.Group.AddUserToGroup(context.TODO(), group.Id, "1") | ||
|
||
if err == nil { | ||
t.Errorf("expected error but didn't get one %v", err) | ||
|
@@ -247,6 +245,74 @@ func TestGroupResource_AddUserToGroup(t *testing.T) { | |
} | ||
}) | ||
} | ||
func TestGroupResource_RemoveUserFromGroup(t *testing.T) { | ||
t.Run("should err if group doesn't exist", func(t *testing.T) { | ||
userEmailArg := "[email protected]" | ||
|
||
client := NewClient() | ||
user, _ := client.User.CreateUser(userEmailArg) | ||
|
||
_, err := client.Group.RemoveUserFromGroup(context.TODO(), "1", user.Id) | ||
|
||
if err == nil { | ||
t.Errorf("expected error but didn't get one") | ||
} | ||
}) | ||
|
||
t.Run("should err if user doesn't exist", func(t *testing.T) { | ||
groupNameArg := "TestGroup" | ||
|
||
client := NewClient() | ||
group, _, _ := client.Group.CreateGroup(context.TODO(), *NewGroup(groupNameArg)) | ||
_, err := client.Group.RemoveUserFromGroup(context.TODO(), group.Id, "1") | ||
|
||
if err == nil { | ||
t.Errorf("expected error but didn't get one %v", err) | ||
} | ||
}) | ||
|
||
t.Run("should remove user from group", func(t *testing.T) { | ||
userEmailArg := "[email protected]" | ||
groupNameArg := "TestGroup" | ||
|
||
client := NewClient() | ||
group, _, _ := client.Group.CreateGroup(context.TODO(), *NewGroup(groupNameArg)) | ||
user, _ := client.User.CreateUser(userEmailArg) | ||
|
||
client.Group.RemoveUserFromGroup(context.TODO(), group.Id, user.Id) | ||
|
||
if client.Group.GroupContainsUser(*group, userEmailArg) { | ||
t.Errorf("expected group %v to not contain user %v", groupNameArg, userEmailArg) | ||
} | ||
}) | ||
t.Run("should not remove other users", func(t *testing.T) { | ||
userEmailArg1 := "[email protected]" | ||
userEmailArg2 := "[email protected]" | ||
userEmailArg3 := "[email protected]" | ||
|
||
groupNameArg := "TestGroup" | ||
|
||
client := NewClient() | ||
group, _, _ := client.Group.CreateGroup(context.TODO(), *NewGroup(groupNameArg)) | ||
user1, _ := client.User.CreateUser(userEmailArg1) | ||
user2, _ := client.User.CreateUser(userEmailArg2) | ||
user3, _ := client.User.CreateUser(userEmailArg3) | ||
|
||
client.Group.AddUserToGroup(context.TODO(), group.Id, user1.Id) | ||
client.Group.AddUserToGroup(context.TODO(), group.Id, user2.Id) | ||
client.Group.AddUserToGroup(context.TODO(), group.Id, user3.Id) | ||
|
||
client.Group.RemoveUserFromGroup(context.TODO(), group.Id, user2.Id) | ||
|
||
want := 2 | ||
got := len(client.Group.GroupUsers[group.Profile.Name]) | ||
|
||
if got != want { | ||
t.Errorf("expected group %v to have %d users but found %d", groupNameArg, want, got) | ||
} | ||
}) | ||
|
||
} | ||
|
||
func TestUserResource_ListUsers(t *testing.T) { | ||
client := NewClient() | ||
|