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

Function TestIPFSCompBuild

cmd/nerdctl/ipfs/ipfs_compose_linux_test.go:190–270  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

188}
189
190func TestIPFSCompBuild(t *testing.T) {
191 testCase := nerdtest.Setup()
192
193 var ipfsServer test.TestableCommand
194 var comp *testutil.ComposeDir
195
196 const mainImageCIDKey = "mainImageCIDKey"
197 safePort, err := portlock.Acquire(0)
198 assert.NilError(t, err)
199 var listenAddr = "localhost:" + strconv.Itoa(safePort)
200
201 testCase.Require = require.All(
202 // Linux only
203 require.Linux,
204 // Obviously not docker supported
205 require.Not(nerdtest.Docker),
206 nerdtest.Build,
207 nerdtest.IPFS,
208 )
209
210 testCase.Setup = func(data test.Data, helpers test.Helpers) {
211 // Get alpine
212 helpers.Ensure("pull", "--quiet", testutil.NginxAlpineImage)
213 // Start a local ipfs backed registry
214 // FIXME: this is bad and likely to collide with other tests
215 ipfsServer = helpers.Command("ipfs", "registry", "serve", "--listen-registry", listenAddr)
216 // This should not take longer than that
217 ipfsServer.WithTimeout(30 * time.Second)
218 ipfsServer.Background()
219 // Apparently necessary to let it start...
220 time.Sleep(time.Second)
221
222 // Save nginx to ipfs
223 data.Labels().Set(mainImageCIDKey, pushToIPFS(helpers, testutil.NginxAlpineImage))
224
225 const dockerComposeYAML = `
226services:
227 web:
228 build: .
229 ports:
230 - 8081:80
231`
232 dockerfile := fmt.Sprintf(`FROM %s/ipfs/%s
233COPY index.html /usr/share/nginx/html/index.html
234`, listenAddr, data.Labels().Get(mainImageCIDKey))
235
236 comp = testutil.NewComposeDir(t, dockerComposeYAML)
237 comp.WriteFile("Dockerfile", dockerfile)
238 comp.WriteFile("index.html", data.Identifier("indexhtml"))
239 }
240
241 testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
242 if ipfsServer != nil {
243 helpers.Anyhow("rmi", "-f", data.Labels().Get(mainImageCIDKey))
244 ipfsServer.Signal(os.Kill)
245 }
246 if comp != nil {
247 helpers.Anyhow("compose", "-f", comp.YAMLFullPath(), "down", "-v")

Callers

nothing calls this directly

Calls 15

WithTimeoutMethod · 0.95
BackgroundMethod · 0.95
WriteFileMethod · 0.95
SignalMethod · 0.95
YAMLFullPathMethod · 0.95
CleanUpMethod · 0.95
SetupFunction · 0.92
AcquireFunction · 0.92
NewComposeDirFunction · 0.92
HTTPGetFunction · 0.92
pushToIPFSFunction · 0.85
AssertMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…