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

Function TestSecretCreateErrors

cli/command/secret/create_test.go:23–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21const secretDataFile = "secret-create-with-name.golden"
22
23func TestSecretCreateErrors(t *testing.T) {
24 testCases := []struct {
25 args []string
26 secretCreateFunc func(context.Context, client.SecretCreateOptions) (client.SecretCreateResult, error)
27 expectedError string
28 }{
29 {
30 args: []string{"too", "many", "arguments"},
31 expectedError: "requires at least 1 and at most 2 arguments",
32 },
33 {
34 args: []string{"create", "--driver", "driver", "-"},
35 expectedError: "secret data must be empty",
36 },
37 {
38 args: []string{"name", filepath.Join("testdata", secretDataFile)},
39 secretCreateFunc: func(context.Context, client.SecretCreateOptions) (client.SecretCreateResult, error) {
40 return client.SecretCreateResult{}, errors.New("error creating secret")
41 },
42 expectedError: "error creating secret",
43 },
44 }
45 for _, tc := range testCases {
46 cmd := newSecretCreateCommand(
47 test.NewFakeCli(&fakeClient{
48 secretCreateFunc: tc.secretCreateFunc,
49 }),
50 )
51 cmd.SetArgs(tc.args)
52 cmd.SetOut(io.Discard)
53 cmd.SetErr(io.Discard)
54 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
55 }
56}
57
58func TestSecretCreateWithName(t *testing.T) {
59 const name = "secret-with-name"

Callers

nothing calls this directly

Calls 4

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