Skip to content

Commit

Permalink
chore: run test with matrix strategy
Browse files Browse the repository at this point in the history
Signed-off-by: nic-chen <[email protected]>
  • Loading branch information
nic-chen committed Dec 1, 2022
1 parent 712e923 commit 2a0136e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
24 changes: 21 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@ on: [push, pull_request]
jobs:
run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- linux-amd64-unit-4-cpu-race
- linux-386-unit-1-cpu
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.19.3"
# TODO(ahrtr): add test matrix for different platform and ARCH
- run: make test

- env:
TARGET: ${{ matrix.target }}
run: |
case "${TARGET}" in
linux-amd64-unit-4-cpu-race)
GOARCH=amd64 PASSES='unit' RACE='true' CPU='4' ./scripts/test.sh -p=2
;;
linux-386-unit-1-cpu)
GOARCH=386 PASSES='unit' RACE='false' CPU='1' ./scripts/test.sh -p=4
;;
*)
echo "Failed to find target"
exit 1
;;
esac
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
GO_TEST_FLAGS?=

.PHONY: verify
verify: verify-gofmt verify-dep verify-lint verify-mod-tidy verify-genproto
Expand All @@ -24,5 +25,4 @@ verify-genproto:

.PHONY: test
test:
go test ./...

PASSES="unit" ./scripts/test.sh $(GO_TEST_FLAGS)
35 changes: 35 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ set -eo pipefail

source ./scripts/test_lib.sh

# set default GOARCH if not set
if [ -z "$GOARCH" ]; then
GOARCH=$(go env GOARCH);
fi

# determine whether target supports race detection
if [ -z "${RACE}" ] ; then
if [ "$GOARCH" == "amd64" ]; then
RACE="--race"
else
RACE="--race=false"
fi
else
RACE="--race=${RACE:-true}"
fi

# This options make sense for cases where SUT (System Under Test) is compiled by test.
COMMON_TEST_FLAGS=("${RACE}")
if [[ -n "${CPU}" ]]; then
COMMON_TEST_FLAGS+=("--cpu=${CPU}")
fi

######### Code formatting checkers #############################################

# generic_checker [cmd...]
Expand Down Expand Up @@ -97,6 +119,19 @@ function mod_tidy_pass {
mod_tidy_for_module
}

################# REGULAR TESTS ################################################

# run_unit_tests [pkgs] runs unit tests for a current module and givesn set of [pkgs]
function run_unit_tests {
shift 1
# shellcheck disable=SC2086
GOLANG_TEST_SHORT=true go test ./... -short -timeout="${TIMEOUT:-3m}" "${COMMON_TEST_FLAGS[@]}" "${RUN_ARG[@]}" "$@"
}

function unit_pass {
run_unit_tests "$@"
}

########### MAIN ###############################################################

function run_pass {
Expand Down

0 comments on commit 2a0136e

Please sign in to comment.