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

Function TestSetConfigsWithCredSpecAndConfigs

cli/command/service/create_test.go:42–122  ·  view source on GitHub ↗

TestSetConfigsWithCredSpecAndConfigs tests that the setConfigs function for create correctly looks up the right configs, and correctly handles the credentialSpec

(t *testing.T)

Source from the content-addressed store, hash-verified

40// create correctly looks up the right configs, and correctly handles the
41// credentialSpec
42func TestSetConfigsWithCredSpecAndConfigs(t *testing.T) {
43 // we can't directly access the internal fields of the ConfigOpt struct, so
44 // we need to let it do the parsing
45 configOpt := &swarmopts.ConfigOpt{}
46 assert.Check(t, configOpt.Set("bar"))
47 opts := &serviceOptions{
48 credentialSpec: credentialSpecOpt{
49 value: &swarm.CredentialSpec{
50 Config: "foo",
51 },
52 source: "config://foo",
53 },
54 configs: *configOpt,
55 }
56
57 // create a service spec. we need to be sure to fill in the nullable
58 // fields, like the code expects
59 service := &swarm.ServiceSpec{
60 TaskTemplate: swarm.TaskSpec{
61 ContainerSpec: &swarm.ContainerSpec{
62 Privileges: &swarm.Privileges{
63 CredentialSpec: opts.credentialSpec.value,
64 },
65 },
66 },
67 }
68
69 // set up a function to use as the list function
70 var fakeClient fakeConfigAPIClientList = func(_ context.Context, opts client.ConfigListOptions) (client.ConfigListResult, error) {
71 // we're expecting the filter to have names "foo" and "bar"
72 expected := make(client.Filters).Add("name", "foo", "bar")
73 assert.Assert(t, is.DeepEqual(opts.Filters, expected))
74 return client.ConfigListResult{
75 Items: []swarm.Config{
76 {
77 ID: "fooID",
78 Spec: swarm.ConfigSpec{
79 Annotations: swarm.Annotations{
80 Name: "foo",
81 },
82 },
83 }, {
84 ID: "barID",
85 Spec: swarm.ConfigSpec{
86 Annotations: swarm.Annotations{
87 Name: "bar",
88 },
89 },
90 },
91 },
92 }, nil
93 }
94
95 ctx := context.Background()
96
97 // now call setConfigs
98 err := setConfigs(ctx, fakeClient, service, opts)
99 // verify no error is returned

Callers

nothing calls this directly

Calls 3

SetMethod · 0.95
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…