TestSetConfigsOnlyCredSpec tests that even if a CredentialSpec is the only config needed, setConfigs still works
(t *testing.T)
| 124 | // TestSetConfigsOnlyCredSpec tests that even if a CredentialSpec is the only |
| 125 | // config needed, setConfigs still works |
| 126 | func TestSetConfigsOnlyCredSpec(t *testing.T) { |
| 127 | opts := &serviceOptions{ |
| 128 | credentialSpec: credentialSpecOpt{ |
| 129 | value: &swarm.CredentialSpec{ |
| 130 | Config: "foo", |
| 131 | }, |
| 132 | source: "config://foo", |
| 133 | }, |
| 134 | } |
| 135 | |
| 136 | service := &swarm.ServiceSpec{ |
| 137 | TaskTemplate: swarm.TaskSpec{ |
| 138 | ContainerSpec: &swarm.ContainerSpec{ |
| 139 | Privileges: &swarm.Privileges{ |
| 140 | CredentialSpec: opts.credentialSpec.value, |
| 141 | }, |
| 142 | }, |
| 143 | }, |
| 144 | } |
| 145 | |
| 146 | // set up a function to use as the list function |
| 147 | fakeClient := fakeConfigAPIClientList(func(_ context.Context, opts client.ConfigListOptions) (client.ConfigListResult, error) { |
| 148 | expected := make(client.Filters).Add("name", "foo") |
| 149 | assert.Assert(t, is.DeepEqual(opts.Filters, expected)) |
| 150 | |
| 151 | return client.ConfigListResult{ |
| 152 | Items: []swarm.Config{ |
| 153 | { |
| 154 | ID: "fooID", |
| 155 | Spec: swarm.ConfigSpec{ |
| 156 | Annotations: swarm.Annotations{ |
| 157 | Name: "foo", |
| 158 | }, |
| 159 | }, |
| 160 | }, |
| 161 | }, |
| 162 | }, nil |
| 163 | }) |
| 164 | |
| 165 | // now call setConfigs |
| 166 | ctx := context.Background() |
| 167 | err := setConfigs(ctx, fakeClient, service, opts) |
| 168 | // verify no error is returned |
| 169 | assert.NilError(t, err) |
| 170 | |
| 171 | credSpecConfigValue := service.TaskTemplate.ContainerSpec.Privileges.CredentialSpec.Config |
| 172 | assert.Equal(t, credSpecConfigValue, "fooID") |
| 173 | |
| 174 | configRefs := service.TaskTemplate.ContainerSpec.Configs |
| 175 | assert.Assert(t, is.Contains(configRefs, &swarm.ConfigReference{ |
| 176 | ConfigID: "fooID", |
| 177 | ConfigName: "foo", |
| 178 | Runtime: &swarm.ConfigReferenceRuntimeTarget{}, |
| 179 | })) |
| 180 | } |
| 181 | |
| 182 | // TestSetConfigsOnlyConfigs verifies setConfigs when only configs (and not a |
| 183 | // CredentialSpec) is needed. |
nothing calls this directly
no test coverage detected
searching dependent graphs…