Skip to content

Commit 5d4e3dc

Browse files
committed
add flag for go build flags
1 parent 764385e commit 5d4e3dc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

go-test-runner

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ main () {
1313
MIN_COVERAGE_PERCENTAGE_NUM=0.0;
1414
VERBOSE_FLAG='false';
1515
FILE_PATH='.';
16+
BUILD_FLAGS='';
1617

1718
# Parse flags and assign to global variables.
18-
while getopts ':n:f:v' flag; do
19+
while getopts ':n:f:t:v' flag; do
1920
case "${flag}" in
2021
n) MIN_COVERAGE_PERCENTAGE_NUM="${OPTARG}" ;;
21-
v) VERBOSE_FLAG="true" ;;
2222
f) FILE_PATH="${OPTARG}" ;;
23+
t) BUILD_FLAGS="${OPTARG}" ;;
24+
v) VERBOSE_FLAG="true" ;;
2325
*) error "Unexpected option ${flag}" ;;
2426
esac
2527
done
@@ -84,15 +86,15 @@ generate_test_coverage () {
8486
# If the pkg filepath contains 'vendor' we do not want to test it.
8587
if [[ ${pkg} != *"vendor"* && ${pkg} != *"mock"* ]]; then
8688
# Run the go cover and output results to 'coverage.out'.
87-
OUTPUT=$(go test -v -cover -coverprofile=coverage.out -covermode=count $pkg);
89+
OUTPUT=$(go test -v --tags "$BUILD_FLAGS" -cover -coverprofile=coverage.out -covermode=count $pkg);
8890
if [[ $OUTPUT == *"[no test files]"* ]]; then
8991
print_handler "no tests founds for "$pkg
9092
BASE_FOLDER_NAME=$(basename $pkg);
9193
MOCK_FILE_PATH="${PWD}/${pkg}/${BASE_FOLDER_NAME}_test.go";
9294
TEMP_TEST_FILE_PATHS_ARR+=($MOCK_FILE_PATH)
9395
touch $MOCK_FILE_PATH;
9496
echo "package ${BASE_FOLDER_NAME}" > $MOCK_FILE_PATH;
95-
k=$(go test -v -cover -coverprofile=coverage.out -covermode=count $pkg);
97+
k=$(go test -v --tags "$BUILD_FLAGS" -cover -coverprofile=coverage.out -covermode=count $pkg);
9698
fi
9799

98100
# Take the results of coverage.out and append them to coverage-all.txt.

0 commit comments

Comments
 (0)