(t *testing.T)
| 310 | } |
| 311 | |
| 312 | func TestServiceContextWriteJSONField(t *testing.T) { |
| 313 | services := client.ServiceListResult{ |
| 314 | Items: []swarm.Service{ |
| 315 | { |
| 316 | ID: "01_baz", |
| 317 | Spec: swarm.ServiceSpec{ |
| 318 | Annotations: swarm.Annotations{Name: "baz"}, |
| 319 | Mode: swarm.ServiceMode{ |
| 320 | Global: &swarm.GlobalService{}, |
| 321 | }, |
| 322 | }, |
| 323 | ServiceStatus: &swarm.ServiceStatus{ |
| 324 | RunningTasks: 2, |
| 325 | DesiredTasks: 4, |
| 326 | }, |
| 327 | }, |
| 328 | { |
| 329 | ID: "24_bar", |
| 330 | Spec: swarm.ServiceSpec{ |
| 331 | Annotations: swarm.Annotations{Name: "bar"}, |
| 332 | Mode: swarm.ServiceMode{ |
| 333 | Replicated: &swarm.ReplicatedService{}, |
| 334 | }, |
| 335 | }, |
| 336 | ServiceStatus: &swarm.ServiceStatus{ |
| 337 | RunningTasks: 2, |
| 338 | DesiredTasks: 4, |
| 339 | }, |
| 340 | }, |
| 341 | }, |
| 342 | } |
| 343 | out := bytes.NewBufferString("") |
| 344 | err := ListFormatWrite(formatter.Context{Format: "{{json .Name}}", Output: out}, services) |
| 345 | if err != nil { |
| 346 | t.Fatal(err) |
| 347 | } |
| 348 | for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") { |
| 349 | msg := fmt.Sprintf("Output: line %d: %s", i, line) |
| 350 | var s string |
| 351 | err := json.Unmarshal([]byte(line), &s) |
| 352 | assert.NilError(t, err, msg) |
| 353 | assert.Check(t, is.Equal(services.Items[i].Spec.Name, s), msg) |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | func TestServiceContext_Ports(t *testing.T) { |
| 358 | c := serviceContext{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…