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

Function TestSecretCreateWithLabels

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

Source from the content-addressed store, hash-verified

144}
145
146func TestSecretCreateWithLabels(t *testing.T) {
147 expectedLabels := map[string]string{
148 "lbl1": "Label-foo",
149 "lbl2": "Label-bar",
150 }
151 const name = "secret-with-labels"
152
153 cli := test.NewFakeCli(&fakeClient{
154 secretCreateFunc: func(_ context.Context, options client.SecretCreateOptions) (client.SecretCreateResult, error) {
155 if options.Spec.Name != name {
156 return client.SecretCreateResult{}, fmt.Errorf("expected name %q, got %q", name, options.Spec.Name)
157 }
158
159 if !reflect.DeepEqual(options.Spec.Labels, expectedLabels) {
160 return client.SecretCreateResult{}, fmt.Errorf("expected labels %v, got %v", expectedLabels, options.Spec.Labels)
161 }
162
163 return client.SecretCreateResult{
164 ID: "ID-" + options.Spec.Name,
165 }, nil
166 },
167 })
168
169 cmd := newSecretCreateCommand(cli)
170 cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
171 assert.Check(t, cmd.Flags().Set("label", "lbl1=Label-foo"))
172 assert.Check(t, cmd.Flags().Set("label", "lbl2=Label-bar"))
173 assert.NilError(t, cmd.Execute())
174 assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
175}

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…