MCPcopy Create free account
hub / github.com/gogs/gogs / orgsList

Function orgsList

internal/database/organizations_test.go:45–113  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, s *OrganizationsStore)

Source from the content-addressed store, hash-verified

43}
44
45func orgsList(t *testing.T, ctx context.Context, s *OrganizationsStore) {
46 usersStore := newUsersStore(s.db)
47 alice, err := usersStore.Create(ctx, "alice", "alice@example.com", CreateUserOptions{})
48 require.NoError(t, err)
49 bob, err := usersStore.Create(ctx, "bob", "bob@example.com", CreateUserOptions{})
50 require.NoError(t, err)
51
52 // TODO: Use Orgs.Create to replace SQL hack when the method is available.
53 org1, err := usersStore.Create(ctx, "org1", "org1@example.com", CreateUserOptions{})
54 require.NoError(t, err)
55 org2, err := usersStore.Create(ctx, "org2", "org2@example.com", CreateUserOptions{})
56 require.NoError(t, err)
57 err = s.db.Exec(
58 dbutil.Quote("UPDATE %s SET type = ? WHERE id IN (?, ?)", "user"),
59 UserTypeOrganization, org1.ID, org2.ID,
60 ).Error
61 require.NoError(t, err)
62
63 // TODO: Use Orgs.Join to replace SQL hack when the method is available.
64 err = s.db.Exec(`INSERT INTO org_user (uid, org_id, is_public) VALUES (?, ?, ?)`, alice.ID, org1.ID, false).Error
65 require.NoError(t, err)
66 err = s.db.Exec(`INSERT INTO org_user (uid, org_id, is_public) VALUES (?, ?, ?)`, alice.ID, org2.ID, true).Error
67 require.NoError(t, err)
68 err = s.db.Exec(`INSERT INTO org_user (uid, org_id, is_public) VALUES (?, ?, ?)`, bob.ID, org2.ID, true).Error
69 require.NoError(t, err)
70
71 tests := []struct {
72 name string
73 opts ListOrgsOptions
74 wantOrgNames []string
75 }{
76 {
77 name: "only public memberships for a user",
78 opts: ListOrgsOptions{
79 MemberID: alice.ID,
80 IncludePrivateMembers: false,
81 },
82 wantOrgNames: []string{org2.Name},
83 },
84 {
85 name: "all memberships for a user",
86 opts: ListOrgsOptions{
87 MemberID: alice.ID,
88 IncludePrivateMembers: true,
89 },
90 wantOrgNames: []string{org1.Name, org2.Name},
91 },
92 {
93 name: "no membership for a non-existent user",
94 opts: ListOrgsOptions{
95 MemberID: 404,
96 IncludePrivateMembers: true,
97 },
98 wantOrgNames: []string{},
99 },
100 }
101 for _, test := range tests {
102 t.Run(test.name, func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

QuoteFunction · 0.92
newUsersStoreFunction · 0.85
ExecMethod · 0.80
ListMethod · 0.65
CreateMethod · 0.45

Tested by

no test coverage detected