MCPcopy Create free account
hub / github.com/docker/cli / TestInspectErrors

Function TestInspectErrors

cli/command/plugin/inspect_test.go:39–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37}
38
39func TestInspectErrors(t *testing.T) {
40 testCases := []struct {
41 description string
42 args []string
43 flags map[string]string
44 expectedError string
45 inspectFunc func(name string) (client.PluginInspectResult, error)
46 }{
47 {
48 description: "too few arguments",
49 args: []string{},
50 expectedError: "requires at least 1 argument",
51 },
52 {
53 description: "error inspecting plugin",
54 args: []string{"foo"},
55 expectedError: "error inspecting plugin",
56 inspectFunc: func(string) (client.PluginInspectResult, error) {
57 return client.PluginInspectResult{}, errors.New("error inspecting plugin")
58 },
59 },
60 {
61 description: "invalid format",
62 args: []string{"foo"},
63 flags: map[string]string{
64 "format": "{{invalid format}}",
65 },
66 expectedError: "template parsing error",
67 inspectFunc: func(string) (client.PluginInspectResult, error) {
68 return client.PluginInspectResult{}, errors.New("this function should not be called in this test")
69 },
70 },
71 }
72
73 for _, tc := range testCases {
74 t.Run(tc.description, func(t *testing.T) {
75 cli := test.NewFakeCli(&fakeClient{pluginInspectFunc: tc.inspectFunc})
76 cmd := newInspectCommand(cli)
77 cmd.SetArgs(tc.args)
78 for key, value := range tc.flags {
79 assert.NilError(t, cmd.Flags().Set(key, value))
80 }
81 cmd.SetOut(io.Discard)
82 cmd.SetErr(io.Discard)
83 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
84 })
85 }
86}
87
88func TestInspect(t *testing.T) {
89 testCases := []struct {

Callers

nothing calls this directly

Calls 5

SetArgsMethod · 0.80
newInspectCommandFunction · 0.70
SetMethod · 0.45
SetOutMethod · 0.45
SetErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…