MCPcopy
hub / github.com/moby/moby / TestPluginList

Function TestPluginList

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

Source from the content-addressed store, hash-verified

20}
21
22func TestPluginList(t *testing.T) {
23 const expectedURL = "/plugins"
24
25 listCases := []struct {
26 filters Filters
27 expectedQueryParams map[string]string
28 }{
29 {
30 expectedQueryParams: map[string]string{
31 "all": "",
32 "filter": "",
33 "filters": "",
34 },
35 },
36 {
37 filters: make(Filters).Add("enabled", "true"),
38 expectedQueryParams: map[string]string{
39 "all": "",
40 "filter": "",
41 "filters": `{"enabled":{"true":true}}`,
42 },
43 },
44 {
45 filters: make(Filters).Add("capability", "volumedriver", "authz"),
46 expectedQueryParams: map[string]string{
47 "all": "",
48 "filter": "",
49 "filters": `{"capability":{"authz":true,"volumedriver":true}}`,
50 },
51 },
52 }
53
54 for _, listCase := range listCases {
55 client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) {
56 if err := assertRequest(req, http.MethodGet, expectedURL); err != nil {
57 return nil, err
58 }
59 query := req.URL.Query()
60 for key, expected := range listCase.expectedQueryParams {
61 actual := query.Get(key)
62 if actual != expected {
63 return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual)
64 }
65 }
66 return mockJSONResponse(http.StatusOK, nil, []plugin.Plugin{
67 {ID: "plugin_id1"},
68 {ID: "plugin_id2"},
69 })(req)
70 }))
71 assert.NilError(t, err)
72
73 list, err := client.PluginList(t.Context(), PluginListOptions{
74 Filters: listCase.filters,
75 })
76 assert.NilError(t, err)
77 assert.Check(t, is.Len(list.Items, 2))
78 }
79}

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