Skip to content

Commit

Permalink
Extended acceptance tests AWS (#233) (#234)
Browse files Browse the repository at this point in the history
* Extended acceptance tests AWS (#233)

* Moved some of the shared acceptance code into a util file.

* Added code to upload files for integration and acceptance tests

* Added code to upload files needed for acceptance tests

* Cleaned up files

* Cleaned up files

* Simplified test more

* Fix acceptance test status file (#235)

* Fixed status file name for acceptance test

* FIxed contentType for Test Status File
  • Loading branch information
tkmcmaster authored Jul 9, 2024
1 parent f6ec9c5 commit 6c1e8f7
Show file tree
Hide file tree
Showing 20 changed files with 738 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
node_modules
.nyc_output/
coverage/
/controller/aws*.sh
testmerge.json
.env.local*
.env.development.local*
Expand Down
1 change: 1 addition & 0 deletions common/src/s3file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class PpaasS3File implements S3File {
this.contentType = "text/x-yaml";
break;
case ".json":
case ".info":
this.contentType = "application/json";
break;
default:
Expand Down
10 changes: 9 additions & 1 deletion controller/acceptance/errorFile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ACCEPTANCE_AWS_PERMISSIONS, integrationUrl, uploadAcceptanceFiles } from "./util";
import { API_ERROR, API_SEARCH, API_TEST, TestData } from "../types";
import { LogLevel, PpaasTestId, TestStatus, log } from "@fs/ppaas-common";
import _axios, { AxiosRequestConfig, AxiosResponse as Response } from "axios";
import { getPpaasTestId, getTestData, integrationUrl } from "./test.spec";
import { getPpaasTestId, getTestData } from "./test.spec";
import { expect } from "chai";

const REDIRECT_TO_S3: boolean = process.env.REDIRECT_TO_S3 === "true";
Expand Down Expand Up @@ -36,6 +37,12 @@ describe("ErrorFile API Integration", function () {
this.timeout(60000);
url = integrationUrl + API_ERROR;
log("ErrorFile tests url=" + url, LogLevel.DEBUG);
if (ACCEPTANCE_AWS_PERMISSIONS) {
const { ppaasTestId } = await uploadAcceptanceFiles();
yamlFile = ppaasTestId.yamlFile;
dateString = ppaasTestId.dateString;
expectedStatus = 200;
} else {
// Initialize to one that will 404 for the build server
const ppaasTestId = await getPpaasTestId();
yamlFile = ppaasTestId.yamlFile;
Expand Down Expand Up @@ -87,6 +94,7 @@ describe("ErrorFile API Integration", function () {
} catch (error) {
log("Could not Search and find Results", LogLevel.ERROR, error);
}
} // end else not ACCEPTANCE_AWS_PERMISSIONS
});

it("GET /error should respond 404 Not Found", (done: Mocha.Done) => {
Expand Down
4 changes: 1 addition & 3 deletions controller/acceptance/healthcheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { API_HEALTHCHECK, API_HEALTHCHECK_HEARTBEAT, API_HEALTHCHECK_S3, API_HEA
import { LogLevel, log } from "@fs/ppaas-common";
import _axios, { AxiosResponse as Response } from "axios";
import { expect } from "chai";
import { integrationUrl } from "./util";

const fetch = _axios.get;

// Beanstalk <SYSTEM_NAME>_<SERVICE_NAME>_URL
const integrationUrl = "http://" + (process.env.BUILD_APP_URL || `localhost:${process.env.PORT || "8081"}`);

describe("Healthcheck Integration", () => {
let url: string;

Expand Down
4 changes: 1 addition & 3 deletions controller/acceptance/pewpew.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import _axios, { AxiosRequestConfig, AxiosResponse as Response } from "axios";
import FormData from "form-data";
import { createReadStream } from "fs";
import { expect } from "chai";
import { integrationUrl } from "./util";
import { latestPewPewVersion } from "../pages/api/util/clientutil";
import path from "path";
import semver from "semver";
Expand Down Expand Up @@ -39,9 +40,6 @@ const UNIT_TEST_FOLDER = process.env.UNIT_TEST_FOLDER || "test";
const PEWPEW_ZIP_LEGACY_FILEPATH = process.env.PEWPEW_ZIP_LEGACY_FILEPATH || path.join(UNIT_TEST_FOLDER, PEWPEW_BINARY_EXECUTABLE + ".zip");
const PEWPEW_ZIP_SCRIPTING_FILEPATH = process.env.PEWPEW_ZIP_SCRIPTING_FILEPATH || path.join(UNIT_TEST_FOLDER + "/scripting", PEWPEW_BINARY_EXECUTABLE + ".zip");

// Beanstalk <SYSTEM_NAME>_<SERVICE_NAME>_URL
const integrationUrl = "http://" + (process.env.BUILD_APP_URL || `localhost:${process.env.PORT || "8081"}`);

let sharedPewPewVersions: string[] | undefined;
let uploadedPewPewVersion: string | undefined;

Expand Down
4 changes: 1 addition & 3 deletions controller/acceptance/queues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import {
import { AgentQueueDescription, LogLevel, log } from "@fs/ppaas-common";
import _axios, { AxiosResponse as Response } from "axios";
import { expect } from "chai";
import { integrationUrl } from "./util";

const fetch = _axios.get;

// Beanstalk <SYSTEM_NAME>_<SERVICE_NAME>_URL
const integrationUrl = "http://" + (process.env.BUILD_APP_URL || `localhost:${process.env.PORT || "8081"}`);

let sharedQueueNames: string[] | undefined;

export async function getQueueNames (): Promise<string[]> {
Expand Down
15 changes: 12 additions & 3 deletions controller/acceptance/resultsFile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ACCEPTANCE_AWS_PERMISSIONS, integrationUrl, uploadAcceptanceFiles } from "./util";
import { API_JSON, API_SEARCH, API_TEST, TestData } from "../types";
import { LogLevel, PpaasTestId, TestStatus, log } from "@fs/ppaas-common";
import _axios, { AxiosRequestConfig, AxiosResponse as Response } from "axios";
import { getPpaasTestId, getTestData, integrationUrl } from "./test.spec";
import { getPpaasTestId, getTestData } from "./test.spec";
import { expect } from "chai";

const REDIRECT_TO_S3: boolean = process.env.REDIRECT_TO_S3 === "true";
Expand Down Expand Up @@ -36,6 +37,13 @@ describe("ResultsFile API Integration", function () {
this.timeout(60000);
url = integrationUrl + API_JSON;
log("ResultsFile tests url=" + url, LogLevel.DEBUG);
if (ACCEPTANCE_AWS_PERMISSIONS) {
const { ppaasTestId, resultsFile: resultsFileName } = await uploadAcceptanceFiles();
yamlFile = ppaasTestId.yamlFile;
dateString = ppaasTestId.dateString;
resultsFile = resultsFileName;
} else {
// Initialize to one that will 404 for the build server
const ppaasTestId = await getPpaasTestId();
yamlFile = ppaasTestId.yamlFile;
dateString = ppaasTestId.dateString;
Expand Down Expand Up @@ -97,7 +105,8 @@ describe("ResultsFile API Integration", function () {
} catch (error) {
log("Could not Search and find Results", LogLevel.ERROR, error);
}
});
} // end else not ACCEPTANCE_AWS_PERMISSIONS
});

it("GET json should respond 404 Not Found", (done: Mocha.Done) => {
fetch(url).then((res: Response) => {
Expand Down Expand Up @@ -179,7 +188,7 @@ describe("ResultsFile API Integration", function () {
log(`GET ${url}/${yamlFile}/${dateString}/${resultsFile}`, LogLevel.DEBUG, { res });
expect(res, "res").to.not.equal(undefined);
// The build server will 404 because there won't be any completed tests, localhost should have some
if (url.includes("localhost")) {
if (url.includes("localhost") || ACCEPTANCE_AWS_PERMISSIONS) {
log(`GET ${url}/${yamlFile}/${dateString}/${resultsFile}`, LogLevel.DEBUG, { data: res.data });
if (REDIRECT_TO_S3) {
expect(res.status, "status").to.equal(302);
Expand Down
3 changes: 2 additions & 1 deletion controller/acceptance/schedule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
TestData,
TestManagerError
} from "../types";
import { BASIC_FILEPATH, getScheduledTestData, integrationUrl, unsetScheduledTestData } from "./test.spec";
import { BASIC_FILEPATH, getScheduledTestData, unsetScheduledTestData } from "./test.spec";
import { LogLevel, TestStatus, log } from "@fs/ppaas-common";
import _axios, { AxiosRequestConfig, AxiosResponse as Response } from "axios";
import { EventInput } from "@fullcalendar/core";
import { expect } from "chai";
import { getQueueNames } from "./queues.spec";
import { integrationUrl } from "./util";
import path from "path";

async function fetch (
Expand Down
13 changes: 10 additions & 3 deletions controller/acceptance/search.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ACCEPTANCE_AWS_PERMISSIONS, integrationUrl, uploadAcceptanceFiles } from "./util";
import { API_SEARCH, API_TEST_STATUS, TestData, TestManagerMessage } from "../types";
import { LogLevel, PpaasTestId, TestStatus, log } from "@fs/ppaas-common";
import _axios, { AxiosRequestConfig, AxiosResponse as Response } from "axios";
import { getTestData, integrationUrl } from "./test.spec";
import { expect } from "chai";
import { getTestData } from "./test.spec";

async function fetch (
url: string,
Expand Down Expand Up @@ -62,8 +63,14 @@ describe("Search API Integration", () => {
before(async () => {
url = integrationUrl + API_SEARCH;
log("search tests url=" + url, LogLevel.DEBUG);
const testData = await getTestData();
s3Folder = testData.s3Folder;
if (ACCEPTANCE_AWS_PERMISSIONS) {
// Populate a finished result
const { ppaasTestId } = await uploadAcceptanceFiles();
s3Folder = ppaasTestId.s3Folder;
} else {
const testData = await getTestData();
s3Folder = testData.s3Folder;
}
});

describe("GET /search", () => {
Expand Down
3 changes: 2 additions & 1 deletion controller/acceptance/stop.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { API_STOP, TestManagerMessage } from "../types";
import { LogLevel, PpaasTestId, log } from "@fs/ppaas-common";
import _axios, { AxiosRequestConfig, AxiosResponse as Response } from "axios";
import { getPpaasTestId, integrationUrl } from "./test.spec";
import { expect } from "chai";
import { getPpaasTestId } from "./test.spec";
import { integrationUrl } from "./util";

async function fetch (
url: string,
Expand Down
12 changes: 5 additions & 7 deletions controller/acceptance/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { createReadStream } from "fs";
import { expect } from "chai";
import { getPewPewVersions } from "./pewpew.spec";
import { getQueueNames } from "./queues.spec";
import { integrationUrl } from "./util";
import { latestPewPewVersion } from "../pages/api/util/clientutil";
import path from "path";

Expand Down Expand Up @@ -68,13 +69,6 @@ const defaultEnvironmentVariables: EnvironmentVariablesFile = {
TEST2: "true"
};

// Beanstalk <SYSTEM_NAME>_<SERVICE_NAME>_URL
export const integrationUrl = "http://" + (process.env.BUILD_APP_URL || `localhost:${process.env.PORT || "8081"}`);

let sharedPpaasTestId: PpaasTestId | undefined;
let sharedTestData: TestData | undefined;
let sharedScheduledTestData: TestData | undefined;

function appendFileData (formData: FormData, formName: string, fileData: string | FileData) {
if (typeof fileData === "string") {
formData.append(formName, fileData);
Expand Down Expand Up @@ -127,6 +121,10 @@ function convertFormDataPutToFormData (formDataPut: FormDataPut): FormData {
return formData;
}

let sharedPpaasTestId: PpaasTestId | undefined;
let sharedTestData: TestData | undefined;
let sharedScheduledTestData: TestData | undefined;

export async function getPpaasTestId (): Promise<PpaasTestId> {
if (sharedPpaasTestId) { return sharedPpaasTestId; }
await initSharedTestData();
Expand Down
7 changes: 7 additions & 0 deletions controller/acceptance/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { uploadAcceptanceFiles } from "../integration/util";

// Shared functions for Acceptance Tests
export const ACCEPTANCE_AWS_PERMISSIONS: boolean = process.env.ACCEPTANCE_AWS_PERMISSIONS?.toLowerCase() === "true";

// Beanstalk <SYSTEM_NAME>_<SERVICE_NAME>_URL
export const integrationUrl = "http://" + (process.env.BUILD_APP_URL || `localhost:${process.env.PORT || "8081"}`);
3 changes: 2 additions & 1 deletion controller/acceptance/yamlFile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { BASIC_FILEPATH, getPpaasTestId, integrationUrl } from "./test.spec";
import { BASIC_FILEPATH, getPpaasTestId } from "./test.spec";
import { LogLevel, PpaasTestId, log } from "@fs/ppaas-common";
import _axios, { AxiosRequestConfig, AxiosResponse as Response } from "axios";
import { API_YAML } from "../types";
import { expect } from "chai";
import { integrationUrl } from "./util";
import path from "path";

const REDIRECT_TO_S3: boolean = process.env.REDIRECT_TO_S3 === "true";
Expand Down
Loading

0 comments on commit 6c1e8f7

Please sign in to comment.