Skip to content

Commit 608f560

Browse files
committed
Introspect AWS to get hostname of deployed API Gateway
Still doesn't work correctly with CI yet, but at least we don't need to manually set hostname before running integration test locally.
1 parent ff7c624 commit 608f560

File tree

3 files changed

+123
-4
lines changed

3 files changed

+123
-4
lines changed

__tests__/integration/api-integration.test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
const {test, expect} = require("@jest/globals"),
1+
const {beforeAll, test, expect} = require("@jest/globals"),
2+
AWS = require("aws-sdk"),
23
https = require('https')
34

5+
let apiEndpoint
6+
7+
beforeAll(async () => {
8+
const apiName = process.env.hasOwnProperty('API_NAME') ? process.env['API_NAME'] : 'sam-app'
9+
console.log(`Looking for API Gateway named [${apiName}]`)
10+
11+
const apis = await new AWS.ApiGatewayV2().getApis().promise()
12+
13+
apiEndpoint = apis.Items.find(api => api.Name === apiName).ApiEndpoint
14+
console.log(`Using Coffee Store API at [${apiEndpoint}]`)
15+
})
16+
417
test('API should return 200 exit code and expected content', async () => {
5-
const apiEndpoint = process.env.COFFEE_API_ENDPOINT
618
expect(apiEndpoint).toBeDefined()
719

820
const result = await getWithBody(`${apiEndpoint}/`)

package-lock.json

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"private": true,
55
"devDependencies": {
66
"@jest/globals": "26.x",
7-
"jest": "26.x"
7+
"jest": "26.x",
8+
"aws-sdk": "2.x"
89
},
910
"scripts": {
1011
"test": "npm run unit-test && npm run integration-test",
1112
"unit-test": "jest --config __tests__/jest-unit.config.js",
12-
"integration-test": "jest --config __tests__/jest-integration.config.js"
13+
"integration-test": "AWS_SDK_LOAD_CONFIG=true jest --config __tests__/jest-integration.config.js"
1314
}
1415
}

0 commit comments

Comments
 (0)