Skip to content

Commit 7841619

Browse files
committed
address linter complaints in group*_test.go
1 parent c90a71c commit 7841619

File tree

4 files changed

+38
-66
lines changed

4 files changed

+38
-66
lines changed

enterprise/cli/groupcreate_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"github.com/coder/coder/v2/cli/clitest"
1212
"github.com/coder/coder/v2/cli/cliui"
13+
"github.com/coder/coder/v2/coderd/coderdtest"
14+
"github.com/coder/coder/v2/coderd/rbac"
1315
"github.com/coder/coder/v2/codersdk"
1416
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
1517
"github.com/coder/coder/v2/enterprise/coderd/license"
@@ -22,11 +24,12 @@ func TestCreateGroup(t *testing.T) {
2224
t.Run("OK", func(t *testing.T) {
2325
t.Parallel()
2426

25-
client, _ := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
27+
client, admin := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
2628
Features: license.Features{
2729
codersdk.FeatureTemplateRBAC: 1,
2830
},
2931
}})
32+
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID, rbac.RoleUserAdmin())
3033

3134
var (
3235
groupName = "test"
@@ -40,7 +43,7 @@ func TestCreateGroup(t *testing.T) {
4043

4144
pty := ptytest.New(t)
4245
inv.Stdout = pty.Output()
43-
clitest.SetupConfig(t, client, conf)
46+
clitest.SetupConfig(t, anotherClient, conf)
4447

4548
err := inv.Run()
4649
require.NoError(t, err)

enterprise/cli/groupdelete_test.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010

1111
"github.com/coder/coder/v2/cli/clitest"
1212
"github.com/coder/coder/v2/cli/cliui"
13+
"github.com/coder/coder/v2/coderd/coderdtest"
14+
"github.com/coder/coder/v2/coderd/rbac"
1315
"github.com/coder/coder/v2/codersdk"
1416
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
1517
"github.com/coder/coder/v2/enterprise/coderd/license"
1618
"github.com/coder/coder/v2/pty/ptytest"
17-
"github.com/coder/coder/v2/testutil"
1819
)
1920

2021
func TestGroupDelete(t *testing.T) {
@@ -28,12 +29,9 @@ func TestGroupDelete(t *testing.T) {
2829
codersdk.FeatureTemplateRBAC: 1,
2930
},
3031
}})
32+
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID, rbac.RoleUserAdmin())
3133

32-
ctx := testutil.Context(t, testutil.WaitLong)
33-
group, err := client.CreateGroup(ctx, admin.OrganizationID, codersdk.CreateGroupRequest{
34-
Name: "alpha",
35-
})
36-
require.NoError(t, err)
34+
group := coderdtest.CreateGroup(t, client, admin.OrganizationID, "alpha")
3735

3836
inv, conf := newCLI(t,
3937
"groups", "delete", group.Name,
@@ -42,9 +40,9 @@ func TestGroupDelete(t *testing.T) {
4240
pty := ptytest.New(t)
4341

4442
inv.Stdout = pty.Output()
45-
clitest.SetupConfig(t, client, conf)
43+
clitest.SetupConfig(t, anotherClient, conf)
4644

47-
err = inv.Run()
45+
err := inv.Run()
4846
require.NoError(t, err)
4947

5048
pty.ExpectMatch(fmt.Sprintf("Successfully deleted group %s", pretty.Sprint(cliui.DefaultStyles.Keyword, group.Name)))
@@ -53,18 +51,19 @@ func TestGroupDelete(t *testing.T) {
5351
t.Run("NoArg", func(t *testing.T) {
5452
t.Parallel()
5553

56-
client, _ := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
54+
client, admin := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
5755
Features: license.Features{
5856
codersdk.FeatureTemplateRBAC: 1,
5957
},
6058
}})
59+
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID, rbac.RoleUserAdmin())
6160

6261
inv, conf := newCLI(
6362
t,
6463
"groups", "delete",
6564
)
6665

67-
clitest.SetupConfig(t, client, conf)
66+
clitest.SetupConfig(t, anotherClient, conf)
6867

6968
err := inv.Run()
7069
require.Error(t, err)

enterprise/cli/groupedit_test.go

+14-28
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"github.com/coder/coder/v2/cli/clitest"
1212
"github.com/coder/coder/v2/cli/cliui"
1313
"github.com/coder/coder/v2/coderd/coderdtest"
14+
"github.com/coder/coder/v2/coderd/rbac"
1415
"github.com/coder/coder/v2/codersdk"
1516
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
1617
"github.com/coder/coder/v2/enterprise/coderd/license"
1718
"github.com/coder/coder/v2/pty/ptytest"
18-
"github.com/coder/coder/v2/testutil"
1919
)
2020

