Skip to content

Commit 514fcdf

Browse files
committed
small refactors
1 parent dda30ec commit 514fcdf

File tree

3 files changed

+22
-51
lines changed

3 files changed

+22
-51
lines changed

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,24 +640,18 @@ func (s *MethodTestSuite) TestOrganization() {
640640
rbac.ResourceOrganizationMember.InOrg(o.ID).WithID(u.ID), policy.ActionCreate)
641641
}))
642642
s.Run("UpdateOrganization", s.Subtest(func(db database.Store, check *expects) {
643-
ctx := testutil.Context(s.T(), testutil.WaitShort)
644-
o, err := db.InsertOrganization(ctx, database.InsertOrganizationParams{
645-
ID: uuid.New(),
643+
o := dbgen.Organization(s.T(), db, database.Organization{
646644
Name: "something-unique",
647645
})
648-
require.NoError(s.T(), err)
649646
check.Args(database.UpdateOrganizationParams{
650647
ID: o.ID,
651648
Name: "something-different",
652649
}).Asserts(o, policy.ActionUpdate)
653650
}))
654651
s.Run("DeleteOrganization", s.Subtest(func(db database.Store, check *expects) {
655-
ctx := testutil.Context(s.T(), testutil.WaitShort)
656-
o, err := db.InsertOrganization(ctx, database.InsertOrganizationParams{
657-
ID: uuid.New(),
652+
o := dbgen.Organization(s.T(), db, database.Organization{
658653
Name: "doomed",
659654
})
660-
require.NoError(s.T(), err)
661655
check.Args(
662656
o.ID,
663657
).Asserts(o, policy.ActionDelete)

coderd/database/dbmem/dbmem.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,9 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
15741574
}
15751575

15761576
func (q *FakeQuerier) DeleteOrganization(_ context.Context, id uuid.UUID) error {
1577+
q.mutex.Lock()
1578+
defer q.mutex.Unlock()
1579+
15771580
for i, org := range q.organizations {
15781581
if org.ID == id && !org.IsDefault {
15791582
q.organizations = append(q.organizations[:i], q.organizations[i+1:]...)
@@ -7159,6 +7162,9 @@ func (q *FakeQuerier) UpdateOrganization(_ context.Context, arg database.UpdateO
71597162
return database.Organization{}, err
71607163
}
71617164

7165+
q.mutex.Lock()
7166+
defer q.mutex.Unlock()
7167+
71627168
for i, org := range q.organizations {
71637169
if org.ID == arg.ID {
71647170
org.Name = arg.Name

coderd/organizations_test.go

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package coderd_test
22

33
import (
4-
"context"
54
"net/http"
65
"testing"
76

@@ -16,9 +15,7 @@ func TestMultiOrgFetch(t *testing.T) {
1615
t.Parallel()
1716
client := coderdtest.New(t, nil)
1817
_ = coderdtest.CreateFirstUser(t, client)
19-
20-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
21-
defer cancel()
18+
ctx := testutil.Context(t, testutil.WaitLong)
2219

2320
makeOrgs := []string{"foo", "bar", "baz"}
2421
for _, name := range makeOrgs {
@@ -38,9 +35,7 @@ func TestOrganizationsByUser(t *testing.T) {
3835
t.Parallel()
3936
client := coderdtest.New(t, nil)
4037
_ = coderdtest.CreateFirstUser(t, client)
41-
42-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
43-
defer cancel()
38+
ctx := testutil.Context(t, testutil.WaitLong)
4439

4540
orgs, err := client.OrganizationsByUser(ctx, codersdk.Me)
4641
require.NoError(t, err)
@@ -62,9 +57,7 @@ func TestOrganizationByUserAndName(t *testing.T) {
6257
t.Parallel()
6358
client := coderdtest.New(t, nil)
6459
coderdtest.CreateFirstUser(t, client)
65-
66-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
67-
defer cancel()
60+
ctx := testutil.Context(t, testutil.WaitLong)
6861

6962
_, err := client.OrganizationByUserAndName(ctx, codersdk.Me, "nothing")
7063
var apiErr *codersdk.Error
@@ -77,9 +70,7 @@ func TestOrganizationByUserAndName(t *testing.T) {
7770
client := coderdtest.New(t, nil)
7871
first := coderdtest.CreateFirstUser(t, client)
7972
other, _ := coderdtest.CreateAnotherUser(t, client, first.OrganizationID)
80-
81-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
82-
defer cancel()
73+
ctx := testutil.Context(t, testutil.WaitLong)
8374

8475
org, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
8576
Name: "another",
@@ -95,9 +86,7 @@ func TestOrganizationByUserAndName(t *testing.T) {
9586
t.Parallel()
9687
client := coderdtest.New(t, nil)
9788
user := coderdtest.CreateFirstUser(t, client)
98-
99-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
100-
defer cancel()
89+
ctx := testutil.Context(t, testutil.WaitLong)
10190

10291
org, err := client.Organization(ctx, user.OrganizationID)
10392
require.NoError(t, err)
@@ -112,9 +101,7 @@ func TestPostOrganizationsByUser(t *testing.T) {
112101
t.Parallel()
113102
client := coderdtest.New(t, nil)
114103
user := coderdtest.CreateFirstUser(t, client)
115-
116-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
117-
defer cancel()
104+
ctx := testutil.Context(t, testutil.WaitLong)
118105

119106
org, err := client.Organization(ctx, user.OrganizationID)
120107
require.NoError(t, err)
@@ -130,9 +117,7 @@ func TestPostOrganizationsByUser(t *testing.T) {
130117
t.Parallel()
131118
client := coderdtest.New(t, nil)
132119
_ = coderdtest.CreateFirstUser(t, client)
133-
134-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
135-
defer cancel()
120+
ctx := testutil.Context(t, testutil.WaitLong)
136121

137122
_, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
138123
Name: "new",
@@ -147,9 +132,7 @@ func TestPatchOrganizationsByUser(t *testing.T) {
147132
t.Parallel()
148133
client := coderdtest.New(t, nil)
149134
user := coderdtest.CreateFirstUser(t, client)
150-
151-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
152-
defer cancel()
135+
ctx := testutil.Context(t, testutil.WaitMedium)
153136

154137
originalOrg, err := client.Organization(ctx, user.OrganizationID)
155138
require.NoError(t, err)
@@ -170,9 +153,7 @@ func TestPatchOrganizationsByUser(t *testing.T) {
170153
t.Parallel()
171154
client := coderdtest.New(t, nil)
172155
_ = coderdtest.CreateFirstUser(t, client)
173-
174-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
175-
defer cancel()
156+
ctx := testutil.Context(t, testutil.WaitMedium)
176157

177158
o, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
178159
Name: "something-unique",
@@ -191,9 +172,7 @@ func TestPatchOrganizationsByUser(t *testing.T) {
191172
t.Parallel()
192173
client := coderdtest.New(t, nil)
193174
_ = coderdtest.CreateFirstUser(t, client)
194-
195-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
196-
defer cancel()
175+
ctx := testutil.Context(t, testutil.WaitMedium)
197176

198177
o, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
199178
Name: "new",
@@ -211,9 +190,7 @@ func TestPatchOrganizationsByUser(t *testing.T) {
211190
t.Parallel()
212191
client := coderdtest.New(t, nil)
213192
_ = coderdtest.CreateFirstUser(t, client)
214-
215-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
216-
defer cancel()
193+
ctx := testutil.Context(t, testutil.WaitMedium)
217194

218195
o, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
219196
Name: "new",
@@ -234,9 +211,7 @@ func TestDeleteOrganizationsByUser(t *testing.T) {
234211
t.Parallel()
235212
client := coderdtest.New(t, nil)
236213
user := coderdtest.CreateFirstUser(t, client)
237-
238-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
239-
defer cancel()
214+
ctx := testutil.Context(t, testutil.WaitMedium)
240215

241216
o, err := client.Organization(ctx, user.OrganizationID)
242217
require.NoError(t, err)
@@ -251,9 +226,7 @@ func TestDeleteOrganizationsByUser(t *testing.T) {
251226
t.Parallel()
252227
client := coderdtest.New(t, nil)
253228
_ = coderdtest.CreateFirstUser(t, client)
254-
255-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
256-
defer cancel()
229+
ctx := testutil.Context(t, testutil.WaitMedium)
257230

258231
o, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
259232
Name: "doomed",
@@ -268,9 +241,7 @@ func TestDeleteOrganizationsByUser(t *testing.T) {
268241
t.Parallel()
269242
client := coderdtest.New(t, nil)
270243
_ = coderdtest.CreateFirstUser(t, client)
271-
272-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
273-
defer cancel()
244+
ctx := testutil.Context(t, testutil.WaitMedium)
274245

275246
o, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
276247
Name: "doomed",

0 commit comments

Comments
 (0)