@@ -13,6 +13,7 @@ import (
13
13
"github.com/coder/coder/v2/cli/clitest"
14
14
"github.com/coder/coder/v2/cli/cliui"
15
15
"github.com/coder/coder/v2/coderd/coderdtest"
16
+ "github.com/coder/coder/v2/coderd/rbac"
16
17
"github.com/coder/coder/v2/codersdk"
17
18
"github.com/coder/coder/v2/pty/ptytest"
18
19
)
@@ -24,14 +25,15 @@ func TestTemplateDelete(t *testing.T) {
24
25
t .Parallel ()
25
26
26
27
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
27
- user := coderdtest .CreateFirstUser (t , client )
28
- version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
28
+ admin := coderdtest .CreateFirstUser (t , client )
29
+ templateAdmin , _ := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID , rbac .RoleTemplateAdmin ())
30
+ version := coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
29
31
_ = coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
30
- template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
32
+ template := coderdtest .CreateTemplate (t , client , admin .OrganizationID , version .ID )
31
33
32
34
inv , root := clitest .New (t , "templates" , "delete" , template .Name )
33
35
34
- clitest .SetupConfig (t , client , root )
36
+ clitest .SetupConfig (t , templateAdmin , root )
35
37
pty := ptytest .New (t ).Attach (inv )
36
38
37
39
execDone := make (chan error )
@@ -52,19 +54,20 @@ func TestTemplateDelete(t *testing.T) {
52
54
t .Parallel ()
53
55
54
56
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
55
- user := coderdtest .CreateFirstUser (t , client )
57
+ admin := coderdtest .CreateFirstUser (t , client )
58
+ templateAdmin , _ := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID , rbac .RoleTemplateAdmin ())
56
59
templates := []codersdk.Template {}
57
60
templateNames := []string {}
58
61
for i := 0 ; i < 3 ; i ++ {
59
- version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
62
+ version := coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
60
63
_ = coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
61
- template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
64
+ template := coderdtest .CreateTemplate (t , client , admin .OrganizationID , version .ID )
62
65
templates = append (templates , template )
63
66
templateNames = append (templateNames , template .Name )
64
67
}
65
68
66
69
inv , root := clitest .New (t , append ([]string {"templates" , "delete" , "--yes" }, templateNames ... )... )
67
- clitest .SetupConfig (t , client , root )
70
+ clitest .SetupConfig (t , templateAdmin , root )
68
71
require .NoError (t , inv .Run ())
69
72
70
73
for _ , template := range templates {
@@ -77,19 +80,20 @@ func TestTemplateDelete(t *testing.T) {
77
80
t .Parallel ()
78
81
79
82
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
80
- user := coderdtest .CreateFirstUser (t , client )
83
+ admin := coderdtest .CreateFirstUser (t , client )
84
+ templateAdmin , _ := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID , rbac .RoleTemplateAdmin ())
81
85
templates := []codersdk.Template {}
82
86
templateNames := []string {}
83
87
for i := 0 ; i < 3 ; i ++ {
84
- version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
88
+ version := coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
85
89
_ = coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
86
- template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
90
+ template := coderdtest .CreateTemplate (t , client , admin .OrganizationID , version .ID )
87
91
templates = append (templates , template )
88
92
templateNames = append (templateNames , template .Name )
89
93
}
90
94
91
95
inv , root := clitest .New (t , append ([]string {"templates" , "delete" }, templateNames ... )... )
92
- clitest .SetupConfig (t , client , root )
96
+ clitest .SetupConfig (t , templateAdmin , root )
93
97
pty := ptytest .New (t ).Attach (inv )
94
98
95
99
execDone := make (chan error )
@@ -112,13 +116,14 @@ func TestTemplateDelete(t *testing.T) {
112
116
t .Parallel ()
113
117
114
118
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
115
- user := coderdtest .CreateFirstUser (t , client )
116
- version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
119
+ admin := coderdtest .CreateFirstUser (t , client )
120
+ templateAdmin , _ := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID , rbac .RoleTemplateAdmin ())
121
+ version := coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
117
122
_ = coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
118
- template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
123
+ template := coderdtest .CreateTemplate (t , client , admin .OrganizationID , version .ID )
119
124
120
125
inv , root := clitest .New (t , "templates" , "delete" )
121
- clitest .SetupConfig (t , client , root )
126
+ clitest .SetupConfig (t , templateAdmin , root )
122
127
123
128
pty := ptytest .New (t ).Attach (inv )
124
129
0 commit comments