TestSetConfigsWithCredSpecAndConfigs tests that the setConfigs function for create correctly looks up the right configs, and correctly handles the credentialSpec
(t *testing.T)
| 40 | // create correctly looks up the right configs, and correctly handles the |
| 41 | // credentialSpec |
| 42 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…