MCPcopy
hub / github.com/containerd/containerd / newDaemonWithConfig

Function newDaemonWithConfig

integration/client/restart_monitor_test.go:44–121  ·  view source on GitHub ↗
(t *testing.T, configTOML string)

Source from the content-addressed store, hash-verified

42)
43
44func newDaemonWithConfig(t *testing.T, configTOML string) (*Client, *daemon, func()) {
45 if testing.Short() {
46 t.Skip()
47 }
48 testutil.RequiresRoot(t)
49 var (
50 ctrd = daemon{}
51 configTOMLDecoded srvconfig.Config
52 buf = bytes.NewBuffer(nil)
53 )
54
55 tempDir := t.TempDir()
56
57 configTOMLFile := filepath.Join(tempDir, "config.toml")
58 if err := os.WriteFile(configTOMLFile, []byte(configTOML), 0600); err != nil {
59 t.Fatal(err)
60 }
61
62 if err := srvconfig.LoadConfig(context.TODO(), configTOMLFile, &configTOMLDecoded); err != nil {
63 t.Fatal(err)
64 }
65
66 var address string
67 if grpcPlugin, ok := configTOMLDecoded.Plugins["io.containerd.server.v1.grpc"].(map[string]any); ok {
68 address, _ = grpcPlugin["address"].(string)
69 }
70 if address == "" {
71 if runtime.GOOS == "windows" {
72 address = fmt.Sprintf(`\\.\pipe\containerd-containerd-test-%s`, filepath.Base(tempDir))
73 } else {
74 address = filepath.Join(tempDir, "containerd.sock")
75 }
76 }
77 args := []string{"-c", configTOMLFile}
78 if configTOMLDecoded.Root == "" {
79 args = append(args, "--root", filepath.Join(tempDir, "root"))
80 }
81 if configTOMLDecoded.State == "" {
82 args = append(args, "--state", filepath.Join(tempDir, "state"))
83 }
84 if err := ctrd.start("containerd", address, args, buf, buf); err != nil {
85 t.Fatalf("%v: %s", err, buf.String())
86 }
87
88 waitCtx, waitCancel := context.WithTimeout(context.TODO(), 2*time.Second)
89 client, err := ctrd.waitForStart(waitCtx)
90 waitCancel()
91 if err != nil {
92 ctrd.Kill()
93 ctrd.Wait()
94 t.Fatalf("%v: %s", err, buf.String())
95 }
96
97 cleanup := func() {
98 if err := client.Close(); err != nil {
99 t.Errorf("failed to close client: %v", err)
100 }
101 if err := ctrd.Stop(); err != nil {

Callers 3

TestRestartMonitorFunction · 0.85
TestDaemonRuntimeRootFunction · 0.85
TestDaemonCustomCgroupFunction · 0.85

Calls 12

RequiresRootFunction · 0.92
FatalMethod · 0.80
waitForStartMethod · 0.80
LogMethod · 0.80
forceRemoveAllFunction · 0.70
WriteFileMethod · 0.65
KillMethod · 0.65
WaitMethod · 0.65
CloseMethod · 0.65
StopMethod · 0.65
startMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…