Skip to content

Commit

Permalink
Fixed the getTags call to get the latest tags (#211)
Browse files Browse the repository at this point in the history
* Fixed the getTags call to get the latest tags

- Unit and Integration tests were not catching the bug, fixed the tests, then fixed the code

* Cleaned up the logging of currentLatestVersion
  • Loading branch information
tkmcmaster authored Mar 26, 2024
1 parent 0bca329 commit 0a67dec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions controller/integration/pewpew.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ describe("PewPew Util Integration", () => {
expect(match, "pewpew match").to.not.equal(null);
expect(match!.length, "pewpew match.length").to.be.greaterThan(1);
const version: string = match![1];
expect(global.currentLatestVersion, "global.currentLatestVersion").to.equal(version);
// If this runs before the other acceptance tests populate the shared pewpew versions
if (!sharedPewPewVersions) {
sharedPewPewVersions = [latestPewPewVersion];
Expand Down Expand Up @@ -271,7 +272,10 @@ describe("PewPew Util Integration", () => {

it("getCurrentPewPewLatestVersion", async () => {
expect(currentPewPewLatestVersion, "currentPewPewLatestVersion").to.not.equal(undefined);
// We need to reset this to force it to go to S3. Otherwise it just returns the value
global.currentLatestVersion = undefined;
const result = await getCurrentPewPewLatestVersion();
log("getCurrentPewPewLatestVersion: " + result, LogLevel.DEBUG, result);
expect(result, "result").to.equal(currentPewPewLatestVersion);
});
});
Expand Down
11 changes: 8 additions & 3 deletions controller/pages/api/util/pewpew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export async function postPewPew (parsedForm: ParsedForm, authPermissions: AuthP
// If latest version is being updated:
if (latest) {
global.currentLatestVersion = version;
log("Sucessfully updated currentLatestVersion. ", LogLevel.INFO, version);
log("Sucessfully updated currentLatestVersion: " + version, LogLevel.INFO, version);
}
log(PEWPEW_BINARY_EXECUTABLE + " only uploaded, version: " + versionLogDisplay, LogLevel.INFO, { files, authPermissions: getLogAuthPermissions(authPermissions) });
return { json: { message: "PewPew uploaded, version: " + versionLogDisplay }, status: 200 };
Expand Down Expand Up @@ -237,13 +237,18 @@ export async function getCurrentPewPewLatestVersion (): Promise<string | undefin
}
try {
const pewpewTags = await s3.getTags({
s3Folder: `${PEWPEW_BINARY_FOLDER}/${latestPewPewVersion}/`,
s3Folder: `${PEWPEW_BINARY_FOLDER}/${latestPewPewVersion}`,
filename: PEWPEW_BINARY_EXECUTABLE
});
global.currentLatestVersion = pewpewTags && pewpewTags.get(VERSION_TAG_NAME); // <- change to get the tag here
if (global.currentLatestVersion) {
log("Sucessfully retrieved currentLatestVersion: " + global.currentLatestVersion, LogLevel.INFO, global.currentLatestVersion);
} else {
log("Failed to retriev currentLatestVersion: " + global.currentLatestVersion, LogLevel.WARN, global.currentLatestVersion);
}
return global.currentLatestVersion;
} catch (error) {
log("Could not load latest pewpew in file", LogLevel.ERROR, error);
log("Could not load latest pewpew in file for currentLatestVersion", LogLevel.ERROR, error);
throw error;
}
}
11 changes: 11 additions & 0 deletions controller/test/pewpew.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ describe("PewPew Util", () => {

after(() => {
resetMockS3();
// We need to reset this to force it to go to S3 later. Otherwise it just returns the value
global.currentLatestVersion = undefined;
});

describe("getCurrentPewPewLatestVersion", () => {
it("getCurrentPewPewLatestVersion should return version with latest tag from S3", (done: Mocha.Done) => {
const expected = "0.5.13";
mockGetObjectTagging(new Map([[VERSION_TAG_NAME, expected]]));
// We need to reset this to force it to go to S3. Otherwise it just returns the value
global.currentLatestVersion = undefined;
getCurrentPewPewLatestVersion().then((result: string | undefined) => {
log("getPewPewVersionsInS3()", LogLevel.DEBUG, result);
expect(result).to.equal(expected);
Expand Down Expand Up @@ -186,6 +190,7 @@ describe("PewPew Util", () => {
files
};
log("postPewPew parsedForm", LogLevel.DEBUG, parsedForm);
global.currentLatestVersion = "0.0.1"; // bogus value
postPewPew(parsedForm, authAdmin).then((res: ErrorResponse) => {
log("postPewPew res", LogLevel.DEBUG, res);
expect(res.status, JSON.stringify(res.json)).to.equal(200);
Expand All @@ -195,6 +200,12 @@ describe("PewPew Util", () => {
expect(body.message).to.not.equal(undefined);
expect(body.message).to.include("PewPew uploaded, version");
expect(body.message).to.include("as latest");
const match: RegExpMatchArray | null = body.message.match(/PewPew uploaded, version: (\d+\.\d+\.\d+)/);
log(`pewpew match: ${match}`, LogLevel.DEBUG, match);
expect(match, "pewpew match").to.not.equal(null);
expect(match!.length, "pewpew match.length").to.be.greaterThan(1);
const version: string = match![1];
expect(global.currentLatestVersion, "global.currentLatestVersion").to.equal(version);
done();
}).catch((error) => {
log("postPewPew error", LogLevel.ERROR, error);
Expand Down

0 comments on commit 0a67dec

Please sign in to comment.