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

Function TestNewInspectCommandSuccess

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

Source from the content-addressed store, hash-verified

37}
38
39func TestNewInspectCommandSuccess(t *testing.T) {
40 imageInspectInvocationCount := 0
41 testCases := []struct {
42 name string
43 args []string
44 imageCount int
45 imageInspectFunc func(img string) (client.ImageInspectResult, error)
46 }{
47 {
48 name: "simple",
49 args: []string{"image"},
50 imageCount: 1,
51 imageInspectFunc: func(img string) (client.ImageInspectResult, error) {
52 imageInspectInvocationCount++
53 assert.Check(t, is.Equal("image", img))
54 return client.ImageInspectResult{}, nil
55 },
56 },
57 {
58 name: "format",
59 imageCount: 1,
60 args: []string{"--format='{{.ID}}'", "image"},
61 imageInspectFunc: func(img string) (client.ImageInspectResult, error) {
62 imageInspectInvocationCount++
63 return client.ImageInspectResult{
64 InspectResponse: image.InspectResponse{ID: img},
65 }, nil
66 },
67 },
68 {
69 name: "simple-many",
70 args: []string{"image1", "image2"},
71 imageCount: 2,
72 imageInspectFunc: func(img string) (client.ImageInspectResult, error) {
73 imageInspectInvocationCount++
74 if imageInspectInvocationCount == 1 {
75 assert.Check(t, is.Equal("image1", img))
76 } else {
77 assert.Check(t, is.Equal("image2", img))
78 }
79 return client.ImageInspectResult{}, nil
80 },
81 },
82 }
83 for _, tc := range testCases {
84 t.Run(tc.name, func(t *testing.T) {
85 imageInspectInvocationCount = 0
86 cli := test.NewFakeCli(&fakeClient{imageInspectFunc: tc.imageInspectFunc})
87 cmd := newInspectCommand(cli)
88 cmd.SetOut(io.Discard)
89 cmd.SetArgs(tc.args)
90 err := cmd.Execute()
91 assert.NilError(t, err)
92 golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("inspect-command-success.%s.golden", tc.name))
93 assert.Check(t, is.Equal(imageInspectInvocationCount, tc.imageCount))
94 })
95 }
96}

Callers

nothing calls this directly

Calls 5

OutBufferMethod · 0.95
SetArgsMethod · 0.80
newInspectCommandFunction · 0.70
StringMethod · 0.65
SetOutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…