Skip to content

Commit

Permalink
Removed additional hard-coded latest and pewpew strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tkmcmaster committed Mar 26, 2024
1 parent 0d32d85 commit c3f2099
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 22 deletions.
5 changes: 3 additions & 2 deletions agent/createtest/pewpewtest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
LogLevel,
MessageType,
PEWPEW_VERSION_LATEST,
PpaasS3File,
PpaasS3Message,
PpaasTestId,
Expand Down Expand Up @@ -83,7 +84,7 @@ describe("PewPewTest Create Test", () => {
s3Folder,
yamlFile: createTestFilename,
testRunTimeMn: 2,
version: "latest",
version: PEWPEW_VERSION_LATEST,
envVariables: { SERVICE_URL_AGENT: "127.0.0.1:8080" },
restartOnFailure: false,
additionalFiles: [],
Expand Down Expand Up @@ -309,7 +310,7 @@ describe("PewPewTest Create Test", () => {
testId: ppaasTestId.testId,
s3Folder,
yamlFile: createTestFilename,
version: "latest",
version: PEWPEW_VERSION_LATEST,
envVariables: {
SERVICE_URL_AGENT: "127.0.0.1:8080",
RUST_LOG: "info",
Expand Down
10 changes: 5 additions & 5 deletions agent/src/pewpewtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export async function findYamlCreatedFiles (localPath: string, yamlFile: string,
// Export for testing
export function versionGreaterThan (currentVersion: string, compareVersion: string): boolean {
// If the current version is latest then we're always greater than or equal to
if (currentVersion === "latest") { return true; }
if (currentVersion === util.PEWPEW_VERSION_LATEST) { return true; }
// If the compareVersion is latest, then only currrentVersion=latest is greater
if (compareVersion === "latest") { return false; }
if (compareVersion === util.PEWPEW_VERSION_LATEST) { return false; }

return semver.gt(currentVersion, compareVersion);
}
Expand Down Expand Up @@ -373,10 +373,10 @@ export class PewPewTest {
// Download the pewpew executable if needed
if (DOWNLOAD_PEWPEW) {
// version check in the test message
const version = this.testMessage.version || "latest";
const version = this.testMessage.version || util.PEWPEW_VERSION_LATEST;
const localDirectory = this.localPath;
const s3Folder = "pewpew/" + version;
this.log(`os.platform() = ${platform()}`, LogLevel.DEBUG, { version, s3Folder });
const s3Folder = `${util.PEWPEW_BINARY_FOLDER}/${version}`;
this.log(`os.platform() = ${platform()}`, LogLevel.DEBUG, { version, s3Folder, filename: util.PEWPEW_BINARY_EXECUTABLE });
const pewpewS3File: PpaasS3File = new PpaasS3File({
filename: util.PEWPEW_BINARY_EXECUTABLE,
s3Folder,
Expand Down
6 changes: 4 additions & 2 deletions agent/src/tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
LogLevel,
PEWPEW_BINARY_FOLDER,
PEWPEW_VERSION_LATEST,
PpaasTestId,
PpaasTestMessage,
TestMessage,
Expand All @@ -19,7 +21,7 @@ logger.config.LogFileName = "ppaas-agent";

const UNIT_TEST_FOLDER = process.env.UNIT_TEST_FOLDER || "test";
const yamlFile = "basicwithenv.yaml";
const version = "latest";
const version = PEWPEW_VERSION_LATEST;
const PEWPEW_PATH = process.env.PEWPEW_PATH || pathJoin(UNIT_TEST_FOLDER, util.PEWPEW_BINARY_EXECUTABLE);
const buildTestContents = `
vars:
Expand Down Expand Up @@ -72,7 +74,7 @@ export async function buildTest ({
}),
s3.uploadFile({
filepath: PEWPEW_PATH,
s3Folder: `pewpew/${version}`,
s3Folder: `${PEWPEW_BINARY_FOLDER}/${version}`,
publicRead: false,
contentType: "application/octet-stream"
})
Expand Down
7 changes: 4 additions & 3 deletions agent/test/pewpewtest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
LogLevel,
PEWPEW_VERSION_LATEST,
PpaasTestId,
PpaasTestStatus,
TestStatus,
Expand Down Expand Up @@ -78,17 +79,17 @@ describe("PewPewTest", () => {

describe("versionGreaterThan", () => {
it("latest is always greater", (done: Mocha.Done) => {
expect(versionGreaterThan("latest", "")).to.equal(true);
expect(versionGreaterThan(PEWPEW_VERSION_LATEST, "")).to.equal(true);
done();
});

it("latest is always greater than latest", (done: Mocha.Done) => {
expect(versionGreaterThan("latest", "latest")).to.equal(true);
expect(versionGreaterThan(PEWPEW_VERSION_LATEST, PEWPEW_VERSION_LATEST)).to.equal(true);
done();
});

it("greater than latest is false", (done: Mocha.Done) => {
expect(versionGreaterThan("0.5.5", "latest")).to.equal(false);
expect(versionGreaterThan("0.5.5", PEWPEW_VERSION_LATEST)).to.equal(false);
done();
});

Expand Down
3 changes: 2 additions & 1 deletion common/integration/ppaasteststatus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
LogLevel,
PEWPEW_VERSION_LATEST,
PpaasTestId,
PpaasTestStatus,
TestStatus,
Expand Down Expand Up @@ -33,7 +34,7 @@ describe("PpaasTestStatus", () => {
resultsFilename: [ppaasTestId.testId + ".json"],
status: TestStatus.Running,
errors: ["Test Error"],
version: "latest",
version: PEWPEW_VERSION_LATEST,
queueName: "unittest",
userId: "unittestuser"
};
Expand Down
2 changes: 2 additions & 0 deletions common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PEWPEW_BINARY_EXECUTABLE,
PEWPEW_BINARY_EXECUTABLE_NAMES,
PEWPEW_BINARY_FOLDER,
PEWPEW_VERSION_LATEST,
SYSTEM_NAME,
poll,
sleep
Expand Down Expand Up @@ -42,6 +43,7 @@ export {
PEWPEW_BINARY_EXECUTABLE,
PEWPEW_BINARY_EXECUTABLE_NAMES,
PEWPEW_BINARY_FOLDER,
PEWPEW_VERSION_LATEST,
SYSTEM_NAME,
poll,
sleep,
Expand Down
1 change: 1 addition & 0 deletions common/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const CONTROLLER_ENV = process.env.CONTROLLER_ENV;
export const AGENT_ENV = process.env.AGENT_ENV;

export const PEWPEW_BINARY_FOLDER: string = "pewpew";
export const PEWPEW_VERSION_LATEST: string = "latest";
export const PEWPEW_BINARY_EXECUTABLE_LINUX = "pewpew";
export const PEWPEW_BINARY_EXECUTABLE_WINDOWS = "pewpew.exe";
export const PEWPEW_BINARY_EXECUTABLE_MAC = "pewpew.mac";
Expand Down
44 changes: 39 additions & 5 deletions common/test/ppaastestmessage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { AgentQueueDescription, LogLevel, PpaasTestMessage, TestMessage, log } from "../src/index";
import {
AgentQueueDescription,
LogLevel,
PEWPEW_VERSION_LATEST,
PpaasTestMessage,
TestMessage,
log
} from "../src/index";
import { UNIT_TEST_FILENAME, UNIT_TEST_KEY_PREFIX } from "../test/s3.spec";
import {
mockReceiveMessageAttributes,
Expand Down Expand Up @@ -36,7 +43,7 @@ describe("PpaasTestMessage", () => {
},
restartOnFailure: true,
bucketSizeMs: 60000,
version: "latest",
version: PEWPEW_VERSION_LATEST,
additionalFiles: ["file1", "file2"],
userId: "[email protected]",
bypassParser: false
Expand All @@ -45,7 +52,16 @@ describe("PpaasTestMessage", () => {
before(() => {
mockSqs();
log("QUEUE_URL_TEST=" + [...QUEUE_URL_TEST], LogLevel.DEBUG);
ppaasUnitTestMessage = new PPaasUnitTestMessage({ testId, s3Folder, yamlFile, testRunTimeMn, envVariables: {}, restartOnFailure: true, bucketSizeMs: 60000, version: "latest" });
ppaasUnitTestMessage = new PPaasUnitTestMessage({
testId,
s3Folder,
yamlFile,
testRunTimeMn,
envVariables: {},
restartOnFailure: true,
bucketSizeMs: 60000,
version: PEWPEW_VERSION_LATEST
});
});

after(() => {
Expand Down Expand Up @@ -102,7 +118,16 @@ describe("PpaasTestMessage", () => {

it("extendMessageVisibility should succeed", (done: Mocha.Done) => {
if (ppaasTestMessage === undefined) {
ppaasTestMessage = new PpaasTestMessage({ testId, s3Folder, yamlFile, testRunTimeMn, envVariables: {}, restartOnFailure: true, bucketSizeMs: 60000, version: "latest" });
ppaasTestMessage = new PpaasTestMessage({
testId,
s3Folder,
yamlFile,
testRunTimeMn,
envVariables: {},
restartOnFailure: true,
bucketSizeMs: 60000,
version: PEWPEW_VERSION_LATEST
});
}
if (ppaasTestMessage.receiptHandle === undefined) {
ppaasTestMessage.receiptHandle = "unit-test-receipt-handle";
Expand All @@ -112,7 +137,16 @@ describe("PpaasTestMessage", () => {

it("deleteMessageFromQueue should succeed", (done: Mocha.Done) => {
if (ppaasTestMessage === undefined) {
ppaasTestMessage = new PpaasTestMessage({ testId, s3Folder, yamlFile, testRunTimeMn, envVariables: {}, restartOnFailure: true, bucketSizeMs: 60000, version: "latest" });
ppaasTestMessage = new PpaasTestMessage({
testId,
s3Folder,
yamlFile,
testRunTimeMn,
envVariables: {},
restartOnFailure: true,
bucketSizeMs: 60000,
version: PEWPEW_VERSION_LATEST
});
}
if (ppaasTestMessage.receiptHandle === undefined) {
ppaasTestMessage.receiptHandle = "unit-test-receipt-handle";
Expand Down
3 changes: 2 additions & 1 deletion common/test/ppaasteststatus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
LogLevel,
PEWPEW_VERSION_LATEST,
PpaasTestId,
PpaasTestStatus,
TestStatus,
Expand Down Expand Up @@ -46,7 +47,7 @@ describe("PpaasTestStatus", () => {
resultsFilename: [ppaasTestId.testId + ".json"],
status: TestStatus.Running,
errors: ["Test Error"],
version: "latest",
version: PEWPEW_VERSION_LATEST,
queueName: "unittest",
userId: "unittestuser"
};
Expand Down
3 changes: 2 additions & 1 deletion controller/components/TestInfo/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PpaasTestId } from "@fs/ppaas-common/dist/src/ppaastestid";
import React from "react";
import { TestData } from "../../types/testmanager";
import { TestStatus } from "@fs/ppaas-common/dist/types";
import { latestPewPewVersion } from "../../pages/api/util/clientutil";

/**
* Developing and visually testing components in isolation before composing them in your app is useful.
Expand Down Expand Up @@ -40,7 +41,7 @@ const fullTest: Required<TestData> = {
lastUpdated: new Date(Date.now() - 300000),
lastChecked: new Date(Date.now() - 100000),
errors: ["error1", "error2", "error3"],
version: "latest",
version: latestPewPewVersion,
queueName: "unittest",
userId: "[email protected]"
};
Expand Down
4 changes: 3 additions & 1 deletion controller/pages/api/util/clientutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { LogLevel, log } from "./log";
import { TestData, TestManagerError, TestManagerMessage } from "../../../types";
import { AxiosError } from "axios";
import { IncomingMessage } from "http";
// Must import from sub-path to avoid other dependencies
import { PEWPEW_VERSION_LATEST } from "@fs/ppaas-common/dist/src/util/util";
import getConfig from "next/config";
import semver from "semver";

Expand Down Expand Up @@ -116,7 +118,7 @@ export function getHourMinuteFromTimestamp (datetime: number): string {
return date.toTimeString().split(" ")[0];
}

export const latestPewPewVersion: string = "latest";
export const latestPewPewVersion: string = PEWPEW_VERSION_LATEST;

/**
* Sorts the array by versions returning the latest versions first and invalid versions last.
Expand Down
3 changes: 2 additions & 1 deletion controller/pages/api/util/testmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,8 @@ export abstract class TestManager {
let version: string | undefined;
if (fieldKeys.includes("version")) {
// Validate the version is in s3
if (Array.isArray(fields.version) || !fields.version || !await PpaasS3File.existsInS3("pewpew/" + fields.version)) {
if (Array.isArray(fields.version) || !fields.version
|| !await PpaasS3File.existsInS3(`${PEWPEW_BINARY_FOLDER}/${fields.version}/`)) {
return { json: { message: "Received an invalid version: " + fields.version }, status: 400 };
}
version = fields.version;
Expand Down

0 comments on commit c3f2099

Please sign in to comment.