mirror of
https://github.com/firecow/gitlab-ci-local.git
synced 2026-02-07 00:25:45 +01:00
fix: stabilize extra-host test by removing external network dependency (#1741)
Some checks are pending
Some checks are pending
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:
@@ -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:
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user