opt-cc/api/apib/dredd/populate-data.sh

40 lines
1.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2018-04-02 00:32:45 +02:00
########### IMPORT EXPORT/SCRIPT FOR DREDD TEST DATA ##############
###-------------------------------------------------------------###
###------------------- HOW TO USE THIS FILE --------------------###
###-------------------------------------------------------------###
### 1. start express server with `npm run start-test` ###
### 2. import data by executing script: `./populate-data.sh` ###
### 3. change data in app as you need for tests ###
### 4. export data state with: `./populate-data.sh -m save` ###
###################################################################
# execute script in its location folder
cd $(dirname $0)
2018-04-02 00:32:45 +02:00
while getopts m:p:d: option
do
case "${option}"
in
m) MODE=${OPTARG};;
p) PORT=${OPTARG};;
d) DATABASE=${OPTARG};;
esac
done
# array of available collection names
2018-03-30 12:53:49 +02:00
col=(app_user awarding campaign decoration logBudget logFlag logKill logPoints logRespawn logRevive logTransport logVehicle player promotion rank squad user war )
for i in "${col[@]}"
do
# provide date for restore process, if data import is needed
2018-04-02 00:32:45 +02:00
if [ "$MODE" == "save" ]
then
echo -e "$(date "+%Y-%m-%dT%T.%3N%z")\tTable: ${i}"
2018-04-02 00:32:45 +02:00
mongoexport --db ${DATABASE} --port ${PORT} --collection $i --out data/${i}.json;
else
2018-04-02 00:32:45 +02:00
mongoimport --db ${DATABASE} --port ${PORT} --collection $i --drop --file data/${i}.json
fi
done