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

Function TestConfigCreateErrors

cli/command/config/create_test.go:24–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22const configDataFile = "config-create-with-name.golden"
23
24func TestConfigCreateErrors(t *testing.T) {
25 testCases := []struct {
26 args []string
27 configCreateFunc func(context.Context, client.ConfigCreateOptions) (client.ConfigCreateResult, error)
28 expectedError string
29 }{
30 {
31 args: []string{"too_few"},
32 expectedError: "requires 2 arguments",
33 },
34 {
35 args: []string{"too", "many", "arguments"},
36 expectedError: "requires 2 arguments",
37 },
38 {
39 args: []string{"name", filepath.Join("testdata", configDataFile)},
40 configCreateFunc: func(_ context.Context, options client.ConfigCreateOptions) (client.ConfigCreateResult, error) {
41 return client.ConfigCreateResult{}, errors.New("error creating config")
42 },
43 expectedError: "error creating config",
44 },
45 }
46 for _, tc := range testCases {
47 t.Run(tc.expectedError, func(t *testing.T) {
48 cmd := newConfigCreateCommand(
49 test.NewFakeCli(&fakeClient{
50 configCreateFunc: tc.configCreateFunc,
51 }),
52 )
53 cmd.SetArgs(tc.args)
54 cmd.SetOut(io.Discard)
55 cmd.SetErr(io.Discard)
56 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
57 })
58 }
59}
60
61func TestConfigCreateWithName(t *testing.T) {
62 const name = "config-with-name"

Callers

nothing calls this directly

Calls 4

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