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

Function TestPublish

pkg/e2e/publish_test.go:158–208  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestPublish(t *testing.T) {
159 c := NewParallelCLI(t)
160 const projectName = "compose-e2e-publish"
161 const registryName = projectName + "-registry"
162 c.RunDockerCmd(t, "run", "--name", registryName, "-P", "-d", "registry:3")
163 port := c.RunDockerCmd(t, "inspect", "--format", `{{ (index (index .NetworkSettings.Ports "5000/tcp") 0).HostPort }}`, registryName).Stdout()
164 registry := "localhost:" + strings.TrimSpace(port)
165 t.Cleanup(func() {
166 c.RunDockerCmd(t, "rm", "--force", registryName)
167 })
168
169 // Wait for registry to be ready
170 registryURL := "http://" + registry + "/v2/"
171 poll.WaitOn(t, func(l poll.LogT) poll.Result {
172 resp, err := http.Get(registryURL) //nolint:gosec,noctx
173 if err != nil {
174 return poll.Continue("registry not ready: %v", err)
175 }
176 _ = resp.Body.Close()
177 if resp.StatusCode < 500 {
178 return poll.Success()
179 }
180 return poll.Continue("registry not ready, status %d", resp.StatusCode)
181 }, poll.WithTimeout(10*time.Second), poll.WithDelay(100*time.Millisecond))
182
183 res := c.RunDockerComposeCmd(t, "-f", "./fixtures/publish/oci/compose.yaml", "-f", "./fixtures/publish/oci/compose-override.yaml",
184 "-p", projectName, "publish", "--with-env", "--yes", "--insecure-registry", registry+"/test:test")
185 res.Assert(t, icmd.Expected{ExitCode: 0})
186
187 // docker exec -it compose-e2e-publish-registry tree /var/lib/registry/docker/registry/v2/
188
189 cmd := c.NewDockerComposeCmd(t, "--verbose", "--project-name=oci",
190 "--insecure-registry", registry,
191 "-f", fmt.Sprintf("oci://%s/test:test", registry), "config")
192 res = icmd.RunCmd(cmd, func(cmd *icmd.Cmd) {
193 cmd.Env = append(cmd.Env, "XDG_CACHE_HOME="+t.TempDir())
194 })
195 res.Assert(t, icmd.Expected{ExitCode: 0})
196 assert.Equal(t, res.Stdout(), `name: oci
197services:
198 app:
199 environment:
200 HELLO: WORLD
201 image: alpine
202 networks:
203 default: null
204networks:
205 default:
206 name: oci_default
207`)
208}

Callers

nothing calls this directly

Calls 7

NewParallelCLIFunction · 0.85
RunDockerCmdMethod · 0.80
RunDockerComposeCmdMethod · 0.80
NewDockerComposeCmdMethod · 0.80
RunCmdMethod · 0.80
TempDirMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected