MCPcopy Index your code
hub / github.com/docker/docker-agent / TestCagentAPI_ListSessions

Function TestCagentAPI_ListSessions

e2e/api_test.go:25–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23}
24
25func TestCagentAPI_ListSessions(t *testing.T) {
26 type testcase struct {
27 db string
28 expectedCount int
29 }
30
31 for _, tc := range []testcase{
32 {"one-session.db", 1},
33 {"two-sessions.db", 2},
34 {"transfer-task.db", 1},
35 {"session.db", 1},
36 {"session-not-found.db", 17},
37 {"desktop.db", 2},
38 } {
39 t.Run(tc.db, func(t *testing.T) {
40 socketPath := startCagentAPI(t, filepath.Join("testdata", "db", tc.db))
41
42 client := &http.Client{
43 Transport: &http.Transport{
44 DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
45 return (&net.Dialer{}).DialContext(ctx, "unix", socketPath)
46 },
47 },
48 }
49
50 req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://localhost/api/sessions", http.NoBody)
51 require.NoError(t, err)
52 resp, err := client.Do(req)
53 require.NoError(t, err)
54 defer resp.Body.Close()
55
56 var sessions []Session
57 err = json.NewDecoder(resp.Body).Decode(&sessions)
58 require.NoError(t, err)
59
60 assert.Len(t, sessions, tc.expectedCount)
61 })
62 }
63}
64
65func startCagentAPI(t *testing.T, db string) string {
66 t.Helper()

Callers

nothing calls this directly

Calls 6

startCagentAPIFunction · 0.85
ContextMethod · 0.80
RunMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected