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

Function TestContainerContextWriteJSONField

cli/command/formatter/container_test.go:563–580  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

561}
562
563func TestContainerContextWriteJSONField(t *testing.T) {
564 containers := []container.Summary{
565 {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu"},
566 {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu"},
567 }
568 out := bytes.NewBufferString("")
569 err := ContainerWrite(Context{Format: "{{json .ID}}", Output: out}, containers)
570 if err != nil {
571 t.Fatal(err)
572 }
573 for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") {
574 msg := fmt.Sprintf("Output: line %d: %s", i, line)
575 var s string
576 err := json.Unmarshal([]byte(line), &s)
577 assert.NilError(t, err, msg)
578 assert.Check(t, is.Equal(containers[i].ID, s), msg)
579 }
580}
581
582func TestContainerBackCompat(t *testing.T) {
583 createdAtTime := time.Now().AddDate(-1, 0, 0) // 1 year ago

Callers

nothing calls this directly

Calls 2

ContainerWriteFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…