@@ -11,11 +11,11 @@ import (
11
11
"github.com/coder/coder/v2/cli/clitest"
12
12
"github.com/coder/coder/v2/cli/cliui"
13
13
"github.com/coder/coder/v2/coderd/coderdtest"
14
+ "github.com/coder/coder/v2/coderd/rbac"
14
15
"github.com/coder/coder/v2/codersdk"
15
16
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
16
17
"github.com/coder/coder/v2/enterprise/coderd/license"
17
18
"github.com/coder/coder/v2/pty/ptytest"
18
- "github.com/coder/coder/v2/testutil"
19
19
)
20
20
21
21
func TestGroupEdit (t * testing.T ) {
@@ -29,23 +29,13 @@ func TestGroupEdit(t *testing.T) {
29
29
codersdk .FeatureTemplateRBAC : 1 ,
30
30
},
31
31
}})
32
+ anotherClient , _ := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID , rbac .RoleUserAdmin ())
32
33
33
- ctx := testutil .Context (t , testutil .WaitLong )
34
34
_ , user1 := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID )
35
35
_ , user2 := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID )
36
36
_ , user3 := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID )
37
37
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 )
49
39
50
40
expectedName := "beta"
51
41
@@ -62,9 +52,9 @@ func TestGroupEdit(t *testing.T) {
62
52
pty := ptytest .New (t )
63
53
64
54
inv .Stdout = pty .Output ()
65
- clitest .SetupConfig (t , client , conf )
55
+ clitest .SetupConfig (t , anotherClient , conf )
66
56
67
- err = inv .Run ()
57
+ err : = inv .Run ()
68
58
require .NoError (t , err )
69
59
70
60
pty .ExpectMatch (fmt .Sprintf ("Successfully patched group %s" , pretty .Sprint (cliui .DefaultStyles .Keyword , expectedName )))
@@ -79,39 +69,35 @@ func TestGroupEdit(t *testing.T) {
79
69
},
80
70
}})
81
71
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" )
88
74
89
75
inv , conf := newCLI (
90
76
t ,
91
77
"groups" , "edit" , group .Name ,
92
78
"-a" , "foo" ,
93
79
)
94
80
95
- clitest .SetupConfig (t , client , conf )
81
+ clitest .SetupConfig (t , client , conf ) //nolint:gocritic // intentional usage of owner
96
82
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" )
100
85
})
101
86
102
87
t .Run ("NoArg" , func (t * testing.T ) {
103
88
t .Parallel ()
104
89
105
- client , _ := coderdenttest .New (t , & coderdenttest.Options {LicenseOptions : & coderdenttest.LicenseOptions {
90
+ client , user := coderdenttest .New (t , & coderdenttest.Options {LicenseOptions : & coderdenttest.LicenseOptions {
106
91
Features : license.Features {
107
92
codersdk .FeatureTemplateRBAC : 1 ,
108
93
},
109
94
}})
95
+ anotherClient , _ := coderdtest .CreateAnotherUser (t , client , user .OrganizationID , rbac .RoleUserAdmin ())
110
96
111
97
inv , conf := newCLI (t , "groups" , "edit" )
112
- clitest .SetupConfig (t , client , conf )
98
+ clitest .SetupConfig (t , anotherClient , conf )
113
99
114
100
err := inv .Run ()
115
- require .Error (t , err )
101
+ require .ErrorContains (t , err , "wanted 1 args but got 0" )
116
102
})
117
103
}
0 commit comments