MCPcopy Index your code
hub / github.com/coder/coder / Assert

Method Assert

coderd/idpsync/group_test.go:888–924  ·  view source on GitHub ↗
(t *testing.T, orgID uuid.UUID, db database.Store, user database.User)

Source from the content-addressed store, hash-verified

886}
887
888func (o *orgGroupAssert) Assert(t *testing.T, orgID uuid.UUID, db database.Store, user database.User) {
889 t.Helper()
890
891 ctx := context.Background()
892
893 userGroups, err := db.GetGroups(ctx, database.GetGroupsParams{
894 OrganizationID: orgID,
895 HasMemberID: user.ID,
896 })
897 require.NoError(t, err)
898 if o.ExpectedGroups == nil {
899 o.ExpectedGroups = make([]uuid.UUID, 0)
900 }
901 if len(o.ExpectedGroupNames) > 0 && len(o.ExpectedGroups) > 0 {
902 t.Fatal("ExpectedGroups and ExpectedGroupNames are mutually exclusive")
903 }
904
905 // Everyone groups mess up our asserts
906 userGroups = slices.DeleteFunc(userGroups, func(row database.GetGroupsRow) bool {
907 return row.Group.ID == row.Group.OrganizationID
908 })
909
910 if len(o.ExpectedGroupNames) > 0 {
911 found := slice.List(userGroups, func(g database.GetGroupsRow) string {
912 return g.Group.Name
913 })
914 require.ElementsMatch(t, o.ExpectedGroupNames, found, "user groups by name")
915 require.Len(t, o.ExpectedGroups, 0, "ExpectedGroups should be empty")
916 } else {
917 // Check by ID, recommended
918 found := slice.List(userGroups, func(g database.GetGroupsRow) uuid.UUID {
919 return g.Group.ID
920 })
921 require.ElementsMatch(t, o.ExpectedGroups, found, "user groups")
922 require.Len(t, o.ExpectedGroupNames, 0, "ExpectedGroupNames should be empty")
923 }
924}
925
926//nolint:revive
927func (o orgRoleAssert) Assert(t *testing.T, orgID uuid.UUID, db database.Store, notMember bool, user database.User) {

Callers

nothing calls this directly

Calls 5

ListFunction · 0.92
FatalMethod · 0.80
HelperMethod · 0.65
GetGroupsMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected