From 9016d6f9b217641e0d8b71008efe313cff518370 Mon Sep 17 00:00:00 2001 From: Jonas Fierlings Date: Fri, 26 Jul 2024 08:16:22 +0200 Subject: [PATCH] fix: Allow boolean values in variables (#1302) See . --- src/parser.ts | 4 ++-- .../invalid-variables-bool/.gitlab-ci.yml | 6 ----- ...integration.invalid-variables-bool.test.ts | 24 ------------------- 3 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 tests/test-cases/invalid-variables-bool/.gitlab-ci.yml delete mode 100644 tests/test-cases/invalid-variables-bool/integration.invalid-variables-bool.test.ts diff --git a/src/parser.ts b/src/parser.ts index 62752c94c..d02c2972a 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -138,7 +138,7 @@ export class Parser { let value = _value; if (value === null) value = ""; // variable's values are nullable assert( - typeof value === "string" || typeof value === "number", + typeof value === "string" || typeof value === "number" || typeof value === "boolean", chalk`{blueBright ${jobName}} has invalid variables hash of key value pairs. ${key}=${value}` ); jobData.variables[key] = String(value); @@ -148,7 +148,7 @@ export class Parser { const service = jobData.services[i]; for (const [key, value] of Object.entries(service.variables || {})) { assert( - typeof value === "string" || typeof value === "number", + typeof value === "string" || typeof value === "number" || typeof value === "boolean", chalk`{blueBright ${jobName}.services[${i}]} has invalid variables hash of key value pairs. ${key}=${value}` ); jobData.services[i].variables[key] = String(value); diff --git a/tests/test-cases/invalid-variables-bool/.gitlab-ci.yml b/tests/test-cases/invalid-variables-bool/.gitlab-ci.yml deleted file mode 100644 index e20997a92..000000000 --- a/tests/test-cases/invalid-variables-bool/.gitlab-ci.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -test-job: - variables: - INVALID: true - script: - - echo "Test something ${INVALID}" diff --git a/tests/test-cases/invalid-variables-bool/integration.invalid-variables-bool.test.ts b/tests/test-cases/invalid-variables-bool/integration.invalid-variables-bool.test.ts deleted file mode 100644 index f5c6acdde..000000000 --- a/tests/test-cases/invalid-variables-bool/integration.invalid-variables-bool.test.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {WriteStreamsMock} from "../../../src/write-streams"; -import {handler} from "../../../src/handler"; -import chalk from "chalk"; -import assert, {AssertionError} from "assert"; -import {initSpawnSpy} from "../../mocks/utils.mock"; -import {WhenStatics} from "../../mocks/when-statics"; - -beforeAll(() => { - initSpawnSpy(WhenStatics.all); -}); - -test("invalid-variables-bool ", async () => { - try { - const writeStreams = new WriteStreamsMock(); - await handler({ - cwd: "tests/test-cases/invalid-variables-bool", - job: ["test-job"], - }, writeStreams); - expect(true).toBe(false); - } catch (e) { - assert(e instanceof AssertionError, "e is not instanceof AssertionError"); - expect(e.message).toBe(chalk`{blueBright test-job} has invalid variables hash of key value pairs. INVALID=true`); - } -});