MCPcopy
hub / github.com/docker/docker-agent / startCagentAPI

Function startCagentAPI

e2e/api_test.go:65–99  ·  view source on GitHub ↗
(t *testing.T, db string)

Source from the content-addressed store, hash-verified

63}
64
65func startCagentAPI(t *testing.T, db string) string {
66 t.Helper()
67
68 // Get absolute path to db before changing directory
69 absDB, err := filepath.Abs(db)
70 require.NoError(t, err)
71
72 tmpDir := t.TempDir()
73 t.Chdir(tmpDir) // Use relative socket path to avoid Unix socket path length limit
74
75 // Copy database files to temp directory
76 dbCopy := tmpDir + "/session.db"
77 copyFile(t, dbCopy, absDB)
78 if _, err := os.Stat(absDB + "-wal"); err == nil {
79 copyFile(t, dbCopy+"-wal", absDB+"-wal")
80 }
81
82 ln, err := server.Listen(t.Context(), "unix://cagent.sock")
83 require.NoError(t, err)
84 t.Cleanup(func() {
85 _ = ln.Close()
86 })
87
88 sessionStore, err := session.NewSQLiteSessionStore(t.Context(), dbCopy)
89 require.NoError(t, err)
90
91 srv, err := server.New(t.Context(), sessionStore, &config.RuntimeConfig{}, 0, nil, "")
92 require.NoError(t, err)
93
94 go func() {
95 _ = srv.Serve(t.Context(), ln)
96 }()
97
98 return "cagent.sock"
99}
100
101func copyFile(t *testing.T, dst, src string) {
102 t.Helper()

Callers 1

Calls 8

ListenFunction · 0.92
NewSQLiteSessionStoreFunction · 0.92
NewFunction · 0.92
ContextMethod · 0.80
ServeMethod · 0.80
copyFileFunction · 0.70
CleanupMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected