@@ -201,6 +201,53 @@ func TestTemplatePull(t *testing.T) {
201
201
})
202
202
}
203
203
204
+ //nolint:paralleltest // This test uses default the current directory.
205
+ func TestTemplatePull_DefaultDir (t * testing.T ) {
206
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
207
+ user := coderdtest .CreateFirstUser (t , client )
208
+
209
+ // Create an initial template bundle.
210
+ source1 := genTemplateVersionSource ()
211
+ // Create an updated template bundle. This will be used to ensure
212
+ // that templates are correctly returned in order from latest to oldest.
213
+ source2 := genTemplateVersionSource ()
214
+
215
+ expected , err := echo .Tar (source2 )
216
+ require .NoError (t , err )
217
+
218
+ version1 := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , source1 )
219
+ _ = coderdtest .AwaitTemplateVersionJob (t , client , version1 .ID )
220
+
221
+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version1 .ID )
222
+
223
+ // Update the template version so that we can assert that templates
224
+ // are being sorted correctly.
225
+ _ = coderdtest .UpdateTemplateVersion (t , client , user .OrganizationID , source2 , template .ID )
226
+
227
+ dir := t .TempDir ()
228
+ expectedDest := filepath .Join (dir , "expected" )
229
+ ctx := context .Background ()
230
+
231
+ err = extract .Tar (ctx , bytes .NewReader (expected ), expectedDest , nil )
232
+ require .NoError (t , err )
233
+
234
+ inv , root := clitest .New (t , "templates" , "pull" , template .Name )
235
+ clitest .SetupConfig (t , client , root )
236
+ t .Cleanup (func () {
237
+ err := os .RemoveAll (template .Name )
238
+ require .NoError (t , err , "can't remove template dir" )
239
+ })
240
+
241
+ ptytest .New (t ).Attach (inv )
242
+
243
+ require .NoError (t , inv .Run ())
244
+
245
+ require .Equal (t ,
246
+ dirSum (t , expectedDest ),
247
+ dirSum (t , template .Name ),
248
+ )
249
+ }
250
+
204
251
// genTemplateVersionSource returns a unique bundle that can be used to create
205
252
// a template version source.
206
253
func genTemplateVersionSource () * echo.Responses {
0 commit comments