#!/usr/bin/env bash

set -e

PROFILE=$1
PYTHON_EXE=${PYTHON_EXE:-python3.6}
PIP_VERSION=${PIP_VERSION:-latest}

if [ "$PROFILE" == "conflicting" ]; then
    PIP_VERSION=20.2.3
fi

cd profiles/$PROFILE

echo "Profile dir: $(pwd)"

env_dir=".env_$(basename $PYTHON_EXE)_pip-${PIP_VERSION}"

echo "Profile env: $env_dir"

if [ ! -d $env_dir ]; then
    virtualenv -p $PYTHON_EXE $env_dir
fi

pip=$env_dir/bin/pip

if [ "$PIP_VERSION" == "latest" ]; then
    $pip install -U pip
else
    $pip install pip==$PIP_VERSION
fi

# Install requirements
$pip install -r requirements.txt

# Install pipdeptree
$pip install -e ../../../

pip_deptree=$env_dir/bin/pipdeptree

export TEST_PROFILE_DIR="profiles/$PROFILE"
export PIPDEPTREE_EXE=$TEST_PROFILE_DIR/$pip_deptree

cd -

pytest -v e2e_tests.py


