Skip to content

Commit

Permalink
Refactor and add new feature to improve automatic tests of the QS
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-romero committed Jun 22, 2023
1 parent bcc46f7 commit 633bfd8
Show file tree
Hide file tree
Showing 11 changed files with 443 additions and 228 deletions.
4 changes: 3 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ QS := ods-quickstarters/...

### By default we do not parallelize tests
PARALLEL := 1
PROJECT := unitt

## Full test of existing ODS core installation. Caution: Creates UNITT project and ODSVERIFY project.
test: smoketest verify test-create-projects
Expand All @@ -35,12 +36,13 @@ test-create-projects:

## Run quickstarter tests within existing ODS installation. Depends on UNITT project.
test-quickstarter:
@(./quickstarter-test.sh $(QS) $(PARALLEL))
@(./quickstarter-test.sh $(PROJECT) $(QS) $(PARALLEL))
.PHONY: test-quickstarter

## Install tools required for tests.
prep-tools:
which go-junit-report || go get github.com/jstemmer/go-junit-report
which golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.50.0
.PHONY: prep-tools

## Lint
Expand Down
115 changes: 70 additions & 45 deletions tests/quickstarter-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,83 @@ THIS_SCRIPT="$(basename $0)"

# By default we run all quickstarter tests, otherwise just the quickstarter
# passed as the first argument to this script.
QUICKSTARTER=${1-"ods-quickstarters/..."}
PARALLEL=${2-"1"}
BITBUCKET_TEST_PROJECT="unitt"
QUICKSTARTER="ods-quickstarters/..."
PARALLEL="1"

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ODS_CORE_DIR=${SCRIPT_DIR%/*}

if ! oc whoami &> /dev/null; then
echo "${THIS_SCRIPT}: You need to login to OpenShift to run the tests"
echo "${THIS_SCRIPT}: Returning with exit code 1"
exit 1
fi
function check_already_logged_in_openshift(){
if ! oc whoami &> /dev/null; then
echo "${THIS_SCRIPT}: You need to login to OpenShift to run the tests"
echo "${THIS_SCRIPT}: Returning with exit code 1"
exit 1
fi
}

if [ -f test-quickstarter-results.txt ]; then
rm test-quickstarter-results.txt
fi
function cleanup_workspace(){
if [ -f test-quickstarter-results.txt ]; then
rm test-quickstarter-results.txt
fi
}

BITBUCKET_TEST_PROJECT="unitt"
echo "Setup Bitbucket test project ${BITBUCKET_TEST_PROJECT} ..."
BITBUCKET_URL=$(${ODS_CORE_DIR}/scripts/get-config-param.sh BITBUCKET_URL)
CD_USER_ID=$(${ODS_CORE_DIR}/scripts/get-config-param.sh CD_USER_ID)
CD_USER_PWD_B64=$(${ODS_CORE_DIR}/scripts/get-config-param.sh CD_USER_PWD_B64)
./scripts/setup-bitbucket-test-project.sh \
--bitbucket=${BITBUCKET_URL} \
--user=${CD_USER_ID} \
--password=$(base64 -d - <<< ${CD_USER_PWD_B64}) \
--project=${BITBUCKET_TEST_PROJECT}

echo " "
echo "${THIS_SCRIPT}: Cleaning a little bit the host machine to not suffer from limitated resources... "
echo " "
if [ -f ./scripts/free-unused-resources.sh ]; then
chmod +x ./scripts/free-unused-resources.sh
./scripts/free-unused-resources.sh || true
else
echo "Not found script ./scripts/free-unused-resources.sh "
fi
function run_test(){
echo " "
echo "${THIS_SCRIPT}: Running tests (${QUICKSTARTER}). Output will take a while to arrive ..."
echo " "


# Should fix error " panic: test timed out after "
echo "${THIS_SCRIPT}: go test -v -count=1 -timeout 30h -parallel ${PARALLEL} github.com/opendevstack/ods-core/tests/quickstarter -args ${QUICKSTARTER}"
go test -v -count=1 -timeout 30h -parallel ${PARALLEL} github.com/opendevstack/ods-core/tests/quickstarter -args ${QUICKSTARTER} ${BITBUCKET_TEST_PROJECT} | tee test-quickstarter-results.txt 2>&1

exitcode="${PIPESTATUS[0]}"

if [ -f test-quickstarter-results.txt ]; then
go-junit-report < test-quickstarter-results.txt > test-quickstarter-report.xml
fi

echo " "
echo " "
echo "${THIS_SCRIPT}: Returning with exit code ${exitcode}"
echo " "
echo " "
exit $exitcode
}

echo " "
echo "${THIS_SCRIPT}: Running tests (${QUICKSTARTER}). Output will take a while to arrive ..."
echo " "

# Should fix error " panic: test timed out after "
echo "${THIS_SCRIPT}: go test -v -count=1 -timeout 30h -parallel ${PARALLEL} github.com/opendevstack/ods-core/tests/quickstarter -args ${QUICKSTARTER}"
go test -v -count=1 -timeout 30h -parallel ${PARALLEL} github.com/opendevstack/ods-core/tests/quickstarter -args ${QUICKSTARTER} | tee test-quickstarter-results.txt 2>&1
exitcode="${PIPESTATUS[0]}"
if [ -f test-quickstarter-results.txt ]; then
go-junit-report < test-quickstarter-results.txt > test-quickstarter-report.xml
function usage {
printf "Run quickstarters tests.\n\n"
printf "\t-h |--help\t\tPrint usage\n"
printf "\t-p |--project\t\tBitbucket project (* mandatory)\n"
printf "\t-pa|--parallel\t\tNumber of test executed in parallel\n"
printf "\t-q |--quickstarter\tQuickStarter to test or Quickstarter folder (default:ods-quickstarters/...)\n"
}

while [[ "$#" -gt 0 ]]; do
case $1 in

-h|--help) usage; exit 0;;

-pa|--parallel) PARALLEL="$2"; shift;;
-pa=*|--parallel=*) PARALLEL="${1#*=}";;

-q|--quickstarter) QUICKSTARTER="$2"; shift;;
-q=*|--quickstarter=*) QUICKSTARTER="${1#*=}";;

-p|--project) BITBUCKET_TEST_PROJECT="$2"; shift;;
-p=*|--project=*) BITBUCKET_TEST_PROJECT="${1#*=}";;

*) echo_error "Unknown parameter passed: $1"; exit 1;;
esac; shift; done

if [ -z "${BITBUCKET_TEST_PROJECT}" ]; then
echo "--project is mandatory"
usage
exit 1
fi

echo " "
echo " "
echo "${THIS_SCRIPT}: Returning with exit code ${exitcode}"
echo " "
echo " "
exit $exitcode
check_already_logged_in_openshift
cleanup_workspace
run_test
Loading

0 comments on commit 633bfd8

Please sign in to comment.