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)
| 233 | // |
| 234 | // nolint: paralleltest // The subtests cannot be run in parallel; see the inner loop. |
| 235 | func 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() |
nothing calls this directly
no test coverage detected