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

Function TestSecretCreateWithName

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

Source from the content-addressed store, hash-verified

56}
57
58func TestSecretCreateWithName(t *testing.T) {
59 const name = "secret-with-name"
60 data, err := os.ReadFile(filepath.Join("testdata", secretDataFile))
61 assert.NilError(t, err)
62
63 expected := swarm.SecretSpec{
64 Annotations: swarm.Annotations{
65 Name: name,
66 Labels: make(map[string]string),
67 },
68 Data: data,
69 }
70
71 cli := test.NewFakeCli(&fakeClient{
72 secretCreateFunc: func(_ context.Context, options client.SecretCreateOptions) (client.SecretCreateResult, error) {
73 if !reflect.DeepEqual(options.Spec, expected) {
74 return client.SecretCreateResult{}, fmt.Errorf("expected %+v, got %+v", expected, options.Spec)
75 }
76 return client.SecretCreateResult{
77 ID: "ID-" + options.Spec.Name,
78 }, nil
79 },
80 })
81
82 cmd := newSecretCreateCommand(cli)
83 cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
84 assert.NilError(t, cmd.Execute())
85 assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
86}
87
88func TestSecretCreateWithDriver(t *testing.T) {
89 expectedDriver := &swarm.Driver{

Callers

nothing calls this directly

Calls 4

OutBufferMethod · 0.95
newSecretCreateCommandFunction · 0.85
SetArgsMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…