Compare commits

...

3 Commits

Author SHA1 Message Date
Dan Ribbens
afb31db8bb test: attempt 3 2025-02-28 15:37:33 -05:00
Dan Ribbens
eeed6eacc5 test: attempt 2 2025-02-28 14:58:55 -05:00
Dan Ribbens
109cdb7b0d test: add cosmos db emulator to CI 2025-02-28 14:52:17 -05:00
3 changed files with 41 additions and 16 deletions

View File

@@ -181,6 +181,7 @@ jobs:
- supabase
- sqlite
- sqlite-uuid
- cosmosdb
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
@@ -189,20 +190,26 @@ jobs:
AWS_ACCESS_KEY_ID: localstack
AWS_SECRET_ACCESS_KEY: localstack
AWS_REGION: us-east-1
COSMOSDB_CONNECTION_STRING: ${{ secrets.COSMOSDB_CONNECTION_STRING }}
services:
postgres:
image: ${{ (startsWith(matrix.database, 'postgres') ) && 'postgis/postgis:16-3.4' || '' }}
env:
# must specify password for PG Docker container image, see: https://registry.hub.docker.com/_/postgres?tab=description&page=1&name=10
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
cosmosdb:
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview
ports:
- 8081:8081
env:
PROTOCOL: https
steps:
- uses: actions/checkout@v4
@@ -224,18 +231,6 @@ jobs:
- name: Start LocalStack
run: pnpm docker:start
- name: Install Supabase CLI
uses: supabase/setup-cli@v1
with:
version: latest
if: matrix.database == 'supabase'
- name: Initialize Supabase
run: |
supabase init
supabase start
if: matrix.database == 'supabase'
- name: Configure PostgreSQL
run: |
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" -c "CREATE ROLE runner SUPERUSER LOGIN;"
@@ -253,6 +248,21 @@ jobs:
echo "POSTGRES_URL=postgresql://postgres:postgres@127.0.0.1:54322/postgres" >> $GITHUB_ENV
if: matrix.database == 'supabase'
- name: Set up CosmosDB Emulator (only for CosmosDB tests)
if: matrix.database == 'cosmosdb'
run: |
echo "Waiting for CosmosDB Emulator to be ready..."
until curl -k https://localhost:8081/_explorer/emulator.pem; do sleep 5; done
curl -k https://localhost:8081/_explorer/emulator.pem > cosmos_emulator.cert
sudo cp cosmos_emulator.cert /usr/local/share/ca-certificates/
sudo update-ca-certificates
- name: Run tests
run: npm test
env:
COSMOSDB_CONNECTION_STRING: 'mongodb://localhost:10255/?ssl=true&replicaSet=globaldb&retrywrites=false'
COSMOSDB_CA_CERT: '/usr/local/share/ca-certificates/cosmos_emulator.cert'
- name: Integration Tests
run: pnpm test:int
env:

View File

@@ -48,6 +48,7 @@ export async function buildConfigWithDefaults(
): Promise<SanitizedConfig> {
const config: Config = {
db: databaseAdapter,
indexSortableFields: process.env.PAYLOAD_DATABASE === 'cosmosdb',
editor: lexicalEditor({
features: [
ParagraphFeature(),

View File

@@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export const allDatabaseAdapters = {
export const allDatabaseAdapters: Record<string, string> = {
mongodb: `
import { mongooseAdapter } from '@payloadcms/db-mongodb'
@@ -72,12 +72,26 @@ export const allDatabaseAdapters = {
process.env.POSTGRES_URL || 'postgresql://postgres:postgres@127.0.0.1:54322/postgres',
},
})`,
cosmosdb: `
import { mongooseAdapter } from '@payloadcms/db-mongodb'
export const databaseAdapter = mongooseAdapter({
ensureIndexes: true,
transactionOptions: false,
url: process.env.COSMOSDB_CONNECTION_STRING
options: {
tls: true,
tlsCAFile: process.env.COSMOSDB_CA_CERT || '/usr/local/share/ca-certificates/cosmos_emulator.cert',
useNewUrlParser: true,
useUnifiedTopology: true,
},
})`,
}
/**
* Write to databaseAdapter.ts
*/
export function generateDatabaseAdapter(dbAdapter) {
export function generateDatabaseAdapter(dbAdapter: string) {
const databaseAdapter = allDatabaseAdapters[dbAdapter]
if (!databaseAdapter) {
throw new Error(`Unknown database adapter: ${dbAdapter}`)