Skip to content

Commit

Permalink
hotfix(golang): removed duplicated code definition of GoLang testing …
Browse files Browse the repository at this point in the history
…from different providers

Signed-off-by: Felipe Rios <[email protected]>
  • Loading branch information
rios0rios0 committed Oct 14, 2023
1 parent a8033c7 commit 78e0b24
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
17 changes: 2 additions & 15 deletions azure-devops/golang/stages/30-tests/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,5 @@ stages:
- task: 'GoTool@0'
inputs:
version: '1.20'
# TODO: this should be a share script between the vendors
- script: export GOPATH="$(pwd)/.go" # the GOPATH must be absolute
- script: export PATH="$PATH:$GOPATH/bin" # this is a workaround to detect the new GOPATH
- script: |
export INIT_SCRIPT="config.sh"
[[ -f $INIT_SCRIPT ]] && ./$INIT_SCRIPT || echo "The '$INIT_SCRIPT' file is not found, skipping..."
- script: touch coverage.xml
- script: |
go test -v -tags test,unit,integration \
-coverpkg ./main/... \
-covermode=count ./main/... \
-coverprofile=coverage.txt
- script: go tool cover -func coverage.txt
- script: go install github.com/boumenot/gocover-cobertura@latest
- script: $GOPATH/bin/gocover-cobertura < coverage.txt > coverage.xml
- template: '../../../global/abstracts/scripts-repo.yaml'
- script: $(Scripts.Directory)/global/scripts/golang/test/run.sh
13 changes: 2 additions & 11 deletions gitlab/golang/stages/30-tests/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@ test:all:
extends: '.go'
stage: 'tests'
script:
# TODO: this should be a share script between the vendors
- export INIT_SCRIPT="config.sh"
- "[[ -f $INIT_SCRIPT ]] && ./$INIT_SCRIPT || echo \"The '$INIT_SCRIPT' file is not found, skipping...\""
- touch coverage.xml
- go test -v -tags test,unit,integration
-coverpkg ./main/...
-covermode=count ./main/...
-coverprofile=coverage.txt
- go tool cover -func coverage.txt
- go install github.com/boumenot/gocover-cobertura@latest
- gocover-cobertura < coverage.txt > coverage.xml
- !reference [ .scripts-repo, before_script ]
- $SCRIPTS_DIR/global/scripts/golang/test/run.sh
coverage: '/total.*?([0-9]{1,3}[.][0-9]{0,2})%/'
artifacts:
when: 'always'
Expand Down
18 changes: 18 additions & 0 deletions global/scripts/golang/test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh

if [ -z "$SCRIPTS_DIR" ]; then
export SCRIPTS_DIR="$(echo $(dirname "$(realpath "$0")") | sed 's|\(.*pipelines\).*|\1|')"
fi

export GOPATH="$(pwd)/.go" # the GOPATH must be absolute
export PATH="$PATH:$GOPATH/bin" # this is a workaround to detect the new GOPATH

export INIT_SCRIPT="config.sh"
[[ -f $INIT_SCRIPT ]] && ./$INIT_SCRIPT || echo "The '$INIT_SCRIPT' file is not found, skipping..."

touch coverage.xml
go test -v -tags test,unit,integration -coverpkg ./main/... -covermode=count ./main/... -coverprofile=coverage.txt

go tool cover -func coverage.txt
go install github.com/boumenot/gocover-cobertura@latest
gocover-cobertura < coverage.txt > coverage.xml

0 comments on commit 78e0b24

Please sign in to comment.