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

Function TestConfigInspectErrors

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

Source from the content-addressed store, hash-verified

16)
17
18func TestConfigInspectErrors(t *testing.T) {
19 testCases := []struct {
20 args []string
21 flags map[string]string
22 configInspectFunc func(_ context.Context, configID string, _ client.ConfigInspectOptions) (client.ConfigInspectResult, error)
23 expectedError string
24 }{
25 {
26 expectedError: "requires at least 1 argument",
27 },
28 {
29 args: []string{"foo"},
30 configInspectFunc: func(context.Context, string, client.ConfigInspectOptions) (client.ConfigInspectResult, error) {
31 return client.ConfigInspectResult{}, errors.New("error while inspecting the config")
32 },
33 expectedError: "error while inspecting the config",
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 configInspectFunc: func(_ context.Context, configID string, _ client.ConfigInspectOptions) (client.ConfigInspectResult, error) {
45 if configID == "foo" {
46 return client.ConfigInspectResult{
47 Config: *builders.Config(builders.ConfigName("foo")),
48 }, nil
49 }
50 return client.ConfigInspectResult{}, errors.New("error while inspecting the config")
51 },
52 expectedError: "error while inspecting the config",
53 },
54 }
55 for _, tc := range testCases {
56 cmd := newConfigInspectCommand(
57 test.NewFakeCli(&fakeClient{
58 configInspectFunc: tc.configInspectFunc,
59 }),
60 )
61 cmd.SetArgs(tc.args)
62 for key, value := range tc.flags {
63 assert.Check(t, cmd.Flags().Set(key, value))
64 }
65 cmd.SetOut(io.Discard)
66 cmd.SetErr(io.Discard)
67 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
68 }
69}
70
71func TestConfigInspectWithoutFormat(t *testing.T) {
72 testCases := []struct {

Callers

nothing calls this directly

Calls 5

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