gpt4 book ai didi

go - gocov不会将完整的测试覆盖率结果上传到codeclimate中

转载 作者:行者123 更新时间:2023-12-01 22:21:03 25 4
gpt4 key购买 nike

基于StackOverflow上的question,我将测试覆盖率添加到了Gitlab CI / CD YAML文件中,并且我希望结果可以上传到代码环境中。

- go get github.com/axw/gocov/gocov
- export CC_TEST_REPORTER_ID=My_REPO_ID
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
- gocov test -v ./... -coverprofile=out
- ./cc-test-reporter format-coverage --input-type gocov out
- ./cc-test-reporter upload-coverage
该脚本在我所有的程序包中都成功运行了测试,并且CI / CD的输出显示运行了不同程序包中的所有测试,但是将报告上载到codeclimate中仅显示只有一个文件具有test-coverage,这是最后一个测试程序包,而不是全部显示。
code-climate result report page

最佳答案

我在同一个stackoverflow链接中将解决方案与另一个答案混合在一起,最后创建了一个bash文件,并从我的yaml文件中像这样运行它,因此报告输出包含所有程序包报告,这是我的脚本:

go get github.com/axw/gocov/gocov
export CC_TEST_REPORTER_ID=My_ID
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build

for pkg in $(go list ./... | grep -v vendor); do
go test -coverprofile=$(echo $pkg | tr / -).cover $pkg
done
echo "mode: set" > c.out
grep -h -v "^mode:" ./*.cover >> c.out
rm -f *.cover

./cc-test-reporter after-build

关于go - gocov不会将完整的测试覆盖率结果上传到codeclimate中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63570559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com