MCPcopy Index your code
hub / github.com/containerd/containerd / TestMain

Function TestMain

integration/client/client_test.go:63–193  ·  view source on GitHub ↗
(m *testing.M)

Source from the content-addressed store, hash-verified

61}
62
63func TestMain(m *testing.M) {
64 flag.Parse()
65 if testing.Short() {
66 os.Exit(m.Run())
67 }
68 testutil.RequiresRootM()
69 // check if criu is installed on the system
70 _, err := exec.LookPath("criu")
71 supportsCriu = err == nil && !noCriu
72
73 var (
74 buf = bytes.NewBuffer(nil)
75 ctx, cancel = testContext(nil)
76 )
77 defer cancel()
78
79 if !noDaemon {
80 _ = forceRemoveAll(defaultRoot)
81
82 stdioFile, err := os.CreateTemp("", "")
83 if err != nil {
84 fmt.Fprintf(os.Stderr, "could not create a new stdio temp file: %s\n", err)
85 os.Exit(1)
86 }
87 defer func() {
88 stdioFile.Close()
89 os.Remove(stdioFile.Name())
90 }()
91 ctrdStdioFilePath = stdioFile.Name()
92 stdioWriter := io.MultiWriter(stdioFile, buf)
93
94 err = ctrd.start("containerd", address, []string{
95 "--root", defaultRoot,
96 "--state", defaultState,
97 "--log-level", "debug",
98 "--config", createShimDebugConfig(),
99 }, stdioWriter, stdioWriter)
100 if err != nil {
101 fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String())
102 os.Exit(1)
103 }
104 } else {
105 // Otherwise if no-daemon was specified we need to connect to an already running ctrd instance.
106 // Set the addr field on the daemon object so it knows what to try connecting to.
107 ctrd.addr = address
108 }
109
110 waitCtx, waitCancel := context.WithTimeout(ctx, 4*time.Second)
111 client, err := ctrd.waitForStart(waitCtx)
112 waitCancel()
113 if err != nil {
114 ctrd.Kill()
115 ctrd.Wait()
116 fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String())
117 os.Exit(1)
118 }
119
120 // print out the version in information

Callers

nothing calls this directly

Calls 15

RequiresRootMFunction · 0.92
VersionStruct · 0.92
NamespaceFunction · 0.92
testContextFunction · 0.85
createShimDebugConfigFunction · 0.85
ExitMethod · 0.80
waitForStartMethod · 0.80
NamespaceServiceMethod · 0.80
forceRemoveAllFunction · 0.70
RunMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…