From 32ef68d9addd29a83546c87ba79a2c8d7c391f91 Mon Sep 17 00:00:00 2001 From: Robert Bradley Date: Tue, 7 Jan 2025 10:57:40 +0000 Subject: [PATCH] Adding nightly testing --- .github/workflows/tests.yml | 3 ++ .../scripts/create-local-table.js | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/integration-tests/scripts/create-local-table.js diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bd90300..c73d7f2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,6 +35,9 @@ jobs: - name: Start DynamoDB Local run: docker run -d -p 8000:8000 amazon/dynamodb-local + - name: Create Rooms table for testing + run: node scripts/create-local-table.js + - name: Set up env vars run: | echo "AWS_ACCESS_KEY_ID=FAKE_KEY" >> $GITHUB_ENV diff --git a/test/integration-tests/scripts/create-local-table.js b/test/integration-tests/scripts/create-local-table.js new file mode 100644 index 0000000..b759261 --- /dev/null +++ b/test/integration-tests/scripts/create-local-table.js @@ -0,0 +1,42 @@ +// scripts/create-local-table.js +// This is used to create a test table in our local copy of DynamoDB when the tests run +// This is not used if deploying infrastructure to AWS +const { DynamoDBClient, CreateTableCommand } = require('@aws-sdk/client-dynamodb'); + +(async () => { + try { + const client = new DynamoDBClient({ + region: process.env.AWS_REGION || "us-west-2", + endpoint: process.env.DYNAMODB_ENDPOINT || "http://localhost:8000", + credentials: { + accessKeyId: process.env.AWS_ACCESS_KEY_ID || "FAKE_KEY", + secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || "FAKE_SECRET", + }, + }); + + const tableName = process.env.DYNAMODB_TABLE_NAME || "RoomsTest"; + + const command = new CreateTableCommand({ + TableName: tableName, + AttributeDefinitions: [ + { AttributeName: 'id', AttributeType: 'N' }, + ], + KeySchema: [ + { AttributeName: 'id', KeyType: 'HASH' }, + ], + ProvisionedThroughput: { + ReadCapacityUnits: 5, + WriteCapacityUnits: 5, + }, + SSESpecification: { + Enabled: true, // server-side encryption + }, + }); + + const result = await client.send(command); + console.log(`Created table '${tableName}' locally.`, result.TableDescription?.TableStatus); + } catch (err) { + console.error('Error creating table locally:', err); + process.exit(1); + } +})();