2121
func TestGroupEdit(t *testing.T) {
@@ -29,23 +29,13 @@ func TestGroupEdit(t *testing.T) {
2929
codersdk.FeatureTemplateRBAC: 1,
3030
},
3131
}})
32+
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID, rbac.RoleUserAdmin())
3233

33-
ctx := testutil.Context(t, testutil.WaitLong)
3434
_, user1 := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
3535
_, user2 := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
3636
_, user3 := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
3737

38-
group, err := client.CreateGroup(ctx, admin.OrganizationID, codersdk.CreateGroupRequest{
39-
Name: "alpha",
40-
})
41-
require.NoError(t, err)
42-
43-
// We use the sdk here as opposed to the CLI since adding this user
44-
// is considered setup. They will be removed in the proper CLI test.
45-
group, err = client.PatchGroup(ctx, group.ID, codersdk.PatchGroupRequest{
46-
AddUsers: []string{user3.ID.String()},
47-
})
48-
require.NoError(t, err)
38+
group := coderdtest.CreateGroup(t, client, admin.OrganizationID, "alpha", user3)
4939

5040
expectedName := "beta"
5141

@@ -62,9 +52,9 @@ func TestGroupEdit(t *testing.T) {
6252
pty := ptytest.New(t)
6353

6454
inv.Stdout = pty.Output()
65-
clitest.SetupConfig(t, client, conf)
55+
clitest.SetupConfig(t, anotherClient, conf)
6656

67-
err = inv.Run()
57+
err := inv.Run()
6858
require.NoError(t, err)
6959

7060
pty.ExpectMatch(fmt.Sprintf("Successfully patched group %s", pretty.Sprint(cliui.DefaultStyles.Keyword, expectedName)))
@@ -79,39 +69,35 @@ func TestGroupEdit(t *testing.T) {
7969
},
8070
}})
8171

82-
ctx := testutil.Context(t, testutil.WaitLong)
83-
84-
group, err := client.CreateGroup(ctx, admin.OrganizationID, codersdk.CreateGroupRequest{
85-
Name: "alpha",
86-
})
87-
require.NoError(t, err)
72+
// Create a group with no members.
73+
group := coderdtest.CreateGroup(t, client, admin.OrganizationID, "alpha")
8874

8975
inv, conf := newCLI(
9076
t,
9177
"groups", "edit", group.Name,
9278
"-a", "foo",
9379
)
9480

95-
clitest.SetupConfig(t, client, conf)
81+
clitest.SetupConfig(t, client, conf) //nolint:gocritic // intentional usage of owner
9682

97-
err = inv.Run()
98-
require.Error(t, err)
99-
require.Contains(t, err.Error(), "must be a valid UUID or email address")
83+
err := inv.Run()
84+
require.ErrorContains(t, err, "must be a valid UUID or email address")
10085
})
10186

10287
t.Run("NoArg", func(t *testing.T) {
10388
t.Parallel()
10489

105-
client, _ := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
90+
client, user := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
10691
Features: license.Features{
10792
codersdk.FeatureTemplateRBAC: 1,
10893
},
10994
}})
95+
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleUserAdmin())
11096

11197
inv, conf := newCLI(t, "groups", "edit")
112-
clitest.SetupConfig(t, client, conf)
98+
clitest.SetupConfig(t, anotherClient, conf)
11399

