(t *testing.T)
| 188 | } |
| 189 | |
| 190 | func 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 = ` |
| 226 | services: |
| 227 | web: |
| 228 | build: . |
| 229 | ports: |
| 230 | - 8081:80 |
| 231 | ` |
| 232 | dockerfile := fmt.Sprintf(`FROM %s/ipfs/%s |
| 233 | COPY 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") |
nothing calls this directly
no test coverage detected
searching dependent graphs…