MCPcopy Index your code
hub / github.com/coder/coder / TestTemplatePull_ToDir

Function TestTemplatePull_ToDir

cli/templatepull_test.go:235–339  ·  view source on GitHub ↗

ToDir tests that 'templates pull' pulls down the active template and writes it to the correct directory. nolint: paralleltest // The subtests cannot be run in parallel; see the inner loop.

(t *testing.T)

Source from the content-addressed store, hash-verified

233//
234// nolint: paralleltest // The subtests cannot be run in parallel; see the inner loop.
235func TestTemplatePull_ToDir(t *testing.T) {
236 tests := []struct {
237 name string
238 destPath string
239 useDefaultDest bool
240 }{
241 {
242 name: "absolute path works",
243 useDefaultDest: true,
244 },
245 {
246 name: "relative path to specific dir is sanitized",
247 destPath: "./pulltmp",
248 },
249 {
250 name: "relative path to current dir is sanitized",
251 destPath: ".",
252 },
253 {
254 name: "directory traversal is acceptable",
255 destPath: "../mytmpl",
256 },
257 {
258 name: "empty path falls back to using template name",
259 destPath: "",
260 },
261 }
262
263 // nolint: paralleltest // These tests change the current working dir, and is therefore unsuitable for parallelisation.
264 for _, tc := range tests {
265 t.Run(tc.name, func(t *testing.T) {
266 dir := t.TempDir()
267
268 cwd, err := os.Getwd()
269 require.NoError(t, err)
270 t.Cleanup(func() {
271 require.NoError(t, os.Chdir(cwd))
272 })
273
274 // Change working directory so that relative path tests don't affect the original working directory.
275 newWd := filepath.Join(dir, "new-cwd")
276 require.NoError(t, os.MkdirAll(newWd, 0o750))
277 require.NoError(t, os.Chdir(newWd))
278
279 expectedDest := filepath.Join(dir, "expected")
280 actualDest := tc.destPath
281 if tc.useDefaultDest {
282 actualDest = filepath.Join(dir, "actual")
283 }
284
285 client := coderdtest.New(t, &coderdtest.Options{
286 IncludeProvisionerDaemon: true,
287 })
288 owner := coderdtest.CreateFirstUser(t, client)
289 templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
290
291 // Create an initial template bundle.
292 source1 := genTemplateVersionSource()

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
TarFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
UpdateTemplateVersionFunction · 0.92
UntarFunction · 0.92
NewFunction · 0.92

Tested by

no test coverage detected