MCPcopy
hub / github.com/moby/moby / TestNodeList

Function TestNodeList

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

Source from the content-addressed store, hash-verified

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

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
NodeListMethod · 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…