MCPcopy
hub / github.com/docker/compose / publishedPortForService

Function publishedPortForService

pkg/e2e/pause_test.go:138–159  ·  view source on GitHub ↗
(t testing.TB, cli *CLI, service string, targetPort int)

Source from the content-addressed store, hash-verified

136}
137
138func 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}

Callers 1

urlForServiceFunction · 0.85

Calls 2

RunDockerComposeCmdMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected