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

chore: adds api functional testing to CI #716

Merged
merged 1 commit into from
Jan 24, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/validate-n-build-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
filters: |
api:
- 'apps/api/**'
- 'packages/database/**'
- name: Setup Node.js
if: steps.filter.outputs.api == 'true'
Expand Down Expand Up @@ -54,6 +53,15 @@ jobs:
if: steps.filter.outputs.api == 'true'
run: npm run test:unit --workspace=apps/api

- name: Run functional tests
if: steps.filter.outputs.api == 'true'
env:
POSTGRES_SKIP_IMPORT: true
run: |
npm run dc:up:db
npm run test:functional --workspace=apps/api
npm run dc:down
- name: Build the Docker image for API
if: steps.filter.outputs.api == 'true'
run: packages/docker/script/dc.sh build api
4 changes: 4 additions & 0 deletions apps/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ src/
myComponent.spec.ts
```

#### Functional Tests Wallet

Functional tests rely on a sandbox akash wallet: *akash1fq8fhssjs0w8x9ysggrm4r8x26522elefm737l*. If your workflow starts failing, make sure the wallet is funded and has enough tokens to cover the costs. It can be refilled via https://faucet.sandbox-01.aksh.pw

## Changes from **beta** to **v1** (February 2024)

### Api Versioning
Expand Down
6 changes: 3 additions & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"start": "webpack --config webpack.dev.js --watch",
"test": "jest --selectProjects unit functional",
"test:cov": "jest --selectProjects unit functional --coverage",
"test:functional": "jest --selectProjects functional",
"test:functional:cov": "jest --selectProjects functional --coverage",
"test:functional:watch": "jest --selectProjects functional --watch",
"test:functional": "jest --selectProjects functional --runInBand",
"test:functional:cov": "npm run test:functional -- --coverage",
"test:functional:watch": "npm run test:functional -- --watch",
"test:unit": "jest --selectProjects unit",
"test:unit:cov": "jest --selectProjects unit --coverage",
"test:unit:watch": "jest --selectProjects unit --watch",
Expand Down
11 changes: 6 additions & 5 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions packages/docker/.env.sandbox.docker-compose-dev
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ ActiveChain=akashSandbox
# DB
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DBS: console-users,console-akash-sandbox
POSTGRES_SKIP_IMPORT: ${POSTGRES_SKIP_IMPORT:-false}
POSTGRES_DBS_FOR_IMPORT: console-akash-sandbox
POSTGRES_USERS_DB: console-users
55 changes: 32 additions & 23 deletions packages/docker/script/prepare-and-seed-postgres.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

echo "DB_SEEDER: Importing databases from cloud storage..."
echo "DB_SEEDER: Setting up databases..."

BASE_URL="https://storage.googleapis.com/console-postgresql-backups"

Expand All @@ -14,39 +14,48 @@ if [ -z "${POSTGRES_PASSWORD:-}" ]; then
exit 1
fi

if [ -z "${POSTGRES_DBS_FOR_IMPORT:-}" ]; then
echo "DB_SEEDER: POSTGRES_DBS_FOR_IMPORT is not set. Skipping seeding."
exit 1
fi

if [ -z "${POSTGRES_USERS_DB:-}" ]; then
echo "DB_SEEDER: POSTGRES_USERS_DB is not set. Skipping seeding."
if [ -z "${POSTGRES_DBS:-}" ]; then
echo "DB_SEEDER: POSTGRES_DBS is not set. Skipping seeding."
exit 1
fi

export PGUSER=$POSTGRES_USER
export PGPASSWORD=$POSTGRES_PASSWORD

psql -c "CREATE DATABASE \"$POSTGRES_USERS_DB\""

# Step 1: Create all databases from POSTGRES_DBS
old_IFS=$IFS
IFS=','

for dbname in $POSTGRES_DBS_FOR_IMPORT; do
url="${BASE_URL}/${dbname}.sql.gz"
echo "DB_SEEDER: Importing \"$dbname\""

if ! psql -c "CREATE DATABASE \"$dbname\""; then
echo "DB_SEEDER: Failed to create database \"$dbname\""
exit 1
fi

if ! curl -s -S -L "$url" | gunzip | psql "$dbname"; then
echo "DB_SEEDER: Failed to download and import \"$url\""
exit 1
for dbname in $POSTGRES_DBS; do
echo "DB_SEEDER: Creating database \"$dbname\""
if ! psql -c "CREATE DATABASE \"$dbname\"" 2>/dev/null; then
echo "DB_SEEDER: Database \"$dbname\" already exists or failed to create"
fi
done

# Step 2: Import data for specified databases if POSTGRES_SKIP_IMPORT is not "true"
if [ "${POSTGRES_SKIP_IMPORT:-false}" != "true" ] && [ -n "${POSTGRES_DBS_FOR_IMPORT:-}" ]; then
for dbname in $POSTGRES_DBS_FOR_IMPORT; do
url="${BASE_URL}/${dbname}.sql.gz"
echo "DB_SEEDER: Importing \"$dbname\""

# Create database if it doesn't exist
if ! psql -lqt | cut -d \| -f 1 | grep -qw "$dbname"; then
echo "DB_SEEDER: Database \"$dbname\" doesn't exist, creating..."
if ! psql -c "CREATE DATABASE \"$dbname\""; then
echo "DB_SEEDER: Failed to create database \"$dbname\""
exit 1
fi
fi

if ! curl -s -S -L "$url" | gunzip | psql "$dbname"; then
echo "DB_SEEDER: Failed to download and import \"$url\""
exit 1
fi
done
else
echo "DB_SEEDER: Skipping import step"
fi

IFS=$old_IFS

touch /var/lib/postgresql/data/init-complete
Expand Down
Loading