MCPcopy
hub / github.com/moby/moby / TestTaskList

Function TestTaskList

client/task_list_test.go:22–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20}
21
22func TestTaskList(t *testing.T) {
23 const expectedURL = "/tasks"
24
25 listCases := []struct {
26 options TaskListOptions
27 expectedQueryParams map[string]string
28 }{
29 {
30 options: TaskListOptions{},
31 expectedQueryParams: map[string]string{
32 "filters": "",
33 },
34 },
35 {
36 options: TaskListOptions{
37 Filters: make(Filters).Add("label", "label1", "label2"),
38 },
39 expectedQueryParams: map[string]string{
40 "filters": `{"label":{"label1":true,"label2":true}}`,
41 },
42 },
43 }
44 for _, listCase := range listCases {
45 client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) {
46 if err := assertRequest(req, http.MethodGet, expectedURL); err != nil {
47 return nil, err
48 }
49 query := req.URL.Query()
50 for key, expected := range listCase.expectedQueryParams {
51 actual := query.Get(key)
52 if actual != expected {
53 return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual)
54 }
55 }
56 return mockJSONResponse(http.StatusOK, nil, []swarm.Task{
57 {ID: "task_id1"},
58 {ID: "task_id2"},
59 })(req)
60 }))
61 assert.NilError(t, err)
62
63 result, err := client.TaskList(t.Context(), listCase.options)
64 assert.NilError(t, err)
65 assert.Check(t, is.Len(result.Items, 2))
66 }
67}

Callers

nothing calls this directly

Calls 11

WithMockClientFunction · 0.85
assertRequestFunction · 0.85
mockJSONResponseFunction · 0.85
ErrorfMethod · 0.80
CheckMethod · 0.80
NewFunction · 0.70
AddMethod · 0.65
GetMethod · 0.65
TaskListMethod · 0.65
ContextMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…