Test that MountNamespace can be created with various specs.
(t *testing.T)
| 467 | |
| 468 | // Test that MountNamespace can be created with various specs. |
| 469 | func TestCreateMountNamespace(t *testing.T) { |
| 470 | for _, tc := range createMountTestcases() { |
| 471 | t.Run(tc.name, func(t *testing.T) { |
| 472 | spec := testSpec() |
| 473 | spec.Mounts = tc.spec.Mounts |
| 474 | spec.Root = tc.spec.Root |
| 475 | |
| 476 | t.Logf("Using root: %q", spec.Root.Path) |
| 477 | l, loaderCleanup, err := createLoader(testConfig(), spec) |
| 478 | if err != nil { |
| 479 | t.Fatalf("failed to create loader: %v", err) |
| 480 | } |
| 481 | defer l.Destroy() |
| 482 | defer loaderCleanup() |
| 483 | |
| 484 | l.mu.Lock() |
| 485 | defer l.mu.Unlock() |
| 486 | mntr := l.newContainerMounter(&l.root) |
| 487 | ctx := l.k.SupervisorContext() |
| 488 | creds := auth.NewRootCredentials(l.root.procArgs.Credentials.UserNamespace) |
| 489 | mns, err := mntr.mountAll(ctx, creds, l.root.spec, l.root.conf, &l.root.procArgs) |
| 490 | if err != nil { |
| 491 | t.Fatalf("mountAll: %v", err) |
| 492 | } |
| 493 | |
| 494 | root := mns.Root(ctx) |
| 495 | defer root.DecRef(ctx) |
| 496 | for _, p := range tc.expectedPaths { |
| 497 | target := &vfs.PathOperation{ |
| 498 | Root: root, |
| 499 | Start: root, |
| 500 | Path: fspath.Parse(p), |
| 501 | } |
| 502 | |
| 503 | if d, err := l.k.VFS().GetDentryAt(ctx, l.root.procArgs.Credentials, target, &vfs.GetDentryOptions{}); err != nil { |
| 504 | t.Errorf("expected path %v to exist with spec %v, but got error %v", p, tc.spec, err) |
| 505 | } else { |
| 506 | d.DecRef(ctx) |
| 507 | } |
| 508 | } |
| 509 | }) |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | type createMountPointTestCase struct { |
| 514 | name string |
nothing calls this directly
no test coverage detected
searching dependent graphs…