Skip to content

Commit f277c93

Browse files
authored
fix: stabilize extra-host test by removing external network dependency (#1741)
Replace curl HTTP request against a stale Google IP with getent hosts, which only checks DNS resolution and needs no network connectivity.
1 parent fec2e80 commit f277c93

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

tests/test-cases/extra-host/.gitlab-ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
test-job:
3-
image: docker.io/curlimages/curl:7.69.1
3+
image: docker.io/alpine:3.21
44
script:
5-
- curl -I http://fake-google.com
5+
- getent hosts fake-google.com
66

77
service-job:
8-
image: docker.io/curlimages/curl:7.69.1
8+
image: docker.io/alpine:3.21
99
services:
10-
- name: docker.io/alpine:latest
10+
- name: docker.io/alpine:3.21
1111
entrypoint: ["/bin/sh", "-c"]
1212
command: ["getent hosts fake-google.com"]
1313
script:

tests/test-cases/extra-host/integration.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {WriteStreamsMock} from "../../../src/write-streams.js";
22
import {handler} from "../../../src/handler.js";
3-
import chalk from "chalk-template";
43
import {initSpawnSpy} from "../../mocks/utils.mock.js";
54
import {WhenStatics} from "../../mocks/when-statics.js";
65
import fs from "fs-extra";
@@ -17,14 +16,11 @@ test("extra-host <test-job>", async () => {
1716
extraHost: ["fake-google.com:142.250.185.206"],
1817
}, writeStreams);
1918

20-
const expected = [
21-
chalk`{blueBright test-job} {greenBright >} HTTP/1.1 404 Not Found`,
22-
];
23-
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
19+
expect(writeStreams.stdoutLines.join("\n")).toMatch(/142\.250\.185\.206/);
2420
});
2521

2622
test("extra-host <service-job>", async () => {
27-
await fs.promises.rm("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:latest-0.log", {force: true});
23+
await fs.promises.rm("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:3.21-0.log", {force: true});
2824

2925
const writeStreams = new WriteStreamsMock();
3026
await handler({
@@ -34,6 +30,6 @@ test("extra-host <service-job>", async () => {
3430
}, writeStreams);
3531

3632
expect(writeStreams.stdoutLines.join("\n")).toMatch(/true/);
37-
expect(await fs.pathExists("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:latest-0.log")).toEqual(true);
38-
expect(await fs.readFile("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:latest-0.log", "utf-8")).toMatch(/142.250.185.206/);
33+
expect(await fs.pathExists("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:3.21-0.log")).toEqual(true);
34+
expect(await fs.readFile("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:3.21-0.log", "utf-8")).toMatch(/142.250.185.206/);
3935
});

0 commit comments

Comments
 (0)