#!/usr/bin/env bash

if [ ! -f /.mongo_run_once_test ]; then

    USER=${MONGODB_USERNAME_TEST:-test}
    PASS=${MONGODB_PASSWORD_TEST:-test16}
    DB=${MONGODB_DBNAME_TEST:-test}
    ROLE=${MONGODB_ROLE:-dbOwner}

    touch /.mongo_run_once_test

    # Create User
    echo "Creating user: \"$USER\"..."
    echo "db.createUser({ user: '$USER', pwd: '$PASS', roles: [ { role: '$ROLE', db: '$DB' } ] });"
    R1=`mongo test --eval "db.dropUser('$USER');"`
    R2=`mongo test --eval "db.createUser({ user: '$USER', pwd: '$PASS', roles: [ { role: '$ROLE', db: '$DB' } ] });"`
    echo $R1 $R2

fi
