(t testing.TB, cli *CLI, service string, targetPort int)
| 136 | } |
| 137 | |
| 138 | func publishedPortForService(t testing.TB, cli *CLI, service string, targetPort int) int { |
| 139 | t.Helper() |
| 140 | res := cli.RunDockerComposeCmd(t, "ps", "--format=json", service) |
| 141 | var svc struct { |
| 142 | Publishers []struct { |
| 143 | TargetPort int |
| 144 | PublishedPort int |
| 145 | } |
| 146 | } |
| 147 | assert.NilError(t, json.Unmarshal([]byte(res.Stdout()), &svc), |
| 148 | "Failed to parse `%s` output", res.Cmd.String()) |
| 149 | var found bool |
| 150 | var port int |
| 151 | for _, pp := range svc.Publishers { |
| 152 | if pp.TargetPort == targetPort { |
| 153 | found = true |
| 154 | port = pp.PublishedPort |
| 155 | } |
| 156 | } |
| 157 | assert.Assert(t, found, "No published port for target port %d\nService: %s", targetPort, res.Combined()) |
| 158 | return port |
| 159 | } |
no test coverage detected