#!/bin/sh

if test ! -e scripts/go-test ; then
	echo 'E: Cannot find scripts/go-test. Abort.'
	exit 1
fi

if test ! -d e2e ; then
	echo 'E: Cannot find e2e directory. Abort.'
	exit 1
fi

os=`uname -s`
if [ ! -z "$E2E_PARALLEL" ]; then
    procs=$E2E_PARALLEL
elif [ "$os" = "Linux" ]; then
    procs=`nproc --all`
elif [ "$os" = "Darwin" ]; then
    procs=`sysctl -n hw.ncpu`
else
    procs=`getconf _NPROCESSORS_ONLN`
fi

export sudo_args="env -i PATH=$PATH HOME=$HOME SINGULARITY_E2E_COVERAGE=$SINGULARITY_E2E_COVERAGE"
exec scripts/go-test -sudo -parallel $procs -tags "e2e_test" "$@" ./e2e
