(t *testing.T)
| 124 | } |
| 125 | |
| 126 | func 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 | |
| 168 | func TestContainerListWideMode(t *testing.T) { |
| 169 | testutil.DockerIncompatible(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…