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

Function TestSetConfigsOnlyConfigs

cli/command/service/create_test.go:184–232  ·  view source on GitHub ↗

TestSetConfigsOnlyConfigs verifies setConfigs when only configs (and not a CredentialSpec) is needed.

(t *testing.T)

Source from the content-addressed store, hash-verified

182// TestSetConfigsOnlyConfigs verifies setConfigs when only configs (and not a
183// CredentialSpec) is needed.
184func TestSetConfigsOnlyConfigs(t *testing.T) {
185 configOpt := &swarmopts.ConfigOpt{}
186 assert.Check(t, configOpt.Set("bar"))
187 opts := &serviceOptions{
188 configs: *configOpt,
189 }
190
191 service := &swarm.ServiceSpec{
192 TaskTemplate: swarm.TaskSpec{
193 ContainerSpec: &swarm.ContainerSpec{},
194 },
195 }
196
197 fakeConfigClient := fakeConfigAPIClientList(func(_ context.Context, opts client.ConfigListOptions) (client.ConfigListResult, error) {
198 expected := make(client.Filters).Add("name", "bar")
199 assert.Assert(t, is.DeepEqual(opts.Filters, expected))
200 return client.ConfigListResult{
201 Items: []swarm.Config{
202 {
203 ID: "barID",
204 Spec: swarm.ConfigSpec{
205 Annotations: swarm.Annotations{
206 Name: "bar",
207 },
208 },
209 },
210 },
211 }, nil
212 })
213
214 // now call setConfigs
215 ctx := context.Background()
216 err := setConfigs(ctx, fakeConfigClient, service, opts)
217 // verify no error is returned
218 assert.NilError(t, err)
219
220 configRefs := service.TaskTemplate.ContainerSpec.Configs
221 assert.Assert(t, is.Contains(configRefs, &swarm.ConfigReference{
222 ConfigID: "barID",
223 ConfigName: "bar",
224 File: &swarm.ConfigReferenceFileTarget{
225 Name: "bar",
226 // these are the default field values
227 UID: "0",
228 GID: "0",
229 Mode: 0o444,
230 },
231 }))
232}
233
234// TestSetConfigsNoConfigs checks that setConfigs works when there are no
235// configs of any kind needed

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
fakeConfigAPIClientListFuncType · 0.85
setConfigsFunction · 0.85
ContainsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…