MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestComposeUpBuild

Function TestComposeUpBuild

cmd/nerdctl/compose/compose_up_linux_test.go:135–205  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

133}
134
135func TestComposeUpBuild(t *testing.T) {
136 testCase := nerdtest.Setup()
137
138 testCase.Require = nerdtest.Build
139
140 testCase.Setup = func(data test.Data, helpers test.Helpers) {
141 hostPort, err := portlock.Acquire(0)
142 if err != nil {
143 helpers.T().Log(fmt.Sprintf("Failed to acquire port: %v", err))
144 helpers.T().FailNow()
145 }
146
147 composeYAML := fmt.Sprintf(`
148services:
149 web:
150 build: .
151 ports:
152 - %d:80
153`, hostPort)
154 dockerfile := fmt.Sprintf(`FROM %s
155COPY index.html /usr/share/nginx/html/index.html
156`, testutil.NginxAlpineImage)
157 indexHTML := data.Identifier("indexHTML")
158
159 composePath := data.Temp().Save(composeYAML, "compose.yaml")
160 data.Temp().Save(dockerfile, "Dockerfile")
161 data.Temp().Save(indexHTML, "index.html")
162
163 projectName := filepath.Base(filepath.Dir(composePath))
164 t.Logf("projectName=%q", projectName)
165
166 data.Labels().Set("hostPort", strconv.Itoa(hostPort))
167 data.Labels().Set("composeYAML", composePath)
168 data.Labels().Set("indexHTML", data.Temp().Path("index.html"))
169
170 helpers.Ensure("compose", "-f", composePath, "up", "-d", "--build")
171 nerdtest.EnsureContainerStarted(helpers, serviceparser.DefaultContainerName(projectName, "web", "1"))
172 }
173
174 testCase.SubTests = []*test.Case{
175 {
176 Description: "HTTP request to the web container",
177 Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
178 return &test.Expected{
179 Output: func(stdout string, t tig.T) {
180 host := fmt.Sprintf("http://127.0.0.1:%s", data.Labels().Get("hostPort"))
181 resp, err := nettestutil.HTTPGet(host, 5, false)
182 assert.NilError(t, err)
183 respBody, err := io.ReadAll(resp.Body)
184 assert.NilError(t, err)
185 t.Log(fmt.Sprintf("respBody=%q", respBody))
186 assert.Assert(t, strings.Contains(string(respBody), data.Labels().Get("indexHTML")))
187 },
188 }
189 },
190 },
191 }
192

Callers

nothing calls this directly

Calls 15

SetupFunction · 0.92
AcquireFunction · 0.92
EnsureContainerStartedFunction · 0.92
DefaultContainerNameFunction · 0.92
HTTPGetFunction · 0.92
ReleaseFunction · 0.92
AssertMethod · 0.80
LogMethod · 0.65
TMethod · 0.65
FailNowMethod · 0.65
IdentifierMethod · 0.65
SaveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…