Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dockerize e2e tests #142

Merged
merged 5 commits into from Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
@@ -0,0 +1,2 @@
node_modules
e2e/.env
10 changes: 10 additions & 0 deletions e2e.Dockerfile
@@ -0,0 +1,10 @@
FROM node:20 AS build-env
COPY . /app
WORKDIR /app

RUN npm i

FROM gcr.io/distroless/nodejs20-debian11
COPY --from=build-env /app /app
WORKDIR /app
CMD ["node_modules/jest/bin/jest.js", "-c", "jest.e2e.config.js"]
1 change: 1 addition & 0 deletions e2e/.env.example
Expand Up @@ -2,4 +2,5 @@ TEST_NAMESPACE_1='11111-test'
TEST_AUTH_1='testauth'
TEST_AUTH_2='testauth2'
TEST_NAMESPACE_2='12345-test-stage'
# do not use the scheme for endpoints
ADOBE_STATE_STORE_ENDPOINT_PROD='127.0.0.1:8080'
7 changes: 7 additions & 0 deletions e2e/e2e.js
Expand Up @@ -39,6 +39,13 @@ const initStateEnv = async (n = 1) => {

const waitFor = (ms) => new Promise(resolve => setTimeout(resolve, ms))

test('env vars', () => {
expect(process.env.TEST_AUTH_1).toBeDefined()
expect(process.env.TEST_AUTH_2).toBeDefined()
expect(process.env.TEST_NAMESPACE_1).toBeDefined()
expect(process.env.TEST_NAMESPACE_2).toBeDefined()
})

describe('e2e tests using OpenWhisk credentials (as env vars)', () => {
test('error bad credentials test: auth is ok but namespace is not', async () => {
delete process.env.__OW_API_KEY
Expand Down
22 changes: 21 additions & 1 deletion e2e/e2e.md
Expand Up @@ -10,10 +10,30 @@

Copy the `.env.example` to your own `.env` in this folder.

## Run
For local testing, add the environment variable:

```sh
# do not use the scheme for endpoints
ADOBE_STATE_STORE_ENDPOINT_PROD=127.0.0.1:8080
```

Substitute the host with `host.docker.internal` if you are testing with the Dockerized version of the e2e tests.

## Local Run

`npm run e2e`

## Docker Run

```sh
# build the Docker image
# multi-arch build: see https://docs.docker.com/build/building/multi-platform/#building-multi-platform-images
docker buildx create --name mybuilder --bootstrap --use
docker buildx build -f e2e.Dockerfile --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t aio-lib-state-e2e --load .
# create and run a container based off the Docker image, pass in the environment file
docker run --env-file e2e/.env -t aio-lib-state-e2e
```

## Test overview

Here is a quick overview of what is tested in [e2e.js](./e2e.js):
Expand Down
2 changes: 1 addition & 1 deletion lib/AdobeState.js
Expand Up @@ -145,7 +145,7 @@ class AdobeState {
* @returns {string} the constructed request url
*/
createRequestUrl (key, queryObject = {}) {
const isLocal = this.endpoint.startsWith('localhost') || this.endpoint.startsWith('127.0.0.1')
const isLocal = this.endpoint.startsWith('localhost') || this.endpoint.startsWith('127.0.0.1') || this.endpoint.startsWith('host.docker.internal')
const protocol = isLocal ? 'http' : 'https'
const regionSubdomain = isLocal ? '' : `${this.region}.`
let urlString
Expand Down