From 9367431d560330d1a4d4ce221383ea471d698145 Mon Sep 17 00:00:00 2001 From: Bryan Lopez Date: Wed, 20 Mar 2024 08:01:10 -0400 Subject: [PATCH] adding tag checks for all versions --- controller/pages/api/util/testmanager.ts | 4 +- controller/test/testmanager.spec.ts | 48 ++++++++++++++++++------ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/controller/pages/api/util/testmanager.ts b/controller/pages/api/util/testmanager.ts index 366f53be..ac1c40d8 100644 --- a/controller/pages/api/util/testmanager.ts +++ b/controller/pages/api/util/testmanager.ts @@ -457,7 +457,7 @@ export async function validateYamlfile ( additionalFileNames: string[], bypassParser: boolean | undefined, authPermissions: AuthPermissions, - validateLegacyOnly?: boolean + validateLegacyOnly?: boolean | undefined ): Promise { let testRunTimeMn: number | undefined; let bucketSizeMs: number | undefined; @@ -479,7 +479,7 @@ export async function validateYamlfile ( dummyEnvironmentVariables[splunkPath] = dummySplunkPath; } // Pass pewpew version legacy/scripting - yamlParser = await YamlParser.parseYamlFile(yamlFile.filepath, dummyEnvironmentVariables, validateLegacyOnly); + yamlParser = await YamlParser.parseYamlFile(yamlFile.filepath, dummyEnvironmentVariables, await validateLegacyOnly); } catch (error) { return { json: { message: `yamlFile: ${yamlFile.originalFilename || yamlFile.filepath} failed to parse`, error: formatError(error) }, status: 400 }; } diff --git a/controller/test/testmanager.spec.ts b/controller/test/testmanager.spec.ts index 32c67cc8..6e829c6e 100644 --- a/controller/test/testmanager.spec.ts +++ b/controller/test/testmanager.spec.ts @@ -40,7 +40,7 @@ import { TestSchedulerIntegration } from "./testscheduler.spec"; import { VERSION_TAG_NAME } from "../pages/api/util/pewpew"; import { expect } from "chai"; import { latestPewPewVersion } from "../pages/api/util/clientutil"; -import { mockGetObjectTagging } from "./mock"; +import { mockGetObjectTagging, mockS3, mockUploadObject, resetMockS3 } from "./mock"; import path from "path"; logger.config.LogFileName = "ppaas-controller"; @@ -320,6 +320,8 @@ describe("TestManager", () => { const validateLegacyOnlySuite: Mocha.Suite = describe("getValidateLegacyOnly", () => { before (() => { + mockS3(); + mockUploadObject(); mockGetObjectTagging(new Map([["tagName", "tagValue"]])); const validateLegacyOnlyArray: [string, boolean][] = [ ["0.4.0", true], @@ -345,14 +347,33 @@ describe("TestManager", () => { throw error; } })); + // Tags + validateLegacyOnlySuite.addTest(new MochaTest(version + " should return tags for that version", async () => { + try { + mockGetObjectTagging(new Map([[VERSION_TAG_NAME, version]])); + await getValidateLegacyOnly(version).then((result: boolean | undefined) => { + log("getValidateLegacyOnly()", LogLevel.INFO, result); + expect(result).to.equal(expected) + }); + } catch (error) { + throw error; + } + })) } }); + after(() => { + resetMockS3(); + }); + it("should return undefined for undefined", async () => { try { - await getValidateLegacyOnly(latestPewPewVersion).then((result: boolean | undefined) => { - expect(result).to.equal(undefined); - }); + const expected = ""; + mockGetObjectTagging(new Map([[VERSION_TAG_NAME, expected]])); + await getValidateLegacyOnly(undefined).then((result: boolean | undefined) => { + log("getValidateLegacyOnly()", LogLevel.INFO, result); + expect(result).to.equal(undefined) + }) } catch (error) { throw error; } @@ -360,21 +381,26 @@ describe("TestManager", () => { it("should return undefined for empty string", async () => { try { - mockGetObjectTagging(new Map([[VERSION_TAG_NAME, ""]])); - await getValidateLegacyOnly(latestPewPewVersion).then((result: boolean | undefined) => { - expect(result).to.equal(undefined); - }); + const expected = ""; + mockGetObjectTagging(new Map([[VERSION_TAG_NAME, expected]])); + await getValidateLegacyOnly(expected).then((result: boolean | undefined) => { + log("getValidateLegacyOnly()", LogLevel.INFO, result); + expect(result).to.equal(undefined) + }) } catch (error) { throw error; } }); + it("should return undefined for latest", async () => { try { const expected = "latest"; mockGetObjectTagging(new Map([[VERSION_TAG_NAME, expected]])); - await getValidateLegacyOnly(latestPewPewVersion).then((result: boolean | undefined) => { - expect(result).to.equal(expected); - }); + await getValidateLegacyOnly(expected).then((result: boolean | undefined) => { + log("getValidateLegacyOnly()", LogLevel.INFO, result); + expect(result).to.equal(undefined) + }) + } catch (error) { throw error; }