Skip to content

Commit

Permalink
{AKS} Update unit test pipeline (#4274)
Browse files Browse the repository at this point in the history
* update unit test sh

* fix exit

* fix json report & filter

* fix report name

* fix result

* remove ignore error
  • Loading branch information
FumingZhang authored Dec 30, 2021
1 parent e2292dc commit c89ae41
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 70 deletions.
55 changes: 0 additions & 55 deletions src/aks-preview/azcli_aks_live_test/scripts/test_cli_unit.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,38 @@ set -o pipefail
set -o xtrace

# check var
# take the first arg as test mode
mode=${1:-"cli"}
[[ -z "${WIKI_LINK}" ]] && (echo "WIKI_LINK is empty"; exit 1)
[[ -z "${ACS_BASE_DIR}" ]] && (echo "ACS_BASE_DIR is empty"; exit 1)
[[ -z "${AKS_PREVIEW_BASE_DIR}" ]] && (echo "AKS_PREVIEW_BASE_DIR is empty"; exit 1)
[[ -z "${IGNORE_EXIT_CODE}" ]] && (echo "IGNORE_EXIT_CODE is empty")
[[ -z "${EXT_COVERAGE_CONFIG}" ]] && (echo "CLI_COVERAGE_CONFIG is empty")
[[ -z "${CLI_COVERAGE_CONFIG}" ]] && (echo "CLI_COVERAGE_CONFIG is empty")
[[ -z "${EXT_COVERAGE_CONFIG}" ]] && (echo "EXT_COVERAGE_CONFIG is empty")

# activate virtualenv
source azEnv/bin/activate

# setup aks-preview
./scripts/setup_venv.sh setup-akspreview
# config aks-preview
source ./scripts/setup_venv.sh
removeAKSPreview
if [[ ${mode} == "ext" ]]; then
setupAKSPreview
igniteAKSPreview
fi

# check mode
if [[ ${mode} == "cli" ]]; then
UT_BASE_DIR=${ACS_BASE_DIR}
elif [[ ${mode} == "ext" ]]; then
UT_BASE_DIR=${AKS_PREVIEW_BASE_DIR}
else
echo "Unsupported coverage mode, please choose \"cli\" or \"ext\""
exit 1
fi

# unit test & coverage report
pushd ${AKS_PREVIEW_BASE_DIR}
pushd ${UT_BASE_DIR}

# clean existing coverage report
(coverage combine || true) && (coverage erase || true)
Expand All @@ -31,20 +50,23 @@ coverage run --source=. --omit=*/vendored_sdks/*,*/tests/* -m pytest tests/lates
# generate coverage report
coverage combine || true
coverage report -m
coverage json -o coverage_azext_aks_preview.json
coverage json -o coverage.json
popd

# copy coverage report
mkdir -p reports/ && cp ${AKS_PREVIEW_BASE_DIR}/coverage_azext_aks_preview.json reports/
mkdir -p reports/ && cp ${UT_BASE_DIR}/coverage.json reports/

# prepare running options
# unit test result
options="--unit-test-result ${test_result} --coverage-report ${AKS_PREVIEW_BASE_DIR}/coverage_azext_aks_preview.json"
options="--unit-test-result ${test_result} --coverage-report ${UT_BASE_DIR}/coverage.json"
# ignore exit code
if [[ -n ${IGNORE_EXIT_CODE} ]]; then
options+=" --ignore-exit-code"
fi
if [[ -n ${EXT_COVERAGE_CONFIG} ]]; then
if [[ ${mode} == "cli" && -n ${CLI_COVERAGE_CONFIG} ]]; then
options+=" --coverage-config ./configs/${CLI_COVERAGE_CONFIG}"
fi
if [[ ${mode} == "ext" && -n ${EXT_COVERAGE_CONFIG} ]]; then
options+=" --coverage-config ./configs/${EXT_COVERAGE_CONFIG}"
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ jobs:
condition: succeeded()
displayName: "Set up Virtual Environment"
- bash: |
docker exec $(ContainerName) /opt/scripts/test_cli_unit.sh
condition: and(succeeded(), in(variables['COVERAGE'], 'cli', 'all'))
displayName: Perform Unit Test for CLI
- bash: |
docker exec $(ContainerName) /opt/scripts/test_ext_unit.sh
condition: and(succeededOrFailed(), in(variables['COVERAGE'], 'ext', 'all'))
displayName: Perform Unit Test for EXT
docker exec $(ContainerName) /opt/scripts/test_unit.sh $(COVERAGE)
condition: succeeded()
displayName: Perform Unit Test
- task: CopyFiles@2
inputs:
contents: 'reports/**'
Expand Down

0 comments on commit c89ae41

Please sign in to comment.