@@ -17,7 +17,7 @@ import (
17
17
func TestTemplateEdit (t * testing.T ) {
18
18
t .Parallel ()
19
19
20
- t .Run ("Modified " ,func (t * testing.T ) {
20
+ t .Run ("FirstEmptyThenModified " ,func (t * testing.T ) {
21
21
t .Parallel ()
22
22
client := coderdtest .New (t ,& coderdtest.Options {IncludeProvisionerDaemon :true })
23
23
user := coderdtest .CreateFirstUser (t ,client )
@@ -58,7 +58,7 @@ func TestTemplateEdit(t *testing.T) {
58
58
assert .Equal (t ,icon ,updated .Icon )
59
59
assert .Equal (t ,defaultTTL .Milliseconds (),updated .DefaultTTLMillis )
60
60
})
61
- t .Run ("NotModified " ,func (t * testing.T ) {
61
+ t .Run ("FirstEmptyThenNotModified " ,func (t * testing.T ) {
62
62
t .Parallel ()
63
63
client := coderdtest .New (t ,& coderdtest.Options {IncludeProvisionerDaemon :true })
64
64
user := coderdtest .CreateFirstUser (t ,client )
@@ -124,4 +124,102 @@ func TestTemplateEdit(t *testing.T) {
124
124
assert .Equal (t ,template .Name ,updated .Name )
125
125
assert .Equal (t ,"" ,template .DisplayName )
126
126
})
127
+ t .Run ("WithPropertiesThenModified" ,func (t * testing.T ) {
128
+ t .Parallel ()
129
+ client := coderdtest .New (t ,& coderdtest.Options {IncludeProvisionerDaemon :true })
130
+ user := coderdtest .CreateFirstUser (t ,client )
131
+ version := coderdtest .CreateTemplateVersion (t ,client ,user .OrganizationID ,nil )
132
+ _ = coderdtest .AwaitTemplateVersionJob (t ,client ,version .ID )
133
+
134
+ initialDisplayName := "This is a template"
135
+ initialDescription := "This is description"
136
+ initialIcon := "/img/icon.png"
137
+
138
+ template := coderdtest .CreateTemplate (t ,client ,user .OrganizationID ,version .ID ,func (ctr * codersdk.CreateTemplateRequest ) {
139
+ ctr .DisplayName = initialDisplayName
140
+ ctr .Description = initialDescription
141
+ ctr .Icon = initialIcon
142
+ })
143
+
144
+ // Test created template
145
+ created ,err := client .Template (context .Background (),template .ID )
146
+ require .NoError (t ,err )
147
+ assert .Equal (t ,initialDisplayName ,created .DisplayName )
148
+ assert .Equal (t ,initialDescription ,created .Description )
149
+ assert .Equal (t ,initialIcon ,created .Icon )
150
+
151
+ // Test the cli command.
152
+ displayName := "New Display Name 789"
153
+ icon := "/icons/new-icon.png"
154
+ cmdArgs := []string {
155
+ "templates" ,
156
+ "edit" ,
157
+ template .Name ,
158
+ "--display-name" ,displayName ,
159
+ "--icon" ,icon ,
160
+ }
161
+ cmd ,root := clitest .New (t ,cmdArgs ... )
162
+ clitest .SetupConfig (t ,client ,root )
163
+
164
+ ctx ,_ := testutil .Context (t )
165
+ err = cmd .ExecuteContext (ctx )
166
+
167
+ require .NoError (t ,err )
168
+
169
+ // Assert that the template metadata changed.
170
+ updated ,err := client .Template (context .Background (),template .ID )
171
+ require .NoError (t ,err )
172
+ assert .Equal (t ,template .Name ,updated .Name )// doesn't change
173
+ assert .Equal (t ,initialDescription ,updated .Description )// doesn't change
174
+ assert .Equal (t ,displayName ,updated .DisplayName )
175
+ assert .Equal (t ,icon ,updated .Icon )
176
+ })
177
+ t .Run ("WithPropertiesThenEmptyEdit" ,func (t * testing.T ) {
178
+ t .Parallel ()
179
+ client := coderdtest .New (t ,& coderdtest.Options {IncludeProvisionerDaemon :true })
180
+ user := coderdtest .CreateFirstUser (t ,client )
181
+ version := coderdtest .CreateTemplateVersion (t ,client ,user .OrganizationID ,nil )
182
+ _ = coderdtest .AwaitTemplateVersionJob (t ,client ,version .ID )
183
+
184
+ initialDisplayName := "This is a template"
185
+ initialDescription := "This is description"
186
+ initialIcon := "/img/icon.png"
187
+
188
+ template := coderdtest .CreateTemplate (t ,client ,user .OrganizationID ,version .ID ,func (ctr * codersdk.CreateTemplateRequest ) {
189
+ ctr .DisplayName = initialDisplayName
190
+ ctr .Description = initialDescription
191
+ ctr .Icon = initialIcon
192
+ })
193
+
194
+ // Test created template
195
+ created ,err := client .Template (context .Background (),template .ID )
196
+ require .NoError (t ,err )
197
+ assert .Equal (t ,initialDisplayName ,created .DisplayName )
198
+ assert .Equal (t ,initialDescription ,created .Description )
199
+ assert .Equal (t ,initialIcon ,created .Icon )
200
+
201
+ // Test the cli command.
202
+ cmdArgs := []string {
203
+ "templates" ,
204
+ "edit" ,
205
+ template .Name ,
206
+ }
207
+ cmd ,root := clitest .New (t ,cmdArgs ... )
208
+ clitest .SetupConfig (t ,client ,root )
209
+
210
+ ctx ,_ := testutil .Context (t )
211
+ err = cmd .ExecuteContext (ctx )
212
+
213
+ require .NoError (t ,err )
214
+
215
+ // Assert that the template metadata changed.
216
+ updated ,err := client .Template (context .Background (),template .ID )
217
+ require .NoError (t ,err )
218
+ // Properties don't change
219
+ assert .Equal (t ,template .Name ,updated .Name )
220
+ assert .Equal (t ,template .Description ,updated .Description )
221
+ assert .Equal (t ,template .DisplayName ,updated .DisplayName )
222
+ // Icon is removed, as the API considers it as "delete" request
223
+ assert .Equal (t ,"" ,updated .Icon )
224
+ })
127
225
}