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

Function TestNewHistoryCommandErrors

cli/command/image/history_test.go:17–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestNewHistoryCommandErrors(t *testing.T) {
18 testCases := []struct {
19 name string
20 args []string
21 expectedError string
22 imageHistoryFunc func(img string, options ...client.ImageHistoryOption) (client.ImageHistoryResult, error)
23 }{
24 {
25 name: "wrong-args",
26 args: []string{},
27 expectedError: "requires 1 argument",
28 },
29 {
30 name: "client-error",
31 args: []string{"image:tag"},
32 expectedError: "something went wrong",
33 imageHistoryFunc: func(string, ...client.ImageHistoryOption) (client.ImageHistoryResult, error) {
34 return client.ImageHistoryResult{}, errors.New("something went wrong")
35 },
36 },
37 {
38 name: "invalid platform",
39 args: []string{"--platform", "<invalid>", "arg1"},
40 expectedError: `invalid platform`,
41 },
42 }
43 for _, tc := range testCases {
44 t.Run(tc.name, func(t *testing.T) {
45 cmd := newHistoryCommand(test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc}))
46 cmd.SetOut(io.Discard)
47 cmd.SetErr(io.Discard)
48 cmd.SetArgs(tc.args)
49 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
50 })
51 }
52}
53
54func TestNewHistoryCommandSuccess(t *testing.T) {
55 testCases := []struct {

Callers

nothing calls this directly

Calls 4

newHistoryCommandFunction · 0.85
SetArgsMethod · 0.80
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…