114100
err := inv.Run()
115-
require.Error(t, err)
101+
require.ErrorContains(t, err, "wanted 1 args but got 0")
116102
})
117103
}

enterprise/cli/grouplist_test.go

+10-26
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77

88
"github.com/coder/coder/v2/cli/clitest"
99
"github.com/coder/coder/v2/coderd/coderdtest"
10+
"github.com/coder/coder/v2/coderd/rbac"
1011
"github.com/coder/coder/v2/codersdk"
1112
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
1213
"github.com/coder/coder/v2/enterprise/coderd/license"
1314
"github.com/coder/coder/v2/pty/ptytest"
14-
"github.com/coder/coder/v2/testutil"
1515
)
1616

1717
func TestGroupList(t *testing.T) {
@@ -25,42 +25,25 @@ func TestGroupList(t *testing.T) {
2525
codersdk.FeatureTemplateRBAC: 1,
2626
},
2727
}})
28+
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID, rbac.RoleUserAdmin())
2829

29-
ctx := testutil.Context(t, testutil.WaitLong)
3030
_, user1 := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
3131
_, user2 := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
3232

3333
// We intentionally create the first group as beta so that we
3434
// can assert that things are being sorted by name intentionally
3535
// and not by chance (or some other parameter like created_at).
36-
group1, err := client.CreateGroup(ctx, admin.OrganizationID, codersdk.CreateGroupRequest{
37-
Name: "beta",
38-
})
39-
require.NoError(t, err)
40-
41-
group2, err := client.CreateGroup(ctx, admin.OrganizationID, codersdk.CreateGroupRequest{
42-
Name: "alpha",
43-
})
44-
require.NoError(t, err)
45-
46-
_, err = client.PatchGroup(ctx, group1.ID, codersdk.PatchGroupRequest{
47-
AddUsers: []string{user1.ID.String()},
48-
})
49-
require.NoError(t, err)
50-
51-
_, err = client.PatchGroup(ctx, group2.ID, codersdk.PatchGroupRequest{
52-
AddUsers: []string{user2.ID.String()},
53-
})
54-
require.NoError(t, err)
36+
group1 := coderdtest.CreateGroup(t, client, admin.OrganizationID, "beta", user1)
37+
group2 := coderdtest.CreateGroup(t, client, admin.OrganizationID, "alpha", user2)
5538

5639
inv, conf := newCLI(t, "groups", "list")
5740

5841
pty := ptytest.New(t)
5942

6043
inv.Stdout = pty.Output()
61-
clitest.SetupConfig(t, client, conf)
44+
clitest.SetupConfig(t, anotherClient, conf)
6245

63-
err = inv.Run()
46+
err := inv.Run()
6447
require.NoError(t, err)
6548

6649
matches := []string{
@@ -77,25 +60,26 @@ func TestGroupList(t *testing.T) {
7760
t.Run("Everyone", func(t *testing.T) {
7861
t.Parallel()
7962

80-
client, user := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
63+
client, admin := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
8164
Features: license.Features{
8265
codersdk.FeatureTemplateRBAC: 1,
8366
},
8467
}})
68+
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID, rbac.RoleUserAdmin())
8569

8670
inv, conf := newCLI(t, "groups", "list")
8771

8872
pty := ptytest.New(t)
8973

9074
inv.Stdout = pty.Output()
91-
clitest.SetupConfig(t, client, conf)
75+
clitest.SetupConfig(t, anotherClient, conf)
9276

9377
err := inv.Run()
9478
require.NoError(t, err)
9579

9680
matches := []string{
9781
"NAME", "ORGANIZATION ID", "MEMBERS", " AVATAR URL",
98-
"Everyone", user.OrganizationID.String(), coderdtest.FirstUserParams.Email, "",
82+
"Everyone", admin.OrganizationID.String(), coderdtest.FirstUserParams.Email, "",
9983
}
10084

10185
for _, match := range matches {

0 commit comments

Comments
 (0)