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

Function TestVolumeInspectErrors

cli/command/volume/inspect_test.go:18–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestVolumeInspectErrors(t *testing.T) {
19 testCases := []struct {
20 args []string
21 flags map[string]string
22 volumeInspectFunc func(volumeID string) (client.VolumeInspectResult, error)
23 expectedError string
24 }{
25 {
26 expectedError: "requires at least 1 argument",
27 },
28 {
29 args: []string{"foo"},
30 volumeInspectFunc: func(volumeID string) (client.VolumeInspectResult, error) {
31 return client.VolumeInspectResult{}, errors.New("error while inspecting the volume")
32 },
33 expectedError: "error while inspecting the volume",
34 },
35 {
36 args: []string{"foo"},
37 flags: map[string]string{
38 "format": "{{invalid format}}",
39 },
40 expectedError: "template parsing error",
41 },
42 {
43 args: []string{"foo", "bar"},
44 volumeInspectFunc: func(volumeID string) (client.VolumeInspectResult, error) {
45 if volumeID == "foo" {
46 return client.VolumeInspectResult{
47 Volume: volume.Volume{
48 Name: "foo",
49 },
50 }, nil
51 }
52 return client.VolumeInspectResult{}, errors.New("error while inspecting the volume")
53 },
54 expectedError: "error while inspecting the volume",
55 },
56 }
57 for _, tc := range testCases {
58 cmd := newInspectCommand(
59 test.NewFakeCli(&fakeClient{
60 volumeInspectFunc: tc.volumeInspectFunc,
61 }),
62 )
63 cmd.SetArgs(tc.args)
64 for key, value := range tc.flags {
65 assert.Check(t, cmd.Flags().Set(key, value))
66 }
67 cmd.SetOut(io.Discard)
68 cmd.SetErr(io.Discard)
69 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
70 }
71}
72
73func TestVolumeInspectWithoutFormat(t *testing.T) {
74 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…