MCPcopy
hub / github.com/apptainer/apptainer / testShareNSMode

Method testShareNSMode

e2e/instance/instance.go:432–481  ·  view source on GitHub ↗

testShareNSMopde will test --sharens flag

(t *testing.T)

Source from the content-addressed store, hash-verified

430
431// testShareNSMopde will test --sharens flag
432func (c *ctx) testShareNSMode(t *testing.T) {
433 dir, err := os.MkdirTemp(c.env.TestDir, "InstanceShareNS")
434 if err != nil {
435 t.Fatalf("Failed to create temporary directory: %v", err)
436 }
437 defer os.RemoveAll(dir)
438
439 file := fmt.Sprintf("%s/file", dir)
440 f, err := os.Create(file)
441 if err != nil {
442 t.Fatalf("failed to create file, this is unexpected, err: %v", err)
443 }
444 f.Close()
445
446 insNumber := 2
447 for i := 0; i < insNumber; i++ {
448 go c.env.RunApptainer(
449 t,
450 e2e.WithProfile(c.profile),
451 e2e.WithCommand("exec"),
452 e2e.WithArgs("--bind", fmt.Sprintf("%s:/canary/file", file), "--sharens", c.env.ImagePath, "sh", "-c", "echo 0 >> /canary/file; sleep 1"),
453 e2e.ExpectExit(0),
454 )
455 }
456
457 // waiting enough time for the file written
458 time.Sleep(2 * time.Second)
459
460 f, err = os.Open(file)
461 if err != nil {
462 t.Fatalf("failed to open file: %v, this is unexpected", err)
463 }
464 defer f.Close()
465
466 scanner := bufio.NewScanner(f)
467 scanner.Split(bufio.ScanLines)
468
469 var count int
470 for scanner.Scan() {
471 count++
472 }
473
474 if err := scanner.Err(); err != nil {
475 t.Fatalf("having issue while scanning file: %s, err: %v", file, err)
476 }
477
478 if count != insNumber {
479 t.Fatalf("should have %d lines, but actually is %d", insNumber, count)
480 }
481}
482
483// Test that custom auth file authentication works with instance start
484func (c *ctx) testInstanceAuthFile(t *testing.T) {

Callers

nothing calls this directly

Calls 9

WithProfileFunction · 0.92
WithCommandFunction · 0.92
WithArgsFunction · 0.92
ExpectExitFunction · 0.92
RemoveAllMethod · 0.80
RunApptainerMethod · 0.80
OpenMethod · 0.80
CreateMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected