-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests skeleton * Fix JSDoc * Update dapi tests * Add tips
- Loading branch information
Showing
27 changed files
with
1,997 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"extends": "airbnb-base", | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"no-plusplus": 0, | ||
"eol-last": [ | ||
"error", | ||
"always" | ||
], | ||
"no-await-in-loop": "off", | ||
"import/no-extraneous-dependencies": "off", | ||
"no-restricted-syntax": [ | ||
"error", | ||
{ | ||
"selector": "LabeledStatement", | ||
"message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand." | ||
}, | ||
{ | ||
"selector": "WithStatement", | ||
"message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize." | ||
} | ||
], | ||
"curly": [ | ||
"error", | ||
"all" | ||
] | ||
}, | ||
"globals": { | ||
"expect": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
/ansible/*.retry | ||
/networks/*.inventory | ||
|
||
# Node.JS | ||
node_modules | ||
|
||
# Vagrant | ||
.vagrant | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ea | ||
|
||
. ./lib/cli/utils.sh | ||
|
||
CMD_USAGE="Usage: ./test [options] <network_name> | ||
Options: | ||
-m=<args> --mocha-args=<args> - Mocha arguments | ||
-t=<types> --types=<types> - Test types: smoke, e2e. You may specify several using comma delimiter | ||
-h --help - Show help" | ||
|
||
for i in "$@" | ||
do | ||
case ${i} in | ||
-m=*|--mocha-args=*) | ||
MOCHA_ARGUMENTS="${i#*=}" | ||
;; | ||
-t=*|--types=*) | ||
TEST_TYPES="${i#*=}" | ||
;; | ||
-h|--help) | ||
echo ${CMD_USAGE} | ||
exit 0 | ||
;; | ||
*) | ||
NETWORK_NAME="${i#*=}" | ||
;; | ||
esac | ||
done | ||
|
||
. ./lib/cli/init.sh | ||
. ./lib/cli/test.sh | ||
|
||
echo "Run test against $NETWORK_NAME network..."; | ||
|
||
run_mocha |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function run_mocha() { | ||
if [ ! -f "$INVENTORY_FILE" ]; then | ||
print_error "Ansible inventory file not found. Please read README.md how to create infrastructure with Terraform" | ||
fi | ||
|
||
if [ ! -f "$ANSIBLE_CONFIG_PATH" ]; then | ||
print_error "Ansible network config '$ANSIBLE_CONFIG_PATH' is not found. Please read README.md how to configure networks" | ||
fi | ||
|
||
# Export ansible inventory file | ||
|
||
ANSIBLE_INVENTORY_EXPORT_PATH="networks/$NETWORK_NAME-inventory.json" | ||
|
||
ANSIBLE_GROUP_VARS_PATH="ansible/group_vars/all" | ||
|
||
ANSIBLE_INVENTORY=$(ansible-inventory --list --export -i "$INVENTORY_FILE") | ||
|
||
# Select tests | ||
|
||
if [ -z ${TEST_TYPES} ]; then | ||
TEST_TYPES="smoke,e2e" | ||
fi | ||
|
||
TEST_TYPES_STRING="" | ||
IFS=',' read -ra TEST_TYPES_ARRAY <<< "$TEST_TYPES" | ||
for TYPE in "${TEST_TYPES_ARRAY[@]}"; do | ||
TEST_TYPES_STRING="$TEST_TYPES_STRING test/$TYPE/**/*.spec.js" | ||
done | ||
|
||
# Run mocha tests | ||
|
||
node_modules/.bin/_mocha ${MOCHA_ARGUMENTS} ${TEST_TYPES_STRING} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { expect, use } = require('chai'); | ||
const dirtyChai = require('dirty-chai'); | ||
const chaiAsPromised = require('chai-as-promised'); | ||
|
||
use(chaiAsPromised); | ||
use(dirtyChai); | ||
|
||
process.env.NODE_ENV = 'test'; | ||
|
||
global.expect = expect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const readYamlFiles = require('./readYamlFiles'); | ||
|
||
let info; | ||
|
||
/** | ||
* Get network information | ||
* | ||
* @return {{ network:string, networkName: string, | ||
* devnetName: string, inventory: object, | ||
* variables: object}} | ||
*/ | ||
module.exports = function getNetworkConfig() { | ||
if (info) { | ||
return info; | ||
} | ||
|
||
const variables = readYamlFiles( | ||
`${__dirname}/../../${process.env.ANSIBLE_GROUP_VARS_PATH}`, | ||
`${__dirname}/../../${process.env.ANSIBLE_CONFIG_PATH}`, | ||
); | ||
|
||
info = { | ||
network: process.env.NETWORK, | ||
networkName: process.env.NETWORK_NAME, | ||
devnetName: process.env.NETWORK_DEVNET_NAME, | ||
inventory: JSON.parse(process.env.ANSIBLE_INVENTORY), | ||
variables, | ||
}; | ||
|
||
return variables; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const fs = require('fs'); | ||
const merge = require('lodash.merge'); | ||
const yaml = require('js-yaml'); | ||
|
||
/** | ||
* Read and merge YAML files | ||
* @param files | ||
*/ | ||
module.exports = function readYamlFiles(...files) { | ||
const objectsArray = files.map((file) => { | ||
const fileString = fs.readFileSync(file, 'utf8'); | ||
return yaml.safeLoad(fileString); | ||
}); | ||
|
||
return merge(...objectsArray); | ||
}; |
Oops, something went wrong.