set up postgres CI route

uses env flag TEST_POSTGRES since the sqlite test also runs with env flag CI true
This commit is contained in:
Michael C 2021-06-23 14:48:47 -04:00
parent 746dc4f81d
commit da92f2082d
No known key found for this signature in database
GPG key ID: FFB04FB3B878B7B4
5 changed files with 110 additions and 1 deletions

27
.github/workflows/postgres-ci.yml vendored Normal file
View file

@ -0,0 +1,27 @@
name: Docker Image CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build the docker-compose stack
env:
PG_USER: ci_db_user
PG_PASS: ci_db_pass
run: docker-compose up -d
- name: Sleep
uses: jakejarvis/wait-action@master
with:
time: '10s'
- name: Check running containers
run: docker ps
- uses: actions/setup-node@v1
- run: npm install
- name: Run test suite
env:
TEST_POSTGRES: true
run: npm test

65
ci.json Normal file
View file

@ -0,0 +1,65 @@
{
"port": 8080,
"mockPort": 8081,
"globalSalt": "testSalt",
"adminUserID": "4bdfdc9cddf2c7d07a8a87b57bf6d25389fb75d1399674ee0e0938a6a60f4c3b",
"newLeafURLs": ["placeholder"],
"discordReportChannelWebhookURL": "http://127.0.0.1:8081/ReportChannelWebhook",
"discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/FirstTimeSubmissionsWebhook",
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/CompletelyIncorrectReportWebhook",
"discordNeuralBlockRejectWebhookURL": "http://127.0.0.1:8081/NeuralBlockRejectWebhook",
"neuralBlockURL": "http://127.0.0.1:8081/NeuralBlock",
"behindProxy": true,
"postgres": {
"user": "ci_db_user",
"password": "ci_db_pass",
"host": "localhost",
"port": 5432
},
"createDatabaseIfNotExist": true,
"schemaFolder": "./databases",
"dbSchema": "./databases/_sponsorTimes.db.sql",
"privateDBSchema": "./databases/_private.db.sql",
"mode": "test",
"readOnly": false,
"webhooks": [
{
"url": "http://127.0.0.1:8081/CustomWebhook",
"key": "superSecretKey",
"scopes": [
"vote.up",
"vote.down"
]
}, {
"url": "http://127.0.0.1:8081/FailedWebhook",
"key": "superSecretKey",
"scopes": [
"vote.up",
"vote.down"
]
}, {
"url": "http://127.0.0.1:8099/WrongPort",
"key": "superSecretKey",
"scopes": [
"vote.up",
"vote.down"
]
}
],
"categoryList": ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "highlight"],
"maxNumberOfActiveWarnings": 3,
"hoursAfterWarningExpires": 24,
"rateLimit": {
"vote": {
"windowMs": 900000,
"max": 20,
"message": "Too many votes, please try again later",
"statusCode": 429
},
"view": {
"windowMs": 900000,
"max": 20,
"statusCode": 200
}
}
}

9
docker-compose.yml Normal file
View file

@ -0,0 +1,9 @@
version: '3'
services:
postgres:
image: postgres:alpine
environment:
- POSTGRES_USER=${PG_USER}
- POSTGRES_PASSWORD=${PG_PASS}
ports:
- 5432:5432

View file

@ -2,7 +2,9 @@ import fs from 'fs';
import {SBSConfig} from "./types/config.model";
const isTestMode = process.env.npm_lifecycle_script === 'ts-node test/test.ts';
const configFile = isTestMode ? 'test.json' : 'config.json';
const configFile = process.env.TEST_POSTGRES ? 'ci.json'
: isTestMode ? 'test.json'
: 'config.json';
export const config: SBSConfig = JSON.parse(fs.readFileSync(configFile).toString('utf8'));
addDefaults(config, {

View file

@ -23,6 +23,12 @@ async function init() {
await initDb();
const dbMode = config.mysql ? 'mysql'
: config.postgres ? 'postgres'
: 'sqlite'
// print database mode
console.log('Database Mode: ' + dbMode)
// Instantiate a Mocha instance.
const mocha = new Mocha();