gocov does not upload the complete test-coverage result into codeclimate - go

Based on this question on StackOverflow, I added test coverage into my Gitlab CI/CD YAML file, and I expect the result gets uploaded into codeclimate.
- 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
The script runs test successfully in all my packages, and the output of CI/CD shows that all tests in different packages ran, but uploaded report into codeclimate only shows there is only one file with test-coverage and that is the last test package, instead of showing all.

I mixed the solution with another answer in the same stackoverflow link and finally create a bash file and ran it from my yaml file like this so the report output contain all package reports, this is my script:
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

Related

Go get "get" unexpected EOF

Thank you for visiting here.
First of all, I apologize for my bad English, maybe a little wrong, hope you can help me.
Then I had a little problem when deploying a new CI/CD system on k8s platform (v1.23.5+1) with Gitlab runner (14.9.0) and dind (docker:dind)
When deploying CI to Golang apps with private repositories at https://gitlab.domain.com, (I did the go env -w GOPRIVATE configuration), I had a problem with the go mod tidy command. Specifically getting the unexpected EOF error. I've tried go mod tidy -v but it doesn't seem to give any more info.
I did a lot of work to figure out the problem. Specifically, I have done wget and git clone commands with my private repository and they are still able to download successfully. I tried adding a private repository at https://gitlab.com in go.mod, they can still be retrieved without any errors.
And actually, without using my new runner, I can still git clone and go mod tidy in another vps.
All of this leaves me wondering where am I actually getting the error? Is it my gitlab or my k8s gitlab runner
This is runner output
go: downloading gitlab.domain.com/nood/fountain v0.0.12
unexpected EOF
Cleaning up project directory and file based variables
ERROR: Job failed: command terminated with exit code 1
This is my .gitlab-ci.yml
image: docker:latest
stages:
- build
- deploy
variables:
GTV_ECR_REPOSITORY_URL: repo.domain.com
PROJECT: nood
APP_NAME: backend-super-system
APP_NAME_ECR: backend-super-system
IMAGE_TAG: $GTV_ECR_REPOSITORY_URL/$PROJECT/$APP_NAME_ECR
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
services:
- name: docker:dind
entrypoint: ["env", "-u", "DOCKER_HOST"]
command: ["dockerd-entrypoint.sh", "--tls=false"]
build:
stage: build
allow_failure: false
script:
- echo "Building image."
- docker pull $IMAGE_TAG || echo "Building runtime from scratch"
- >
docker build
--cache-from $IMAGE_TAG
-t $IMAGE_TAG --network host .
- docker push $IMAGE_TAG
Dockerfile
FROM golang:alpine3.15
LABEL maintainer="NoodExe <nood.pr#gmail.com>"
WORKDIR /app
ENV BIN_DIR=/app/bin
RUN apk add --no-cache gcc build-base git
ADD . .
RUN chmod +x scripts/env.sh scripts/build.sh \
&& ./scripts/env.sh \
&& ./scripts/build.sh
# stage 2
FROM alpine:latest
WORKDIR /app
ENV BIN_DIR=/app/bin
ENV SCRIPTS_DIR=/app/scripts
ENV DATA_DIR=/app/data
# Build Args
ARG LOG_DIR=/var/log/nood
# Create log directory
RUN mkdir -p ${BIN_DIR} \
mkdir -p ${SCRIPTS_DIR} \
mkdir -p ${DATA_DIR} \
mkdir -p ${LOG_DIR} \
&& apk update \
&& addgroup -S nood \
&& adduser -S nood -G nood \
&& chown nood:nood /app \
&& chown nood:nood ${LOG_DIR}
USER nood
COPY --chown=nood:nood --from=0 ${BIN_DIR} /app
COPY --chown=nood:nood --from=0 ${DATA_DIR} ${DATA_DIR}
COPY --chown=nood:nood --from=0 ${SCRIPTS_DIR} ${SCRIPTS_DIR}
RUN chmod +x ${SCRIPTS_DIR}/startup.sh
ENTRYPOINT ["/app/scripts/startup.sh"]
scripts/env.sh
#!/bin/sh
go env -w GOPRIVATE=gitlab.domain.com/*
git config --global --add url."https://nood_deploy:rvbsosecret_Hizt97zQSn#gitlab.domain.com".insteadOf "https://gitlab.domain.com"
scripts/build.sh
#!/bin/sh
grep -v "replace\s.*=>.*" go.mod > tmpfile && mv tmpfile go.mod
go mod tidy
set -e
BIN_DIR=${BIN_DIR:-/app/bin}
mkdir -p "$BIN_DIR"
files=`ls *.go`
echo "****************************************"
echo "******** building applications **********"
echo "****************************************"
for file in $files; do
echo building $file
go build -o "$BIN_DIR"/${file%.go} $file
done
Thank you for still being here :3
This is a known issue with installing go modules from gitlab in nested locations. The issue describes several workarounds/solutions. One solution is described as follows:
create a gitlab Personal Access Token with at least read_api and read_repository scopes.
create a .netrc file:
machine gitlab.com
login yourname#gitlab.com
password yourpersonalaccesstoken
use go get --insecure to get your module
do not use the .gitconfig insteadOf workaround
For self-hosted instances of GitLab, there is also the additional option of using the go proxy, which is what I do to resolve this problem.
For additional context, see this answer to What's the proper way to "go get" a private repository?

mochawesome: provides empty report.json with error "Failed at the cypress#1.0.0 post_test script"

Followed the below steps mentioned in tutorial:
https://dev.to/bushraalam/using-mochawesome-reporter-with-cypress-54pf
Installed necessary packages through npm
Added pre and post scripts along with combine and generate report
Ran test script and was able to see that folders getting created in "rm -R -f cypress/reports && mkdir cypress/reports && mkdir cypress/reports/mocha"
But fails to generate report for the script -
commands:
"combine_reports": "mochawesome-merge ./cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json",
"generate_report": "marge cypress/reports/mochareports/ report.json -f report -o cypress/reports/mochareports",
"post_test": "npm run combine_reports && npm run generate_report",
SOLUTION: "cypress run -r cypress-multi-reporters test_script --reporter mochawesome" - generated the correct .json files for all test suites

circleci with parallelism - each container executing all the tests

I want my integration tests to run in parallel on Circleci.
I read this document https://circleci.com/blog/how-to-boost-build-time-with-test-parallelism/ and I setup my job like this
platform_component_test:
working_directory: *workspace_root
executor: ubuntu-machine
parallelism: 16
steps:
- prepare_workspace
- run:
name: 'Run Platform Component tests'
command:
./gradlew platform:componentTest -PtestFilter="`circleci tests glob "platform/src/componentTest/java/**/*.java"|circleci tests split`"
By looking at the UI, I see that each of the 16 containers that are spawn execute all the tests.
Am I missing something?
I ended up slightly modifying this and incorporating what I learned from here and here to build this:
- run:
name: Run tests in parallel
# Use "./gradlew test" instead if tests are not run in parallel
command: |
cd module-with-tests-to-run/src/test/kotlin
# Get list of classnames of tests that should run on this node
CLASSNAMES=$(circleci tests glob "**/**Test.kt" \
| cut -c 1- | sed 's#/#.#g' \
| sed 's/.\{3\}$//' \
| circleci tests split --split-by=timings --timings-type=classname)
cd ../../../..
# Format the arguments to "./gradlew test"
GRADLE_ARGS=$(echo $CLASSNAMES | awk '{for (i=1; i<=NF; i++) print "--tests",$i}')
echo "Prepared arguments for Gradle: $GRADLE_ARGS"
./gradlew clean module-with-tests-to-run:test $GRADLE_ARGS
note: I tried to get the formatting right but I might have goofed.

