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


Keywords
go, cli, golang, coverage, pipeline, test
License
Apache-2.0
Install
go get github.com/newm4n/goornogo

Documentation

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

$ go install github.com/newm4n/goornogo

Usage in the pipeline

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

language: go

go:
  - 1.13.x

script:
  - go install github.com/newm4n/goornogo 
  - go test ./... -v -covermode=count -coverprofile=coverage.out
  - goornogo -i coverage.out -c 45.3

Circle-CI

version: 2
jobs:
  build:
    docker:
      - image: circleci/golang:1.13

    working_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

trigger:
  - master

variables:
  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 code

steps:
  - 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

image: golang:1.13

stages:
  - build
  - test

build:
  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

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 and this code 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.