@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/coder/coder/v2/cli/clitest"
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/pty/ptytest"
16
17
"github.com/coder/coder/v2/testutil"
@@ -21,17 +22,18 @@ func TestTemplateList(t *testing.T) {
21
22
t .Run ("ListTemplates" , func (t * testing.T ) {
22
23
t .Parallel ()
23
24
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
24
- user := coderdtest .CreateFirstUser (t , client )
25
- firstVersion := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
25
+ admin := coderdtest .CreateFirstUser (t , client )
26
+ templateAdmin , _ := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID , rbac .RoleTemplateAdmin ())
27
+ firstVersion := coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
26
28
_ = coderdtest .AwaitTemplateVersionJobCompleted (t , client , firstVersion .ID )
27
- firstTemplate := coderdtest .CreateTemplate (t , client , user .OrganizationID , firstVersion .ID )
29
+ firstTemplate := coderdtest .CreateTemplate (t , client , admin .OrganizationID , firstVersion .ID )
28
30
29
- secondVersion := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
31
+ secondVersion := coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
30
32
_ = coderdtest .AwaitTemplateVersionJobCompleted (t , client , secondVersion .ID )
31
- secondTemplate := coderdtest .CreateTemplate (t , client , user .OrganizationID , secondVersion .ID )
33
+ secondTemplate := coderdtest .CreateTemplate (t , client , admin .OrganizationID , secondVersion .ID )
32
34
33
35
inv , root := clitest .New (t , "templates" , "list" )
34
- clitest .SetupConfig (t , client , root )
36
+ clitest .SetupConfig (t , templateAdmin , root )
35
37
36
38
pty := ptytest .New (t ).Attach (inv )
37
39
@@ -56,17 +58,18 @@ func TestTemplateList(t *testing.T) {
56
58
t .Run ("ListTemplatesJSON" , func (t * testing.T ) {
57
59
t .Parallel ()
58
60
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
59
- user := coderdtest .CreateFirstUser (t , client )
60
- firstVersion := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
61
+ admin := coderdtest .CreateFirstUser (t , client )
62
+ templateAdmin , _ := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID , rbac .RoleTemplateAdmin ())
63
+ firstVersion := coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
61
64
_ = coderdtest .AwaitTemplateVersionJobCompleted (t , client , firstVersion .ID )
62
- _ = coderdtest .CreateTemplate (t , client , user .OrganizationID , firstVersion .ID )
65
+ _ = coderdtest .CreateTemplate (t , client , admin .OrganizationID , firstVersion .ID )
63
66
64
- secondVersion := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
67
+ secondVersion := coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
65
68
_ = coderdtest .AwaitTemplateVersionJobCompleted (t , client , secondVersion .ID )
66
- _ = coderdtest .CreateTemplate (t , client , user .OrganizationID , secondVersion .ID )
69
+ _ = coderdtest .CreateTemplate (t , client , admin .OrganizationID , secondVersion .ID )
67
70
68
71
inv , root := clitest .New (t , "templates" , "list" , "--output=json" )
69
- clitest .SetupConfig (t , client , root )
72
+ clitest .SetupConfig (t , templateAdmin , root )
70
73
71
74
ctx , cancelFunc := context .WithTimeout (context .Background (), testutil .WaitLong )
72
75
defer cancelFunc ()
@@ -83,10 +86,11 @@ func TestTemplateList(t *testing.T) {
83
86
t .Run ("NoTemplates" , func (t * testing.T ) {
84
87
t .Parallel ()
85
88
client := coderdtest .New (t , & coderdtest.Options {})
86
- coderdtest .CreateFirstUser (t , client )
89
+ admin := coderdtest .CreateFirstUser (t , client )
90
+ templateAdmin , _ := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID , rbac .RoleTemplateAdmin ())
87
91
88
92
inv , root := clitest .New (t , "templates" , "list" )
89
- clitest .SetupConfig (t , client , root )
93
+ clitest .SetupConfig (t , templateAdmin , root )
90
94
91
95
pty := ptytest .New (t )
92
96
inv .Stdin = pty .Input ()
0 commit comments