MCPcopy Index your code
hub / github.com/docker/cli / TestPluginMarshal

Function TestPluginMarshal

cli-plugins/manager/plugin_test.go:12–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestPluginMarshal(t *testing.T) {
13 const jsonWithError = `{"Name":"some-plugin","Err":"something went wrong"}`
14 const jsonNoError = `{"Name":"some-plugin"}`
15
16 tests := []struct {
17 doc string
18 error error
19 expected string
20 }{
21 {
22 doc: "no error",
23 expected: jsonNoError,
24 },
25 {
26 doc: "regular error",
27 error: errors.New("something went wrong"),
28 expected: jsonWithError,
29 },
30 {
31 doc: "custom error",
32 error: newPluginError("something went wrong"),
33 expected: jsonWithError,
34 },
35 }
36 for _, tc := range tests {
37 t.Run(tc.doc, func(t *testing.T) {
38 actual, err := json.Marshal(&Plugin{Name: "some-plugin", Err: tc.error})
39 assert.NilError(t, err)
40 assert.Check(t, is.Equal(string(actual), tc.expected))
41 })
42 }
43}

Callers

nothing calls this directly

Calls 1

newPluginErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…