(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func TestPs(t *testing.T) { |
| 32 | c := NewParallelCLI(t) |
| 33 | const projectName = "e2e-ps" |
| 34 | |
| 35 | // ensure clean state from any previous failed run |
| 36 | c.RunDockerComposeCmdNoCheck(t, "--project-name", projectName, "down", "--remove-orphans") |
| 37 | |
| 38 | res := c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "up", "-d") |
| 39 | assert.NilError(t, res.Error) |
| 40 | t.Cleanup(func() { |
| 41 | _ = c.RunDockerComposeCmd(t, "--project-name", projectName, "down") |
| 42 | }) |
| 43 | |
| 44 | assert.Assert(t, is.Contains(res.Combined(), "Container e2e-ps-busybox-1 Started")) |
| 45 | |
| 46 | t.Run("table", func(t *testing.T) { |
| 47 | res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps") |
| 48 | lines := strings.Split(res.Stdout(), "\n") |
| 49 | assert.Assert(t, is.Len(lines, 4)) |
| 50 | count := 0 |
| 51 | for _, line := range lines[1:3] { |
| 52 | if strings.Contains(line, "e2e-ps-busybox-1") { |
| 53 | assert.Assert(t, is.Contains(line, "127.0.0.1:8001->8000/tcp")) |
| 54 | count++ |
| 55 | } |
| 56 | if strings.Contains(line, "e2e-ps-nginx-1") { |
| 57 | assert.Assert(t, is.Contains(line, "80/tcp, 443/tcp, 8080/tcp")) |
| 58 | count++ |
| 59 | } |
| 60 | } |
| 61 | assert.Equal(t, 2, count, "Did not match both services:\n"+res.Combined()) |
| 62 | }) |
| 63 | |
| 64 | t.Run("json", func(t *testing.T) { |
| 65 | res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", |
| 66 | "--format", "json") |
| 67 | type element struct { |
| 68 | Name string |
| 69 | Project string |
| 70 | Publishers api.PortPublishers |
| 71 | } |
| 72 | var output []element |
| 73 | out := res.Stdout() |
| 74 | dec := json.NewDecoder(strings.NewReader(out)) |
| 75 | for dec.More() { |
| 76 | var s element |
| 77 | assert.NilError(t, dec.Decode(&s), "Failed to unmarshal ps JSON output") |
| 78 | output = append(output, s) |
| 79 | } |
| 80 | |
| 81 | count := 0 |
| 82 | assert.Assert(t, is.Len(output, 2)) |
| 83 | for _, service := range output { |
| 84 | assert.Equal(t, projectName, service.Project) |
| 85 | publishers := service.Publishers |
| 86 | if service.Name == "e2e-ps-busybox-1" { |
| 87 | assert.Assert(t, is.Len(publishers, 1)) |
| 88 | assert.DeepEqual(t, api.PortPublishers{ |
nothing calls this directly
no test coverage detected