Skip to content

Commit

Permalink
(feature) support env vars for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay288 committed Sep 11, 2022
1 parent ebebc88 commit 5945770
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 187 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@google-cloud/compute": "^3.4.0",
"@leoscope/openapi-request-validator": "^12.0.2",
"@leoscope/openapi-response-validator": "^12.0.3",
"@metlo/testing": "^0.0.2",
"@metlo/testing": "^0.0.3",
"@types/async-retry": "^1.4.4",
"@types/newman": "^5.3.0",
"@types/ssh2": "^1.11.5",
Expand Down
7 changes: 6 additions & 1 deletion backend/src/api/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import ApiResponseHandler from "api-response-handler"
import { runTest } from "@metlo/testing"
import { AppDataSource } from "data-source"
import { ApiEndpointTest } from "models"
import { GetEndpointsService } from "services/get-endpoints"

export const runTestHandler = async (
req: Request,
res: Response,
): Promise<void> => {
try {
const testRes = await runTest(req.body.test)
const { test, endpointUuid } = req.body
const endpoint = await GetEndpointsService.getEndpoint(endpointUuid)
let envVars = new Map<string, string>()
envVars.set("baseUrl", `https://${endpoint.host}`)
const testRes = await runTest(test, envVars)
await ApiResponseHandler.success(res, testRes)
} catch (err) {
await ApiResponseHandler.error(res, err)
Expand Down
14 changes: 12 additions & 2 deletions backend/src/services/testing/runAllTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ import { runTest } from "@metlo/testing"

export const runAllTests = async (): Promise<void> => {
const testRepository = AppDataSource.getRepository(ApiEndpointTest)
const allTests = await testRepository.find()
const results = await Promise.all(allTests.map(runTest))
const allTests = await testRepository.find({
relations: {
apiEndpoint: true,
},
})
const results = await Promise.all(
allTests.map(t => {
let envVars = new Map<string, string>()
envVars.set("baseUrl", `https://${t.apiEndpoint.host}`)
return runTest(t, envVars)
}),
)
await Promise.all(
allTests.map((test, testIdx) => {
const runResult = results[testIdx]
Expand Down
102 changes: 51 additions & 51 deletions backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,10 @@
resolved "https://registry.yarnpkg.com/@ioredis/commands/-/commands-1.2.0.tgz#6d61b3097470af1fdbbe622795b8921d42018e11"
integrity sha512-Sx1pU8EM64o2BrqNpEO1CNLtKQwyhuXuqyfH7oGKCk+1a33d2r5saW8zNwm3j6BTExtjrv2BxTgzzkMwts6vGg==

"@jest/expect-utils@^29.0.2":
version "29.0.2"
resolved "https://registry.yarnpkg.com/@jest/expect-utils/-/expect-utils-29.0.2.tgz#00dfcb9e6fe99160c326ba39f7734b984543dea8"
integrity sha512-+wcQF9khXKvAEi8VwROnCWWmHfsJYCZAs5dmuMlJBKk57S6ZN2/FQMIlo01F29fJyT8kV/xblE7g3vkIdTLOjw==
"@jest/expect-utils@^29.0.3":
version "29.0.3"
resolved "https://registry.yarnpkg.com/@jest/expect-utils/-/expect-utils-29.0.3.tgz#f5bb86f5565bf2dacfca31ccbd887684936045b2"
integrity sha512-i1xUkau7K/63MpdwiRqaxgZOjxYs4f0WMTGJnYwUKubsNRZSeQbLorS7+I4uXVF9KQ5r61BUPAUMZ7Lf66l64Q==
dependencies:
jest-get-type "^29.0.0"

Expand All @@ -816,10 +816,10 @@
dependencies:
"@sinclair/typebox" "^0.24.1"

"@jest/types@^29.0.2":
version "29.0.2"
resolved "https://registry.yarnpkg.com/@jest/types/-/types-29.0.2.tgz#5a5391fa7f7f41bf4b201d6d2da30e874f95b6c1"
integrity sha512-5WNMesBLmlkt1+fVkoCjHa0X3i3q8zc4QLTDkdHgCa2gyPZc7rdlZBWgVLqwS1860ZW5xJuCDwAzqbGaXIr/ew==
"@jest/types@^29.0.3":
version "29.0.3"
resolved "https://registry.yarnpkg.com/@jest/types/-/types-29.0.3.tgz#0be78fdddb1a35aeb2041074e55b860561c8ef63"
integrity sha512-coBJmOQvurXjN1Hh5PzF7cmsod0zLIOXpP8KD161mqNlroMhLcwpODiEzi7ZsRl5Z/AIuxpeNm8DCl43F4kz8A==
dependencies:
"@jest/schemas" "^29.0.0"
"@types/istanbul-lib-coverage" "^2.0.0"
Expand Down Expand Up @@ -871,10 +871,10 @@
ajv "^8.3.0"
openapi-types "^12.0.0"

"@metlo/testing@^0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@metlo/testing/-/testing-0.0.2.tgz#0bdbc1e776ed06c16bcd4ba4945d252f58cc06ef"
integrity sha512-9Zuv651aYiH/hWkWc30bedHKl3NbS22Keiyackdnor8/jkzywbt0mEbcdCLb09emlZKMlf++kSSHrk+a6sIZWw==
"@metlo/testing@^0.0.3":
version "0.0.3"
resolved "https://registry.yarnpkg.com/@metlo/testing/-/testing-0.0.3.tgz#aad272bf76e69a2f093222488f372787b0771faf"
integrity sha512-9fkjt51/48zn3lNvowgsL061eBOZUaBE3bb6yN9nXXtDy4457RFSbeGkkF5i3LzFqCMX2BxgIRe8uaJtBt5mAA==
dependencies:
axios "^0.27.2"
expect "^29.0.2"
Expand Down Expand Up @@ -934,9 +934,9 @@
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==

"@sinclair/typebox@^0.24.1":
version "0.24.39"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.39.tgz#21d0c56c295a00e391e20a88a48c11d4a1210ac5"
integrity sha512-GqtkxoAjhTzoMwFg/JYRl+1+miOoyvp6mkLpbMSd2fIQak2KvY00ndlXxxkDBpuCPYkorZeEZf0LEQn9V9NRVQ==
version "0.24.40"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.40.tgz#00ee9b48537b147f6ffc80ebc28ab16d6016ed5c"
integrity sha512-Xint60L8rF0+nRy+6fCjW9jQMmu7fTpbwTBrXZiK6eq/RHDJS7LvWX/0oXC8O7fCePmrY/XdfaTv2HiUDeCq4g==

"@sqltools/formatter@^1.2.2":
version "1.2.3"
Expand Down Expand Up @@ -1544,9 +1544,9 @@ chokidar@^3.5.2:
fsevents "~2.3.2"

ci-info@^3.2.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.3.2.tgz#6d2967ffa407466481c6c90b6e16b3098f080128"
integrity sha512-xmDt/QIAdeZ9+nfdPsaBCpMvHNLFiLdjj59qjqn+6iPe6YmHGQ35sBnQ8uslRBXFmXkiZQOJRjvQeoGppoTjjg==
version "3.4.0"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.4.0.tgz#b28484fd436cbc267900364f096c9dc185efb251"
integrity sha512-t5QdPT5jq3o262DOQ8zA6E1tlH2upmUc4Hlvrbx1pGYJuiiHl7O7rvVNI+l8HTVhd/q3Qc9vqimkNk5yiXsAug==

cli-highlight@^2.1.11:
version "2.1.11"
Expand Down Expand Up @@ -1926,15 +1926,15 @@ [email protected]:
integrity sha512-kEcvvCBByWXGnZy6JUlgAp2gBIUjfCAV6P6TgT1/aaQKcmuAEC4OZTV1I4EWQLz2gxZw76atuVyvHhTxvi0Flw==

expect@^29.0.2:
version "29.0.2"
resolved "https://registry.yarnpkg.com/expect/-/expect-29.0.2.tgz#22c7132400f60444b427211f1d6bb604a9ab2420"
integrity sha512-JeJlAiLKn4aApT4pzUXBVxl3NaZidWIOdg//smaIlP9ZMBDkHZGFd9ubphUZP9pUyDEo7bC6M0IIZR51o75qQw==
version "29.0.3"
resolved "https://registry.yarnpkg.com/expect/-/expect-29.0.3.tgz#6be65ddb945202f143c4e07c083f4f39f3bd326f"
integrity sha512-t8l5DTws3212VbmPL+tBFXhjRHLmctHB0oQbL8eUc6S7NzZtYUhycrFO9mkxA0ZUC6FAWdNi7JchJSkODtcu1Q==
dependencies:
"@jest/expect-utils" "^29.0.2"
"@jest/expect-utils" "^29.0.3"
jest-get-type "^29.0.0"
jest-matcher-utils "^29.0.2"
jest-message-util "^29.0.2"
jest-util "^29.0.2"
jest-matcher-utils "^29.0.3"
jest-message-util "^29.0.3"
jest-util "^29.0.3"

express-session@^1.15.6, express-session@^1.17.3:
version "1.17.3"
Expand Down Expand Up @@ -2501,52 +2501,52 @@ isarray@^1.0.0, isarray@~1.0.0:
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
integrity sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==

jest-diff@^29.0.2:
version "29.0.2"
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-29.0.2.tgz#1a99419efda66f9ee72f91e580e774df95de5ddc"
integrity sha512-b9l9970sa1rMXH1owp2Woprmy42qIwwll/htsw4Gf7+WuSp5bZxNhkKHDuCGKL+HoHn1KhcC+tNEeAPYBkD2Jg==
jest-diff@^29.0.3:
version "29.0.3"
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-29.0.3.tgz#41cc02409ad1458ae1bf7684129a3da2856341ac"
integrity sha512-+X/AIF5G/vX9fWK+Db9bi9BQas7M9oBME7egU7psbn4jlszLFCu0dW63UgeE6cs/GANq4fLaT+8sGHQQ0eCUfg==
dependencies:
chalk "^4.0.0"
diff-sequences "^29.0.0"
jest-get-type "^29.0.0"
pretty-format "^29.0.2"
pretty-format "^29.0.3"

jest-get-type@^29.0.0:
version "29.0.0"
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-29.0.0.tgz#843f6c50a1b778f7325df1129a0fd7aa713aef80"
integrity sha512-83X19z/HuLKYXYHskZlBAShO7UfLFXu/vWajw9ZNJASN32li8yHMaVGAQqxFW1RCFOkB7cubaL6FaJVQqqJLSw==

jest-matcher-utils@^29.0.2:
version "29.0.2"
resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-29.0.2.tgz#0ffdcaec340a9810caee6c73ff90fb029b446e10"
integrity sha512-s62YkHFBfAx0JLA2QX1BlnCRFwHRobwAv2KP1+YhjzF6ZCbCVrf1sG8UJyn62ZUsDaQKpoo86XMTjkUyO5aWmQ==
jest-matcher-utils@^29.0.3:
version "29.0.3"
resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-29.0.3.tgz#b8305fd3f9e27cdbc210b21fc7dbba92d4e54560"
integrity sha512-RsR1+cZ6p1hDV4GSCQTg+9qjeotQCgkaleIKLK7dm+U4V/H2bWedU3RAtLm8+mANzZ7eDV33dMar4pejd7047w==
dependencies:
chalk "^4.0.0"
jest-diff "^29.0.2"
jest-diff "^29.0.3"
jest-get-type "^29.0.0"
pretty-format "^29.0.2"
pretty-format "^29.0.3"

jest-message-util@^29.0.2:
version "29.0.2"
resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-29.0.2.tgz#b2781dfb6a2d1c63830d9684c5148ae3155c6154"
integrity sha512-kcJAgms3ckJV0wUoLsAM40xAhY+pb9FVSZwicjFU9PFkaTNmqh9xd99/CzKse48wPM1ANUQKmp03/DpkY+lGrA==
jest-message-util@^29.0.3:
version "29.0.3"
resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-29.0.3.tgz#f0254e1ffad21890c78355726202cc91d0a40ea8"
integrity sha512-7T8JiUTtDfppojosORAflABfLsLKMLkBHSWkjNQrjIltGoDzNGn7wEPOSfjqYAGTYME65esQzMJxGDjuLBKdOg==
dependencies:
"@babel/code-frame" "^7.12.13"
"@jest/types" "^29.0.2"
"@jest/types" "^29.0.3"
"@types/stack-utils" "^2.0.0"
chalk "^4.0.0"
graceful-fs "^4.2.9"
micromatch "^4.0.4"
pretty-format "^29.0.2"
pretty-format "^29.0.3"
slash "^3.0.0"
stack-utils "^2.0.3"

jest-util@^29.0.2:
version "29.0.2"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.0.2.tgz#c75c5cab7f3b410782f9570a60c5558b5dfb6e3a"
integrity sha512-ozk8ruEEEACxqpz0hN9UOgtPZS0aN+NffwQduR5dVlhN+eN47vxurtvgZkYZYMpYrsmlAEx1XabkB3BnN0GfKQ==
jest-util@^29.0.3:
version "29.0.3"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.0.3.tgz#06d1d77f9a1bea380f121897d78695902959fbc0"
integrity sha512-Q0xaG3YRG8QiTC4R6fHjHQPaPpz9pJBEi0AeOE4mQh/FuWOijFjGXMMOfQEaU9i3z76cNR7FobZZUQnL6IyfdQ==
dependencies:
"@jest/types" "^29.0.2"
"@jest/types" "^29.0.3"
"@types/node" "*"
chalk "^4.0.0"
ci-info "^3.2.0"
Expand Down Expand Up @@ -3149,10 +3149,10 @@ prettier@^2.7.1:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==

pretty-format@^29.0.2:
version "29.0.2"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.0.2.tgz#7f7666a7bf05ba2bcacde61be81c6db64f6f3be6"
integrity sha512-wp3CdtUa3cSJVFn3Miu5a1+pxc1iPIQTenOAn+x5erXeN1+ryTcLesV5pbK/rlW5EKwp27x38MoYfNGaNXDDhg==
pretty-format@^29.0.3:
version "29.0.3"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.0.3.tgz#23d5f8cabc9cbf209a77d49409d093d61166a811"
integrity sha512-cHudsvQr1K5vNVLbvYF/nv3Qy/F/BcEKxGuIeMiVMRHxPOO1RxXooP8g/ZrwAp7Dx+KdMZoOc7NxLHhMrP2f9Q==
dependencies:
"@jest/schemas" "^29.0.0"
ansi-styles "^5.0.0"
Expand Down
10 changes: 5 additions & 5 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metlo",
"version": "0.0.4",
"version": "0.0.5",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -20,17 +20,17 @@
"typescript": "^4.7.4"
},
"dependencies": {
"@metlo/testing": "^0.0.2",
"@metlo/testing": "^0.0.3",
"@types/valid-url": "^1.0.3",
"axios": "^0.27.2",
"chalk": "^4.1.2",
"commander": "^9.4.0",
"dotenv": "^16.0.2",
"enquirer": "^2.3.6",
"nodemon": "^2.0.19",
"tslib": "^2.4.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"valid-url": "^1.0.9",
"chalk": "^4.1.2"
"tslib": "^2.4.0",
"valid-url": "^1.0.9"
}
}
2 changes: 1 addition & 1 deletion cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ program
.command("test")
.description("Run Metlo API tests against a specified host.")
.requiredOption("-h, --host <string>", "The production host in Metlo.")
.requiredOption(
.option(
"-t, --target <string>",
"The host to run tests against against.",
)
Expand Down
14 changes: 11 additions & 3 deletions cli/src/testAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Test, runTest, TestResult, Result } from "@metlo/testing"

interface testAPIArgs {
host: string
target: string
target?: string
}

interface APIEndpoint {
Expand All @@ -30,14 +30,22 @@ const getTests = async (args: testAPIArgs): Promise<TestResponse[]> => {
const testAPI = async (args: testAPIArgs) => {
try {
const tests = await getTests(args)
const outputs = await Promise.all(tests.map(runTest))
const outputs = await Promise.all(
tests.map(t => {
let envVars = new Map<string, string>()
envVars.set("baseUrl", args.target || `https://${t.apiEndpoint.host}`)
return runTest(t, envVars)
}),
)
const testWithOutputs: [TestResponse, Result[]][] = outputs.map((e, i) => [
tests[i],
e,
])
let headerToFailures = new Map<string, TestResult[]>()
testWithOutputs.forEach(([test, results]) => {
const name = `${chalk.red(test.name)}\n${test.apiEndpoint.method} ${test.apiEndpoint.path}`
const name = `${chalk.red(test.name)}\n${test.apiEndpoint.method} ${
test.apiEndpoint.path
}`
const failureResults = results
.flatMap(e => e.testResults)
.filter(e => !e.success)
Expand Down
Loading

0 comments on commit 5945770

Please sign in to comment.