Skip to content

Commit

Permalink
enhance: [Cherry-pick] Use gotestsum to run go unit test (#31622) (#3…
Browse files Browse the repository at this point in the history
…1654)

Cherry-pick from master
pr: #31622
See also #31490

---------

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Mar 28, 2024
1 parent 97c28ed commit c80b440
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
run: |
chmod +x build/builder.sh
chmod +x scripts/run_go_codecov.sh
./build/builder.sh /bin/bash -c ./scripts/run_go_codecov.sh
./build/builder.sh /bin/bash -c "make codecov-go-without-build"
- name: Archive result
uses: actions/upload-artifact@v4
with:
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ INTERATION_PATH = $(PWD)/tests/integration
integration-test: getdeps
@echo "Building integration tests ..."
@(env bash $(PWD)/scripts/run_intergration_test.sh "$(INSTALL_PATH)/gotestsum --")
#@source $(PWD)/scripts/setenv.sh && \
mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && \
GO111MODULE=on $(GO) build -ldflags="-r $${RPATH} -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
-tags dynamic -o $(INSTALL_PATH)/integration-test $(INTERATION_PATH)/ #1>/dev/null

BUILD_TAGS = $(shell git describe --tags --always --dirty="-dev")
BUILD_TAGS_GPU = ${BUILD_TAGS}-gpu
Expand Down Expand Up @@ -330,6 +326,11 @@ codecov-go: build-cpp-with-coverage
@echo "Running go coverage..."
@(env bash $(PWD)/scripts/run_go_codecov.sh)

# Run codecov-go without build core again, used in github action
codecov-go-without-build: getdeps
@echo "Running go coverage..."
@(env bash $(PWD)/scripts/run_go_codecov.sh "$(INSTALL_PATH)/gotestsum --")

# Run codecov-cpp
codecov-cpp: build-cpp-with-coverage
@echo "Running cpp coverage..."
Expand Down
9 changes: 7 additions & 2 deletions scripts/run_go_codecov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ echo "mode: atomic" > ${FILE_COVERAGE_INFO}
# run unittest
echo "Running unittest under ./internal & ./pkg"

TEST_CMD=$@
if [ -z "$TEST_CMD" ]; then
TEST_CMD="go test"
fi

# starting the timer
beginTime=`date +%s`
for d in $(go list ./internal/... | grep -v -e vendor -e kafka -e planparserv2/generated -e mocks); do
go test -race -tags dynamic -v -coverpkg=./... -coverprofile=profile.out -covermode=atomic "$d"
$TEST_CMD -race -tags dynamic -v -coverpkg=./... -coverprofile=profile.out -covermode=atomic "$d"
if [ -f profile.out ]; then
grep -v kafka profile.out | grep -v planparserv2/generated | grep -v mocks | sed '1d' >> ${FILE_COVERAGE_INFO}
rm profile.out
fi
done
pushd pkg
for d in $(go list ./... | grep -v -e vendor -e kafka -e planparserv2/generated -e mocks); do
go test -race -tags dynamic -v -coverpkg=./... -coverprofile=profile.out -covermode=atomic "$d"
$TEST_CMD -race -tags dynamic -v -coverpkg=./... -coverprofile=profile.out -covermode=atomic "$d"
if [ -f profile.out ]; then
grep -v kafka profile.out | grep -v planparserv2/generated | grep -v mocks | sed '1d' >> ../${FILE_COVERAGE_INFO}
rm profile.out
Expand Down

0 comments on commit c80b440

Please sign in to comment.