Skip to content

Commit

Permalink
Merge branch 'bc/2529/cleanup-integration-tests' into bc/2529/cleanup…
Browse files Browse the repository at this point in the history
…-integration-tests-refactor
  • Loading branch information
BlairCurrey committed Mar 27, 2024
2 parents 148dfab + 9c4d2e8 commit 31f92b9
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 51 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/lint_test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ jobs:

- name: Setup hosts
run: |
echo "127.0.0.1 host.docker.internal" | sudo tee -a /etc/hosts
echo "127.0.0.1 cloud-nine-wallet-test-backend" | sudo tee -a /etc/hosts
echo "127.0.0.1 cloud-nine-wallet-test-auth" | sudo tee -a /etc/hosts
echo "127.0.0.1 happy-life-bank-test-backend" | sudo tee -a /etc/hosts
echo "127.0.0.1 happy-life-bank-test-auth" | sudo tee -a /etc/hosts
- name: Build dependencies
run: pnpm --filter integration build:deps
Expand Down
9 changes: 8 additions & 1 deletion packages/auth/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { knex } = require('knex')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { GenericContainer } = require('testcontainers')
const { GenericContainer, Wait } = require('testcontainers')

const POSTGRES_PORT = 5432

Expand All @@ -20,6 +20,13 @@ module.exports = async (globalConfig) => {
.withEnvironment({
POSTGRES_PASSWORD: 'password'
})
.withHealthCheck({
test: ['CMD-SHELL', 'pg_isready -d testing'],
interval: 10000,
timeout: 5000,
retries: 5
})
.withWaitStrategy(Wait.forHealthCheck())
.start()

process.env.AUTH_DATABASE_URL = `postgresql://postgres:password@localhost:${postgresContainer.getMappedPort(
Expand Down
31 changes: 31 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 15 additions & 21 deletions test/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Integration tests', (): void => {
describe('Requests', (): void => {
test('Can Get Non-Existing Wallet Address', async (): Promise<void> => {
const notFoundWalletAddress =
'https://host.docker.internal:4100/accounts/asmith'
'https://happy-life-bank-test-backend:4100/accounts/asmith'

const handleWebhookEventSpy = jest.spyOn(
hlb.integrationServer.webhookEventHandler,
Expand Down Expand Up @@ -83,24 +83,20 @@ describe('Integration tests', (): void => {
const { consentInteraction } = testActions

const receiverWalletAddressUrl =
'http://host.docker.internal:4100/accounts/pfry'
'https://happy-life-bank-test-backend:4100/accounts/pfry'
const senderWalletAddressUrl =
'http://host.docker.internal:3100/accounts/gfranklin'
'https://cloud-nine-wallet-test-backend:3100/accounts/gfranklin'
const amountValueToSend = '100'

const receiverWalletAddress = await c9.opClient.walletAddress.get({
url: receiverWalletAddressUrl
})
expect(receiverWalletAddress.id).toBe(
receiverWalletAddressUrl.replace('http', 'https')
)
expect(receiverWalletAddress.id).toBe(receiverWalletAddressUrl)

const senderWalletAddress = await c9.opClient.walletAddress.get({
url: senderWalletAddressUrl
})
expect(senderWalletAddress.id).toBe(
senderWalletAddressUrl.replace('http', 'https')
)
expect(senderWalletAddress.id).toBe(senderWalletAddressUrl)

const incomingPaymentGrant = await grantRequestIncomingPayment(
receiverWalletAddress
Expand Down Expand Up @@ -148,24 +144,20 @@ describe('Integration tests', (): void => {
const { consentInteractionWithInteractRef } = testActions

const receiverWalletAddressUrl =
'http://host.docker.internal:4100/accounts/pfry'
'https://happy-life-bank-test-backend:4100/accounts/pfry'
const senderWalletAddressUrl =
'http://host.docker.internal:3100/accounts/gfranklin'
'https://cloud-nine-wallet-test-backend:3100/accounts/gfranklin'
const amountValueToSend = '100'

const receiverWalletAddress = await c9.opClient.walletAddress.get({
url: receiverWalletAddressUrl
})
expect(receiverWalletAddress.id).toBe(
receiverWalletAddressUrl.replace('http', 'https')
)
expect(receiverWalletAddress.id).toBe(receiverWalletAddressUrl)

const senderWalletAddress = await c9.opClient.walletAddress.get({
url: senderWalletAddressUrl
})
expect(senderWalletAddress.id).toBe(
senderWalletAddressUrl.replace('http', 'https')
)
expect(senderWalletAddress.id).toBe(senderWalletAddressUrl)

const incomingPaymentGrant = await grantRequestIncomingPayment(
receiverWalletAddress
Expand Down Expand Up @@ -219,7 +211,7 @@ describe('Integration tests', (): void => {
} = testActions.admin

const senderWalletAddress = await c9.accounts.getByWalletAddressUrl(
'https://host.docker.internal:3100/accounts/gfranklin'
'https://cloud-nine-wallet-test-backend:3100/accounts/gfranklin'
)
assert(senderWalletAddress?.walletAddressID)
const senderWalletAddressId = senderWalletAddress.walletAddressID
Expand All @@ -233,7 +225,8 @@ describe('Integration tests', (): void => {
assetScale: 2,
value: value as unknown as bigint
},
walletAddressUrl: 'https://host.docker.internal:4100/accounts/pfry'
walletAddressUrl:
'https://happy-life-bank-test-backend:4100/accounts/pfry'
}

const receiver = await createReceiver(createReceiverInput)
Expand All @@ -257,7 +250,7 @@ describe('Integration tests', (): void => {
} = testActions.admin

const senderWalletAddress = await c9.accounts.getByWalletAddressUrl(
'https://host.docker.internal:3100/accounts/gfranklin'
'https://cloud-nine-wallet-test-backend:3100/accounts/gfranklin'
)
assert(senderWalletAddress?.walletAddressID)
const senderWalletAddressId = senderWalletAddress.walletAddressID
Expand All @@ -271,7 +264,8 @@ describe('Integration tests', (): void => {
assetScale: 2,
value: value as unknown as bigint
},
walletAddressUrl: 'https://host.docker.internal:4100/accounts/lars'
walletAddressUrl:
'https://happy-life-bank-test-backend:4100/accounts/lars'
}

const receiver = await createReceiver(createReceiverInput)
Expand Down
4 changes: 3 additions & 1 deletion test/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build:deps": "pnpm --filter mock-account-service-lib build",
"testenv:compose": "docker compose -f ./testenv/cloud-nine-wallet/docker-compose.yml -f ./testenv/happy-life-bank/docker-compose.yml -f ./testenv/docker-compose.yml",
"test": "jest",
"run-tests": "./scripts/run-tests.sh"
"run-tests": "./scripts/run-tests.sh",
"hostile": "hostile"
},
"keywords": [],
"author": "",
Expand All @@ -21,6 +22,7 @@
"@types/koa-bodyparser": "^4.3.12",
"@types/node": "^18.19.19",
"dotenv": "^16.4.1",
"hostile": "^1.4.0",
"koa": "^2.15.0",
"mock-account-service-lib": "workspace:*",
"yaml": "^2.3.4"
Expand Down
26 changes: 23 additions & 3 deletions test/integration/scripts/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# This script runs the integration tests. It starts the test environment, runs the tests,
# saves the container logs to a file, and stops the containers.
# and stops the containers. It saves the container logs to a file and edits /etc/hosts.
# Usage:
# ./script.sh # Run the script with default options
# ./script.sh --build # Skip building the docker images and internal test dependencies (-nb or --no-build)
Expand All @@ -27,16 +27,36 @@ if [ "$build_flag" == "--build" ]; then
pnpm --filter integration build:deps
fi

# setup hosts
addHost() {
local hostname="$1"

# check first to avoid sudo prompt if host is already set
if pnpm --filter integration hostile list | grep -q "127.0.0.1 $hostname"; then
echo "$hostname already set"
else
sudo pnpm --filter integration hostile set 127.0.0.1 "$hostname"
if [ $? -ne 0 ]; then
echo "Error: Failed to write hosts to hostfile."
exit 1
fi
fi
}
addHost "cloud-nine-wallet-test-backend"
addHost "cloud-nine-wallet-test-auth"
addHost "happy-life-bank-test-backend"
addHost "happy-life-bank-test-auth"

# idempotent start
pnpm --filter integration testenv:compose down --volumes
pnpm --filter integration testenv:compose up -d --wait $build_flag

if [ $? -ne 0 ]; then
echo "Error: Failed to start containers."
exit 1
fi

# run tests
mkdir -p ./tmp
pnpm --filter integration testenv:compose logs -f > "$log_file" 2>&1 &

pnpm --filter integration test
pnpm --filter integration testenv:compose down --volumes
8 changes: 4 additions & 4 deletions test/integration/testenv/cloud-nine-wallet/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OPEN_PAYMENTS_URL=https://host.docker.internal:3100
AUTH_SERVER_DOMAIN=http://host.docker.internal:3106
OPEN_PAYMENTS_URL=https://cloud-nine-wallet-test-backend:3100
AUTH_SERVER_DOMAIN=http://cloud-nine-wallet-test-auth:3106
INTEGRATION_SERVER_PORT=8888
WALLET_ADDRESS_URL=https://host.docker.internal:3100/.well-known/pay
GRAPHQL_URL=http://host.docker.internal:3101/graphql
WALLET_ADDRESS_URL=https://cloud-nine-wallet-test-backend:3100/.well-known/pay
GRAPHQL_URL=http://cloud-nine-wallet-test-backend:3101/graphql
# matches pfry key id
KEY_ID=keyid-97a3a431-8ee1-48fc-ac85-70e2f5eba8e5
12 changes: 5 additions & 7 deletions test/integration/testenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ services:
ADMIN_PORT: 3101
OPEN_PAYMENTS_PORT: 3100
DATABASE_URL: postgresql://cloud_nine_wallet_test_backend:cloud_nine_wallet_test_backend@shared-database/cloud_nine_wallet_test_backend
OPEN_PAYMENTS_URL: https://host.docker.internal:3100
WALLET_ADDRESS_URL: https://host.docker.internal:3100/.well-known/pay
OPEN_PAYMENTS_URL: https://cloud-nine-wallet-test-backend:3100
WALLET_ADDRESS_URL: https://cloud-nine-wallet-test-backend:3100/.well-known/pay
# matches pfry key id
KEY_ID: keyid-97a3a431-8ee1-48fc-ac85-70e2f5eba8e5
PRIVATE_KEY_FILE: /workspace/private-key.pem
AUTH_SERVER_INTROSPECTION_URL: http://host.docker.internal:3107
AUTH_SERVER_GRANT_URL: http://host.docker.internal:3106
AUTH_SERVER_INTROSPECTION_URL: http://cloud-nine-wallet-test-auth:3107
AUTH_SERVER_GRANT_URL: http://cloud-nine-wallet-test-auth:3106
ILP_ADDRESS: test.cloud-nine-wallet-test
STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU=
WEBHOOK_URL: http://host.docker.internal:8888/webhooks
Expand All @@ -53,11 +53,9 @@ services:
- '3103:3103'
- '3106:3106'
- '3107:3107'
extra_hosts:
- 'host.docker.internal:host-gateway'
environment:
NODE_ENV: ${NODE_ENV:-development}
AUTH_SERVER_DOMAIN: http://host.docker.internal:3106
AUTH_SERVER_DOMAIN: http://cloud-nine-wallet-test-auth:3106
AUTH_DATABASE_URL: postgresql://cloud_nine_wallet_test_auth:cloud_nine_wallet_test_auth@shared-database/cloud_nine_wallet_test_auth
INTROSPECTION_PORT: 3107
AUTH_PORT: 3106
Expand Down
2 changes: 1 addition & 1 deletion test/integration/testenv/cloud-nine-wallet/seed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ assets:
peeringAsset: 'USD'
peers:
- initialLiquidity: '100000'
peerUrl: http://host.docker.internal:4102
peerUrl: http://happy-life-bank-test-backend:4102
peerIlpAddress: test.happy-life-bank-test
liquidityThreshold: 10000
accounts:
Expand Down
8 changes: 4 additions & 4 deletions test/integration/testenv/happy-life-bank/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OPEN_PAYMENTS_URL=https://host.docker.internal:4100
AUTH_SERVER_DOMAIN=http://host.docker.internal:4106
OPEN_PAYMENTS_URL=https://happy-life-bank-test-backend:4100
AUTH_SERVER_DOMAIN=http://happy-life-bank-test-auth:4106
INTEGRATION_SERVER_PORT=8889
WALLET_ADDRESS_URL=https://host.docker.internal:4100/accounts/pfry
GRAPHQL_URL=http://host.docker.internal:4101/graphql
WALLET_ADDRESS_URL=https://happy-life-bank-test-backend:4100/accounts/pfry
GRAPHQL_URL=http://happy-life-bank-test-backend:4101/graphql
# matches pfry key id
KEY_ID=keyid-97a3a431-8ee1-48fc-ac85-70e2f5eba8e5
12 changes: 5 additions & 7 deletions test/integration/testenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ services:
environment:
NODE_ENV: development
LOG_LEVEL: debug
OPEN_PAYMENTS_URL: https://host.docker.internal:4100
WALLET_ADDRESS_URL: https://host.docker.internal:4100/.well-known/pay
OPEN_PAYMENTS_URL: https://happy-life-bank-test-backend:4100
WALLET_ADDRESS_URL: https://happy-life-bank-test-backend:4100/.well-known/pay
ADMIN_PORT: 4101
CONNECTOR_PORT: 4102
OPEN_PAYMENTS_PORT: 4100
DATABASE_URL: postgresql://happy_life_bank_test_backend:happy_life_bank_test_backend@shared-database/happy_life_bank_test_backend
AUTH_SERVER_GRANT_URL: http://host.docker.internal:4106
AUTH_SERVER_INTROSPECTION_URL: http://host.docker.internal:4107
AUTH_SERVER_GRANT_URL: http://happy-life-bank-test-auth:4106
AUTH_SERVER_INTROSPECTION_URL: http://happy-life-bank-test-auth:4107
# matches pfry key id
KEY_ID: keyid-97a3a431-8ee1-48fc-ac85-70e2f5eba8e5
PRIVATE_KEY_FILE: /workspace/private-key.pem
Expand Down Expand Up @@ -53,12 +53,10 @@ services:
- '4103:4103'
- '4106:4106'
- '4107:4107'
extra_hosts:
- 'host.docker.internal:host-gateway'
environment:
NODE_ENV: development
AUTH_DATABASE_URL: postgresql://happy_life_bank_test_auth:happy_life_bank_test_auth@shared-database/happy_life_bank_test_auth
AUTH_SERVER_DOMAIN: http://host.docker.internal:4106
AUTH_SERVER_DOMAIN: http://happy-life-bank-test-auth:4106
INTROSPECTION_PORT: 4107
ADMIN_PORT: 4103
AUTH_PORT: 4106
Expand Down
2 changes: 1 addition & 1 deletion test/integration/testenv/happy-life-bank/seed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ assets:
peeringAsset: 'USD'
peers:
- initialLiquidity: '1000000000000'
peerUrl: http://host.docker.internal:3102
peerUrl: http://cloud-nine-wallet-test-backend:3102
peerIlpAddress: test.cloud-nine-wallet-test
liquidityThreshold: 100000
accounts:
Expand Down

0 comments on commit 31f92b9

Please sign in to comment.