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

Function TestSecretInspectErrors

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

Source from the content-addressed store, hash-verified

16)
17
18func TestSecretInspectErrors(t *testing.T) {
19 testCases := []struct {
20 args []string
21 flags map[string]string
22 secretInspectFunc func(ctx context.Context, secretID string, _ client.SecretInspectOptions) (client.SecretInspectResult, error)
23 expectedError string
24 }{
25 {
26 expectedError: "requires at least 1 argument",
27 },
28 {
29 args: []string{"foo"},
30 secretInspectFunc: func(_ context.Context, secretID string, _ client.SecretInspectOptions) (client.SecretInspectResult, error) {
31 return client.SecretInspectResult{}, errors.New("error while inspecting the secret")
32 },
33 expectedError: "error while inspecting the secret",
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 secretInspectFunc: func(_ context.Context, secretID string, _ client.SecretInspectOptions) (client.SecretInspectResult, error) {
45 if secretID == "foo" {
46 return client.SecretInspectResult{
47 Secret: *builders.Secret(builders.SecretName("foo")),
48 }, nil
49 }
50 return client.SecretInspectResult{}, errors.New("error while inspecting the secret")
51 },
52 expectedError: "error while inspecting the secret",
53 },
54 }
55 for _, tc := range testCases {
56 cmd := newSecretInspectCommand(
57 test.NewFakeCli(&fakeClient{
58 secretInspectFunc: tc.secretInspectFunc,
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 TestSecretInspectWithoutFormat(t *testing.T) {
72 testCases := []struct {

Callers

nothing calls this directly

Calls 5

newSecretInspectCommandFunction · 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…