MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestContainerList

Function TestContainerList

cmd/nerdctl/container/container_list_linux_test.go:126–166  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestContainerList(t *testing.T) {
127 base, testContainer := preparePsTestContainer(t, "list", true)
128
129 // hope there are no tests running parallel
130 base.Cmd("ps", "-n", "1", "-s").AssertOutWithFunc(func(stdout string) error {
131 // An example of nerdctl/docker ps -n 1 -s
132 // CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
133 // be8d386c991e docker.io/library/busybox:latest "top" 1 second ago Up c1 16.0 KiB (virtual 1.3 MiB)
134
135 lines := strings.Split(strings.TrimSpace(stdout), "\n")
136 if len(lines) < 2 {
137 return fmt.Errorf("expected at least 2 lines, got %d", len(lines))
138 }
139
140 tab := tabutil.NewReader("CONTAINER ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS\tNAMES\tSIZE")
141 err := tab.ParseHeader(lines[0])
142 if err != nil {
143 return fmt.Errorf("failed to parse header: %v", err)
144 }
145
146 container, _ := tab.ReadRow(lines[1], "NAMES")
147 assert.Equal(t, container, testContainer.name)
148
149 image, _ := tab.ReadRow(lines[1], "IMAGE")
150 assert.Equal(t, image, testutil.CommonImage)
151
152 size, _ := tab.ReadRow(lines[1], "SIZE")
153
154 // there is some difference between nerdctl and docker in calculating the size of the container
155 expectedSize := "26.2MB (virtual "
156 if !nerdtest.IsDocker() {
157 expectedSize = "25.0 MiB (virtual "
158 }
159
160 if !strings.Contains(size, expectedSize) {
161 return fmt.Errorf("expect container size %s, but got %s", expectedSize, size)
162 }
163
164 return nil
165 })
166}
167
168func TestContainerListWideMode(t *testing.T) {
169 testutil.DockerIncompatible(t)

Callers

nothing calls this directly

Calls 7

NewReaderFunction · 0.92
IsDockerFunction · 0.92
AssertOutWithFuncMethod · 0.80
ParseHeaderMethod · 0.80
ReadRowMethod · 0.80
preparePsTestContainerFunction · 0.70
CmdMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…