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

Setup and README for local testing #403

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ disabled.

## Development Setup with docker-compose

## Development Setup

### Prerequisites

1. Mac or Linux computer using zsh or bash.
Expand Down Expand Up @@ -52,7 +50,7 @@ api-server locally via your IDE or command line.
behavior is to initialize the database and disable outbound
email queueing.
```
./start-api-server.sh [-init-db-only | -no-db | -enable-mailout ]
./start-api-server.sh [-init-db-only | -no-db | -enable-mailout | -mock-mode ]
```

### Method 2 - launch from IDE
Expand All @@ -72,3 +70,24 @@ Develop to your heart's content!!!! We _love_ pull-requests.
## Run everything in docker

Not working right now :(. Check back later.

## Running Tests

As usual, make sure you are authenticated with vault.

Start the api server - use `-mock-mode` flag if needed
```bash
./start-api-server.sh [-init-db-only | -no-db | -enable-mailout | -mock-mode ]
```

In a separate terminal, source testMode.sh (this will also set CS_API_MOCK_MODE=1)

```bash
. ./testMode.sh
```

then run the tests
```bash
cd api_server
npm run test
```
2 changes: 1 addition & 1 deletion api_server/bin/cs_dev_secrets.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { readVaultDevSecrets } = require('../../shared/server_utils/dev_secrets')
async function main() {
const env = await readVaultDevSecrets();
for (const key in env) {
console.log(`export ${key}="${shellescape([env[key]])}"`);
console.log(`export ${key}=${shellescape([env[key]])}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion api_server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"scripts": {
"veryclean": "git clean -fXd",
"test": "mocha --exit",
"test": "mocha --exit --dev_secrets",
"test:ci": "npm run test -- --reporter mocha-teamcity-reporter",
"clean": "git clean -fXd -e !node_modules -e !node_modules/**/*",
"eslint": "eslint .",
Expand Down
23 changes: 23 additions & 0 deletions api_server/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

'use strict';

// make eslint happy
/* globals before */

before(function (done) {
if (process.argv.find((_) => _ === '--dev_secrets') !== undefined) {
this.timeout(7000);
const devSecrets = require('@datanerd/codestream-utils');
devSecrets
.readVaultSecrets()
.then((secretsEnv) => {
console.log('Merging secrets...');
Object.assign(process.env, secretsEnv);
done();
})
.catch((e) => {
console.error('Error reading secrets', e.message);
done(e);
});
} else {
done();
}
});

require('./lib/test.js');
require('../shared/server_utils/test.js');
require('../shared/codestream_configs/test.js');
Expand Down
4 changes: 4 additions & 0 deletions start-api-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ CSSVC_CFG_FILE=$CSSVC_CFG_FILE
CSSVC_ENV=$CSSVC_ENV
"

echo "$*" | grep -q '\-mock-mode' && {
export CS_API_MOCK_MODE=1
}

echo "$*" | grep -q '\-no-db' || {
echo "======= Initializing database ======="
init_database
Expand Down
16 changes: 16 additions & 0 deletions testMode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

function dev_settings {
for configVar in `cat $SCRIPT_DIR/api_server/config/local.json|grep '"'|cut -f2 -d\"`; do
value=$(grep "\"$configVar\":" $SCRIPT_DIR/api_server/config/local.json|grep '"'|cut -f4 -d\")
echo "export $configVar='$value'"
done
}

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export CSSVC_BACKEND_ROOT=$SCRIPT_DIR
export NODE_PATH="$CSSVC_BACKEND_ROOT/api_server/node_modules:$CSSVC_BACKEND_ROOT/broadcaster/node_modules"
eval `dev_settings`
export CS_API_MOCK_MODE='1'
export CSSVC_ENV=local
export CSSVC_CFG_FILE="$CSSVC_BACKEND_ROOT/codestream-docker.json"