Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/newm4n/goornogo
goornogo read `go test` report file and calculate the total coverage for the entire project. very useful to enforce coverage test in your pipeline
https://github.com/newm4n/goornogo
cli coverage go golang pipeline test
Last synced: about 1 month ago
JSON representation
goornogo read `go test` report file and calculate the total coverage for the entire project. very useful to enforce coverage test in your pipeline
- Host: GitHub
- URL: https://github.com/newm4n/goornogo
- Owner: newm4n
- License: apache-2.0
- Created: 2020-09-02T09:18:11.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-04T04:44:32.000Z (about 4 years ago)
- Last Synced: 2023-08-04T23:22:20.196Z (over 1 year ago)
- Topics: cli, coverage, go, golang, pipeline, test
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goornogo
Go Or No Go. Enforce coverage test in your golang project pipeline.
Goornogo will calculate coverage percentage from all tested golang source
code getting tested by the `go test`, not package by package.
If your Go project meet minimum coverage percentage,
the pipeline will finish without error. Otherwise your build will fail.## Install
```text
$ go install github.com/newm4n/goornogo
```## Usage in the pipeline
```text
go test ./... -covermode=count -coverprofile=coverage.out
goornogo -i coverage.out -c 60
```Params :
- `i` path to coverage report file
- `c` minimum coverage in percentage, 10 = 10%, 45.6 = 45.6%If coverage is above minimum coverage, goornogo will exit with code 0.
If bellow the minimum coverage, it will exit with code 1, failing your pipeline.### Travis-CI
```yaml
language: gogo:
- 1.13.xscript:
- go install github.com/newm4n/goornogo
- go test ./... -v -covermode=count -coverprofile=coverage.out
- goornogo -i coverage.out -c 45.3
```### Circle-CI
```yaml
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.13working_directory: /go/src/github.com/my/beautiful-project
steps:
- checkout# specify any bash command here prefixed with `run: `
- run: go get -v -t -d ./...
- run: go install github.com/newm4n/goornogo
- run: go test ./... -v -covermode=count -coverprofile=coverage.out
- run: goornogo -i coverage.out -c 45.3
```### Azure DevOps
```yaml
trigger:
- mastervariables:
GO111MODULE: 'on'
GOBIN: '$(GOPATH)/bin' # Go binaries path
GOROOT: '/usr/local/go1.13' # Go installation path
GOPATH: '$(system.defaultWorkingDirectory)/gopath' # Go workspace path
modulePath: '$(GOPATH)/src/github.com/my/beautiful-project' # Path to the module's codesteps:
- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
echo '##vso[task.setvariable variable=path]$(PATH):$(GOBIN)'
displayName: 'Set up the Go workspace'
- script: go get -v -t -d ./...
workingDirectory: '$(modulePath)'
displayName: 'go get dependencies'
- script: go build -v ./...
workingDirectory: '$(modulePath)'
displayName: 'Build'
- script: |
go install github.com/newm4n/goornogo
go test ./... -v -covermode=count -coverprofile=coverage.out
goornogo -i coverage.out -c 45.3
workingDirectory: '$(modulePath)'
displayName: 'Run tests'
```### Gitlab-CI
```yaml
image: golang:1.13stages:
- build
- testbuild:
script:
- go build ./...test:
script:
- go install github.com/newm4n/goornogo
- go test ./... -v -covermode=count -coverprofile=coverage.out
- goornogo -i coverage.out -c 45.3
```### Github Action
```yaml
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.13
- name: Checkout code
uses: actions/checkout@v2
- name: Fetching dependencies
run : go get -v -t -d ./...
- name: Install Goornogo
run : go install github.com/newm4n/goornogo
- name: Execute test
run : |
go test ./... -v -covermode=count -coverprofile=coverage.out
goornogo -i coverage.out -c 45.3
```## How you do that ?
Goornogo will read the produced coverage report file from `go test`.
It uses logic from [this code](https://github.com/golang/go/blob/2bc8d90fa21e9547aeb0f0ae775107dc8e05dc0a/src/cmd/cover/html.go#L96)
and [this code](https://github.com/golang/go/blob/2bc8d90fa21e9547aeb0f0ae775107dc8e05dc0a/src/cmd/cover/profile.go#L56) to understand the format and how to calculate the percentage.## Twist
This tiny winny fluffy project talks about code-coverage. While itself don't have any.