From 939a92e359ea6a057ecf2f3d3c5bd2b8358d8af1 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sun, 3 Nov 2024 15:12:11 +0300 Subject: [PATCH] Add 'Users.People' helper --- pachca.go | 13 +++++++++++++ pachca_test.go | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/pachca.go b/pachca.go index 1e39883..08e1584 100644 --- a/pachca.go +++ b/pachca.go @@ -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 diff --git a/pachca_test.go b/pachca_test.go index 9614465..3f5d245 100644 --- a/pachca_test.go +++ b/pachca_test.go @@ -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)