fix: stabilize extra-host test by removing external network dependency (#1741)
Some checks are pending
build / yamllint (push) Waiting to run
build / smoke-test (push) Waiting to run
build / eslint (push) Waiting to run
build / unused-deps (push) Waiting to run
build / jest (push) Waiting to run
build / CodeQL (push) Waiting to run

Replace curl HTTP request against a stale Google IP with getent hosts,
which only checks DNS resolution and needs no network connectivity.
This commit is contained in:
Mads Jon Nielsen
2026-02-06 19:25:45 +01:00
committed by GitHub
parent fec2e80f02
commit f277c93e1f
2 changed files with 8 additions and 12 deletions

View File

@@ -1,13 +1,13 @@
---
test-job:
image: docker.io/curlimages/curl:7.69.1
image: docker.io/alpine:3.21
script:
- curl -I http://fake-google.com
- getent hosts fake-google.com
service-job:
image: docker.io/curlimages/curl:7.69.1
image: docker.io/alpine:3.21
services:
- name: docker.io/alpine:latest
- name: docker.io/alpine:3.21
entrypoint: ["/bin/sh", "-c"]
command: ["getent hosts fake-google.com"]
script:

View File

@@ -1,6 +1,5 @@
import {WriteStreamsMock} from "../../../src/write-streams.js";
import {handler} from "../../../src/handler.js";
import chalk from "chalk-template";
import {initSpawnSpy} from "../../mocks/utils.mock.js";
import {WhenStatics} from "../../mocks/when-statics.js";
import fs from "fs-extra";
@@ -17,14 +16,11 @@ test("extra-host <test-job>", async () => {
extraHost: ["fake-google.com:142.250.185.206"],
}, writeStreams);
const expected = [
chalk`{blueBright test-job} {greenBright >} HTTP/1.1 404 Not Found`,
];
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
expect(writeStreams.stdoutLines.join("\n")).toMatch(/142\.250\.185\.206/);
});
test("extra-host <service-job>", async () => {
await fs.promises.rm("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:latest-0.log", {force: true});
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});
const writeStreams = new WriteStreamsMock();
await handler({
@@ -34,6 +30,6 @@ test("extra-host <service-job>", async () => {
}, writeStreams);
expect(writeStreams.stdoutLines.join("\n")).toMatch(/true/);
expect(await fs.pathExists("tests/test-cases/extra-host/.gitlab-ci-local/services-output/service-job/docker.io/alpine:latest-0.log")).toEqual(true);
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/);
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);
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/);
});