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

Function TestToServiceNetwork

cli/command/service/opts_test.go:218–265  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

216}
217
218func TestToServiceNetwork(t *testing.T) {
219 nws := []network.Inspect{
220 {
221 Network: network.Network{
222 Name: "aaa-network",
223 ID: "id555",
224 },
225 },
226 {
227 Network: network.Network{
228 Name: "mmm-network",
229 ID: "id999",
230 },
231 },
232 {
233 Network: network.Network{
234 Name: "zzz-network",
235 ID: "id111",
236 },
237 },
238 }
239
240 apiClient := &fakeClient{
241 networkInspectFunc: func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (client.NetworkInspectResult, error) {
242 for _, nw := range nws {
243 if nw.ID == networkID || nw.Name == networkID {
244 return client.NetworkInspectResult{Network: nw}, nil
245 }
246 }
247 return client.NetworkInspectResult{}, fmt.Errorf("network not found: %s", networkID)
248 },
249 }
250
251 nwo := opts.NetworkOpt{}
252 assert.NilError(t, nwo.Set("zzz-network"))
253 assert.NilError(t, nwo.Set("mmm-network"))
254 assert.NilError(t, nwo.Set("aaa-network"))
255
256 o := newServiceOptions()
257 o.mode = "replicated"
258 o.networks = nwo
259
260 ctx := context.Background()
261 flags := newCreateCommand(nil).Flags()
262 service, err := o.ToService(ctx, apiClient, flags)
263 assert.NilError(t, err)
264 assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id111"}, {Target: "id555"}, {Target: "id999"}}, service.TaskTemplate.Networks))
265}
266
267func TestToServicePidsLimit(t *testing.T) {
268 flags := newCreateCommand(nil).Flags()

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
newServiceOptionsFunction · 0.85
ToServiceMethod · 0.80
newCreateCommandFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…