Skip to content

Commit

Permalink
Add 'Users.People' helper
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Nov 3, 2024
1 parent f77bb28 commit 939a92e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pachca.go
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,19 @@ func (u Users) Bots() Users {
return result
}

// People returns slice with non-bot users
func (u Users) People() Users {
var result Users

for _, uu := range u {
if !uu.IsBot {
result = append(result, uu)
}
}

return result
}

// Admins returns slice with admins
func (u Users) Admins() Users {
var result Users
Expand Down
4 changes: 4 additions & 0 deletions pachca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,16 @@ func (s *PachcaSuite) TestUsersHelpers(c *C) {

c.Assert(uu.Invited(), HasLen, 1)
c.Assert(uu.Invited()[0].ID, Equals, uint64(1))
c.Assert(uu.Bots(), HasLen, 1)
c.Assert(uu.Bots()[0].ID, Equals, uint64(5))
c.Assert(uu.People(), HasLen, 5)
c.Assert(uu.Admins(), HasLen, 1)
c.Assert(uu.Admins()[0].ID, Equals, uint64(3))
c.Assert(uu.Admins()[0].IsAdmin(), Equals, true)
c.Assert(uu.Regular(), HasLen, 4)
c.Assert(uu.Regular()[0].ID, Equals, uint64(1))
c.Assert(uu.Regular()[0].IsRegular(), Equals, true)
c.Assert(uu.Guests(), HasLen, 1)
c.Assert(uu.Guests()[0].ID, Equals, uint64(4))
c.Assert(uu.Guests()[0].IsGuest(), Equals, true)

Expand Down

0 comments on commit 939a92e

Please sign in to comment.