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

Function TestServiceContextWriteJSONField

cli/command/service/formatter_test.go:312–355  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

310}
311
312func 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
357func TestServiceContext_Ports(t *testing.T) {
358 c := serviceContext{

Callers

nothing calls this directly

Calls 2

ListFormatWriteFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…