MCPcopy Create free account
hub / github.com/containerd/nerdctl / M

Function M

pkg/testutil/testutil.go:492–543  ·  view source on GitHub ↗
(m *testing.M)

Source from the content-addressed store, hash-verified

490)
491
492func M(m *testing.M) {
493 flag.StringVar(&flagTestTarget, "test.target", "nerdctl", "target to test")
494 flag.BoolVar(&flagTestKillDaemon, "test.allow-kill-daemon", false, "enable tests that kill the daemon")
495 flag.BoolVar(&flagTestModifyUsers, "test.allow-modify-users", false, "enable tests that creates/deletes user accounts on the host")
496 flag.BoolVar(&flagTestIPv6, "test.only-ipv6", false, "enable tests on IPv6")
497 flag.BoolVar(&flagTestKube, "test.only-kubernetes", false, "enable tests on Kubernetes")
498 flag.BoolVar(&flagTestFlaky, "test.only-flaky", false, "enable testing of flaky tests only (if false, flaky tests are ignored)")
499 flag.Parse()
500
501 if flagTestTarget == "" {
502 flagTestTarget = "nerdctl"
503 }
504
505 os.Exit(func() int {
506 err := os.MkdirAll(filepath.Dir(testLockFile), 0o777)
507 if err != nil {
508 log.L.WithError(err).Errorf("failed creating testing lock directory %q", filepath.Dir(testLockFile))
509 return 1
510 }
511
512 // Ensure that permissions are set to 777 (regardless of umask value), so that we do not lock people out when
513 // switching between rootful and rootless locking
514 os.Chmod(filepath.Dir(testLockFile), 0o777)
515
516 // Acquire lock
517 lock, err := filesystem.Lock(filepath.Dir(testLockFile))
518 if err != nil {
519 log.L.WithError(err).Errorf("failed acquiring testing lock %q", filepath.Dir(testLockFile))
520 return 1
521 }
522
523 // Release...
524 defer filesystem.Unlock(lock)
525
526 // Create marker file
527 err = filesystem.WriteFile(testLockFile, []byte("prevent testing from running in parallel for subpackages integration tests"), 0o666)
528 if err != nil {
529 log.L.WithError(err).Errorf("failed writing lock file %q", testLockFile)
530 return 1
531 }
532
533 // Ensure cleanup
534 defer func() {
535 os.Remove(testLockFile)
536 }()
537
538 // Now, run the tests
539 fmt.Fprintf(os.Stderr, "test target: %q\n", flagTestTarget)
540
541 return m.Run()
542 }())
543}
544
545func GetTarget() string {
546 if flagTestTarget == "" {

Callers 15

TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92
TestMainFunction · 0.92

Calls 7

LockFunction · 0.92
UnlockFunction · 0.92
WriteFileFunction · 0.92
ParseMethod · 0.65
DirMethod · 0.65
RemoveMethod · 0.65
RunMethod · 0.65

Tested by 15

TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74
TestMainFunction · 0.74