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

Add postresql integration tests into CI #1897

Merged
merged 11 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
34 changes: 31 additions & 3 deletions .github/workflows/pr-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
path: |
tests/**/node_modules
website/**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '!**/node_modules/**') }}-modules-root
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '!**/node_modules/**') }}-modules-tests

- name: Cache build
uses: actions/cache@v2
Expand Down Expand Up @@ -90,7 +90,18 @@ jobs:
name: Integration Tests
runs-on: ubuntu-latest
needs: buildAndTest
if: startsWith(github.head_ref, 'feature/') || startsWith(github.head_ref, 'hotfix/') || startsWith(github.head_ref, 'fix/')
services:
postgres:
image: postgres:10
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2

Expand All @@ -112,6 +123,14 @@ jobs:
internal/**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '!**/node_modules/**') }}-modules-packages

- name: Cache tests and website node_modules
uses: actions/cache@v2
with:
path: |
tests/**/node_modules
website/**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '!**/node_modules/**') }}-modules-tests

- name: Cache build
uses: actions/cache@v2
with:
Expand All @@ -129,9 +148,18 @@ jobs:
.packages/**
key: ${{ runner.os }}-${{ github.run_id }}-build

- name: Test:integration
- name: Integration Tests
run: yarn test:integration

- name: PostgreSQL Integration Tests
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DATABASE: postgres
run: yarn test:integration-postgres

e2eTest:
name: E2E Tests
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"test:e2e": "workspaces run-script -i \"examples/shopping-list-tutorial/*\" test:e2e",
"test:integration": "workspaces run-script test:integration",
"tutorial-test:e2e": "workspaces run-script -i \"examples/*\" test:e2e",
"test:integration-postgres": "cd tests && yarn test:postgres --color 2>&1",
"test:integration-postgres-serverless": "cd tests && yarn test:postgres-serverless --color 2>&1",
"test:clean-snapshots": "workspaces all \"yarn test -u --color 2>&1\"",
"test:cra": "node internal/cra-test/bin/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ const create: UnboundResourceMethod = async (pool, options) => {
database: options.database,
} as OmitObject<AdapterOptions, CommonAdapterOptions>)

await admin.inlineLedgerRunQuery(
[
`CREATE SCHEMA ${escapeId(options.databaseName)}`,
try {
await admin.inlineLedgerRunQuery(
[
`CREATE SCHEMA ${escapeId(options.databaseName)}`,

`CREATE TABLE ${escapeId(options.databaseName)}.${escapeId(
`__${options.databaseName}__LEDGER__`
)}(
`CREATE TABLE ${escapeId(options.databaseName)}.${escapeId(
`__${options.databaseName}__LEDGER__`
)}(
"EventSubscriber" VARCHAR(190) NOT NULL,
"IsPaused" BOOLEAN NOT NULL,
"EventTypes" JSONB NOT NULL,
Expand All @@ -39,42 +40,45 @@ const create: UnboundResourceMethod = async (pool, options) => {
PRIMARY KEY("EventSubscriber")
)`,

`CREATE TABLE ${escapeId(options.databaseName)}.${escapeId(
`__${options.databaseName}__TRX__`
)}(
`CREATE TABLE ${escapeId(options.databaseName)}.${escapeId(
`__${options.databaseName}__TRX__`
)}(
"XaKey" VARCHAR(190) NOT NULL,
"XaValue" VARCHAR(190) NOT NULL,
"Timestamp" BIGINT,
PRIMARY KEY("XaKey")
)`,

`GRANT USAGE ON SCHEMA ${escapeId(options.databaseName)} TO ${escapeId(
options.userLogin
)}`,
`GRANT USAGE ON SCHEMA ${escapeId(options.databaseName)} TO ${escapeId(
options.userLogin
)}`,

`GRANT ALL ON SCHEMA ${escapeId(options.databaseName)} TO ${escapeId(
options.userLogin
)}`,
`GRANT ALL ON SCHEMA ${escapeId(options.databaseName)} TO ${escapeId(
options.userLogin
)}`,

`GRANT ALL ON ALL TABLES IN SCHEMA ${escapeId(
options.databaseName
)} TO ${escapeId(options.userLogin)}`,
`GRANT ALL ON ALL TABLES IN SCHEMA ${escapeId(
options.databaseName
)} TO ${escapeId(options.userLogin)}`,

`GRANT ALL ON ALL SEQUENCES IN SCHEMA ${escapeId(
options.databaseName
)} TO ${escapeId(options.userLogin)}`,
`GRANT ALL ON ALL SEQUENCES IN SCHEMA ${escapeId(
options.databaseName
)} TO ${escapeId(options.userLogin)}`,

`GRANT ALL ON ALL FUNCTIONS IN SCHEMA ${escapeId(
options.databaseName
)} TO ${escapeId(options.userLogin)}`,
`GRANT ALL ON ALL FUNCTIONS IN SCHEMA ${escapeId(
options.databaseName
)} TO ${escapeId(options.userLogin)}`,

`ALTER SCHEMA ${escapeId(options.databaseName)} OWNER TO ${escapeId(
options.userLogin
)}`,
].join('; ')
)

await disconnect(admin)
`ALTER SCHEMA ${escapeId(options.databaseName)} OWNER TO ${escapeId(
options.userLogin
)}`,
].join('; ')
)
} catch (error) {
throw error
} finally {
await disconnect(admin)
}
}

export default create
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const destroy: UnboundResourceMethod = async (pool, options) => {
dropSchemaError = error
}

await disconnect(admin)

if (dropSchemaError != null || alterSchemaError != null) {
const error = new Error()
error.message = `${
Expand All @@ -47,8 +49,6 @@ const destroy: UnboundResourceMethod = async (pool, options) => {

throw error
}

await disconnect(admin)
}

export default destroy
4 changes: 3 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
"scripts": {
"test": "echo || exit 0",
"test:integration": "jest --config=./jest.config.js",
"test:postgres": "yarn test:eventstore-postgres && yarn test:read-model-postgres",
"test:postgres-serverless": "yarn test:eventstore-postgres-serverless && yarn test:read-model-postgres-serverless",
"test:read-model": "env TEST_POSTGRES_SERVERLESS=false jest --config=./jest.config.js --testMatch=**/read-model-store-*/*.test.[jt]s",
"test:read-model-mysql": "env TEST_MYSQL=true jest --config=./jest.config.js --testMatch=**/read-model-store-*/*.test.[jt]s",
"test:read-model-postgres": "env TEST_POSTGRES=true jest --config=./jest.config.js --testMatch=**/read-model-store-*/*.test.[jt]s",
"test:read-model-postgres": "env TEST_POSTGRES=true jest --config=./jest.config.js --testMatch=**/read-model-store-*/*.test.[jt]s --runInBand",
"test:read-model-postgres-serverless": "env TEST_POSTGRES_SERVERLESS=true jest --config=./jest.config.js --testMatch=**/read-model-store-*/*.test.[jt]s",
"test:eventstore-order-events": "env TEST_POSTGRES_SERVERLESS=false jest --config=./jest.config.js --testMatch=**/eventstore-order-events/*.test.[jt]s",
"test:eventstore": "jest --config=./jest.config.js --testMatch=**/eventstore-*/*.test.[jt]s",
"test:eventstore-postgres": "env TEST_POSTGRES=true jest --config=./jest.config.js --testMatch=**/eventstore-*/*.test.[jt]s --runInBand",
"test:eventstore-postgres-serverless": "env TEST_POSTGRES_SERVERLESS=true jest --config=./jest.config.js --testMatch=**/eventstore-*/*.test.[jt]s",
"test:import-export": "jest --config=./jest.config.js --testMatch=**/import-export-sample/*.test.ts",
"test:secrets": "jest --config=./jest.config.js --testMatch=**/eventstore-secrets/*.test.ts",
Expand Down