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

Function TestContainerBackCompat

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

Source from the content-addressed store, hash-verified

580}
581
582func TestContainerBackCompat(t *testing.T) {
583 createdAtTime := time.Now().AddDate(-1, 0, 0) // 1 year ago
584
585 ctrContext := container.Summary{
586 ID: "aabbccddeeff",
587 Names: []string{"/foobar_baz"},
588 Image: "docker.io/library/ubuntu", // should this have canonical format or not?
589 ImageID: "sha256:a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5", // should this have algo-prefix or not?
590 ImageManifestDescriptor: nil,
591 Command: "/bin/sh",
592 Created: createdAtTime.UTC().Unix(),
593 Ports: []container.PortSummary{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}},
594 SizeRw: 123,
595 SizeRootFs: 12345,
596 Labels: map[string]string{"label1": "value1", "label2": "value2"},
597 State: "running",
598 Status: "running",
599 HostConfig: struct {
600 NetworkMode string `json:",omitempty"`
601 Annotations map[string]string `json:",omitempty"`
602 }{
603 NetworkMode: "bridge",
604 Annotations: map[string]string{
605 "com.example.annotation": "hello",
606 },
607 },
608 NetworkSettings: nil,
609 Mounts: nil,
610 }
611
612 tests := []struct {
613 field string
614 expected string
615 }{
616 {field: "ID", expected: "aabbccddeeff"},
617 {field: "Names", expected: "foobar_baz"},
618 {field: "Image", expected: "docker.io/library/ubuntu"},
619 {field: "Command", expected: `"/bin/sh"`},
620 {field: "CreatedAt", expected: time.Unix(createdAtTime.Unix(), 0).String()},
621 {field: "HealthStatus", expected: ""},
622 {field: "RunningFor", expected: "12 months ago"},
623 {field: "Ports", expected: "8080/tcp"},
624 {field: "Status", expected: "running"},
625 {field: "Size", expected: "123B (virtual 12.3kB)"},
626 {field: "Labels", expected: "label1=value1,label2=value2"},
627 {field: "Mounts", expected: ""},
628 }
629
630 for _, tc := range tests {
631 t.Run(tc.field, func(t *testing.T) {
632 buf := new(bytes.Buffer)
633 ctx := Context{Format: Format(fmt.Sprintf("{{ .%s }}", tc.field)), Output: buf}
634 assert.NilError(t, ContainerWrite(ctx, []container.Summary{ctrContext}))
635 assert.Check(t, is.Equal(strings.TrimSpace(buf.String()), tc.expected))
636 })
637 }
638}
639

Callers

nothing calls this directly

Calls 3

FormatTypeAlias · 0.85
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…