#!/usr/bin/env bash
# Run the project's test suite(s).
#
# Copyright (c) 2019 Cisco and/or its affiliates.
# License: MIT


# Run all tests by default
default=true
module=('cli')

# Process Script Arguments
for i in ${@}; do
    case ${i} in
        lint)
        lint=true
        default=
        ;;

        tests)
        tests=true
        default=
        ;;

        ratelimiting)
        ratelimiting=true
        default=
        ;;

        *)
        module+=($i)
        default=
        ;;
    esac
done


set -e
cd "$(dirname "$0")/.."


# Lint the source code
if [ ${default} ] || [ ${lint} ]; then
    echo "==> Linting the source code"
    flake8
    flake8 --config=.test.flake8 tests/
fi

# Run the rate-limit tests
if [ ${ratelimiting} ]; then
    echo "==> Running the rate-limit tests"
    pytest -s -m "ratelimit"
fi

# Run only one module test
if [ ${#module[@]} -gt 1 ]; then
    temp=${module[@]}
    # Join array elements with ' or '
    modules=${temp// / or }
    echo "==> Running the "${modules}" tests"
    pytest -s -m "${modules}"
    exit 0
fi

# Run the test suite
if [ ${default} ] || [ ${tests} ]; then
    echo "==> Running the test suite"
    pytest -s -m "not ratelimit"
fi

