(t *testing.T)
| 20 | } |
| 21 | |
| 22 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…