nosetests skip certain tests in python with multiple tests

I want to skip or exclude some certain tests from the build or the pipeline.
I am running nosetests -s -v * which runs all the tests under some specific folder.
Suppose there are about 30 tests and out of the 5 I want to skip- To do that I am trying
nosetests -s -v * --exclude-test test_sometest.py test_somemoretest.py
or
nosetests -s -v * -- test_sometest.py test_somemoretest.py
but both of them not work for me.
I am referring from here
#!/bin/sh
cd tests/engine_tests/measures
nosetests -s -v * --exclude-test test_sometest1.py test_somemoretest2.py test_sometest3.py test_somemoretest4.py
Any help would be great!!
Add this parameter to your command:
--ignore-files="tests_to_exclude\.py"
python -m pytest --cache-clear -v -x -r a --junit-xml=tests/engine_tests --junit-prefix=measure_tests *.py --deselect Test1\.py --deselect Test2\.py --deselect Test3\.py --deselect Test4\.py
I tried this and it worked for me. Before that You need to install pytest
pip install pytest
Documentation will be find by typing
pytest --help under terminal
or somewhere here

How to exclude or skip specific directory while running 'go test' [duplicate]

This question already has an answer here:
Running tests and skipping some packages
(1 answer)
Closed 3 years ago.
go test $(go list ./... | grep -v /vendor/) -coverprofile .testCoverage.txt
I am using the above command to test the files but there is 1 folder with the name "Store" that I want to exclude from tests. How it can be done?
You're already doing it:
$(go list ./... | grep -v /vendor/)
The grep -v /vendor/ part is to exclude the /vendor/ directory. So just do the same for your Store directory:
go test $(go list ./... | grep -v /Store/) -coverprofile .testCoverage.txt
Note that excluding /vendor/ this way is not necessary (unless you're using a really old version of Go). If you are using an old version of Go, you can combine them:
go test $(go list ./... | grep -v /vendor/ | grep -v /Store/) -coverprofile .testCoverage.txt

Resources