Drive higher confidence in making changes by detecting large blocks of untested functionality

Overview

go-coverage

Increase code coverage of Go projects

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap

About The Project

The key challenge with large code bases with low test coverage is to prioritize which sections of code to test first.

The standard coverage tools tell about the code coverage percentage and what is covered and uncovered however it doesn't give an input on which functions to cover first and what will be the impact of covering them.

This tool addresses the challenge by providing the sorted list of functions to cover and the impact associated with covering it.

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

You'll need Go installed to use this tool. Here is the installation instructions for Go.

Installation

Via go get

go get -u github.com/gojek/go-coverage

Usage

Prerequisites

Generate the coverage profile for your Go codebase, usually done via

go test ./... -coverprofile=coverage.out

Get lines uncovered greater than 10

go-coverage -f coverage.out --line-filter 10

Get trimmed file names

go-coverage -f coverage.out --line-filter 10 --trim
+-------------------------+-------------------------------------+-----------------+--------+
|          FILE           |              FUNCTION               | UNCOVERED LINES | IMPACT |
+-------------------------+-------------------------------------+-----------------+--------+
| ...ice/config/config.go | RadiusForClosestDriverByServicetype |              26 |    1.9 |
| ...ice/config/config.go | RadiusForServicetype                |              26 |    1.9 |
| ...ice/config/config.go | AliceDriverLimit                    |              26 |    1.9 |
| ...ice/config/config.go | ConsumerDriverLimitByServicetype    |              26 |    1.9 |
| .../service/handlers.go | findDriver                          |              19 |    1.4 |
| ...ice/extern/driver.go | driverAllocationStatusFromAPI       |              19 |    1.4 |
| .../service/handlers.go | updateDriverVehicleTags             |              18 |    1.3 |
| ...ice/config/config.go | ConsumerDriverLimit                 |              14 |    1.0 |
| ...vice/service/cron.go | startCrons                          |              14 |    1.0 |
| ...ice/config/config.go | RadiusForVehicleType                |              13 |    0.9 |
| ...ice/config/config.go | matchVehicleType                    |              12 |    0.9 |
| ...rvice/service/api.go | startServer                         |              11 |    0.8 |
+-------------------------+-------------------------------------+-----------------+--------+

Exclude file name pattern

go-coverage -f coverage.out --exclude ".*config.*" --line-filter 10 --trim
+-------------------------+-------------------------------+-----------------+--------+
|          FILE           |           FUNCTION            | UNCOVERED LINES | IMPACT |
+-------------------------+-------------------------------+-----------------+--------+
| .../service/handlers.go | findDriver                    |              19 |    1.4 |
| ...ice/extern/driver.go | driverAllocationStatusFromAPI |              19 |    1.4 |
| .../service/handlers.go | updateDriverVehicleTags       |              18 |    1.3 |
| ...vice/service/cron.go | startCrons                    |              14 |    1.0 |
| ...rvice/service/api.go | startServer                   |              11 |    0.8 |
+-------------------------+-------------------------------+-----------------+--------+

Roadmap

  • Support generation of HTML
  • Integrate with gitlab
Issues
  • go install doesn't work

    go install doesn't work

    newer programs (such as this tool) should be installed by the command: go install github.com/gojek/[email protected] instead of the go get -u variant

    But if i do that, there is something wrong: go: downloading github.com/gojek/go-coverage v0.0.1 go install: github.com/gojek/[email protected]: github.com/gojek/[email protected]: parsing go.mod: module declares its path as: github.com/gojekfarm/go-coverage but was required as: github.com/gojek/go-coverage

    Great idea for that tool BTW :-)

    opened by marcelloh 4
  • Only include functions with lines considered on the report

    Only include functions with lines considered on the report

    This change avoids to add functions that have no lines on the coverage report, needed for reports filtered by line, as in a PR changes coverage report.

    Currently it is reporting 1 line missing coverage of every function not present on the report. This could be seen for example with this report, which was filtered to only the first two blocks of code:

    mode: atomic
    github.com/gojek/go-coverage/go_coverage.go:22.13,58.38 2 0
    github.com/gojek/go-coverage/go_coverage.go:99.2,100.16 2 0
    

    Currently it returns:

    +-------------------------+--------------------+-----------------+--------+
    |          FILE           |      FUNCTION      | UNCOVERED LINES | IMPACT |
    +-------------------------+--------------------+-----------------+--------+
    | ...erage/go_coverage.go | main               |               4 |   26.7 |
    | ...erage/go_coverage.go | getTrimmedFileName |               1 |    6.7 |
    | ...erage/go_coverage.go | fmtFuncInfo        |               1 |    6.7 |
    | ...erage/go_coverage.go | printBat           |               1 |    6.7 |
    | ...erage/go_coverage.go | calculateCoverage  |               1 |    6.7 |
    | ...erage/go_coverage.go | printTable         |               1 |    6.7 |
    | ...erage/go_coverage.go | getFunctionInfos   |               1 |    6.7 |
    | ...erage/go_coverage.go | trimString         |               1 |    6.7 |
    | ...erage/go_coverage.go | findFuncs          |               1 |    6.7 |
    | ...erage/go_coverage.go | Visit              |               1 |    6.7 |
    | ...erage/go_coverage.go | coverage           |               1 |    6.7 |
    | ...erage/go_coverage.go | findFile           |               1 |    6.7 |
    +-------------------------+--------------------+-----------------+--------+
    

    With this changes will return only the functions present on the report :

    +-------------------------+----------+-----------------+--------+
    |          FILE           | FUNCTION | UNCOVERED LINES | IMPACT |
    +-------------------------+----------+-----------------+--------+
    | ...erage/go_coverage.go | main     |               4 |  100.0 |
    +-------------------------+----------+-----------------+--------+
    
    opened by marcosngomezi 0
  • have option not to use full path

    have option not to use full path

    It would be nice if there was an option, like --trim, not to use the full path. in the coverage file itself, files are not shown as a filepath, but as a URI. github.com/company/software/dir/package/somefunc.go instead of: /Users/marcelloh/data/company/software/dir//package/somefunc.go

    The reason is, that I might use it in a presentation towards the customer, and it doesn't look professional when my name is in there. Or perhaps you can just start at the current dir (and remove everything in front of that.

    opened by MarcelXia 1
Releases(v0.0.1)
Owner
Gojek
SuperApp from Southeast Asia
Gojek
This testing tool surrounds go-ethereum with cannon to catch the blocks of retesteth going into go-ethereum and test cannon with them

Siege This testing tool surrounds go-ethereum with cannon to catch the blocks of retesteth going into go-ethereum and test cannon with them. Usage Sta

Diederik Loerakker 8 Mar 15, 2022
A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol.

About chromedp Package chromedp is a faster, simpler way to drive browsers supporting the Chrome DevTools Protocol in Go without external dependencies

Chrome DevTools Protocol clients and tools for Go 8k Aug 14, 2022
A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol.

About chromedp Package chromedp is a faster, simpler way to drive browsers supporting the Chrome DevTools Protocol in Go without external dependencies

Chrome DevTools Protocol clients and tools for Go 8k Aug 12, 2022
Aquatone is a tool for visual inspection of websites across a large amount of hosts and is convenient for quickly gaining an overview of HTTP-based attack surface.

Aquatone is a tool for visual inspection of websites across a large amount of hosts and is convenient for quickly gaining an overview of HTTP-based attack surface.

Michael Henriksen 4.7k Aug 9, 2022
Middleware for Blocking IP ranges by inserting CIDR Blocks and searching IPs through those blocks

firewall Middleware for Blocking IP ranges by inserting CIDR Blocks and searching IPs through those blocks. Features Easy to use Efficient and Fast Co

Golang libraries for everyone 5 May 20, 2022
Command-line tool to organize large directories of media files recursively by date, detecting duplicates.

go-media-organizer Command-line tool written in Go to organise all media files in a directory recursively by date, detecting duplicates.

Allan Avelar 8 Jan 6, 2022
"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Yandex Files

Website | Documentation | Download | Contributing | Changelog | Installation | Forum Rclone Rclone ("rsync for cloud storage") is a command-line progr

rclone 34.1k Aug 13, 2022
Download an upload large files to Google Drive (API v3)

gdriver gdriver is a command-line tool, written in Go, used for uploading and downloading large personal files from Google Drive (API v3). The tool pr

Marcin Tojek 66 Jul 20, 2022
apicompat checks recent changes to a Go project for backwards incompatible changes

Introduction apicompat is a tool to check for the introduction of backwards incompatible changes. apicompat: Guarantees that all consumers of a librar

Bradley Falzon 175 Aug 3, 2022
ChangeTower is intended to help you watch changes in webpages and get notified of any changes written in Go

ChangeTower is intended to help you watch changes in webpages and get notified of any changes written in Go

The Cats 32 Jul 6, 2022
gosx-notifier is a Go framework for sending desktop notifications to OSX 10.8 or higher

gosx-notifier A Go lib for sending desktop notifications to OSX Mountain Lion's (10.8 or higher REQUIRED) Notification Center. Update 4/3/2014 On OSX

Ralph Caraveo III 573 Jul 27, 2022
Bubbly is an open-source platform that gives you confidence in your continuous release process.

Bubbly Bubbly - Release Readiness in a Bubble Bubbly emerged from a need that many lean software teams practicing Continuous Integration and Delivery

Valocode 34 Jul 27, 2022
Higher level abstraction for Sarama.

kafka-do v0.1.5 kafka-do What Higher level abstraction for Sarama. Why We want to be able to write our kafka applications without making the same thin

seo.do 21 Sep 30, 2021
Higher Order Functions using Golang Generics (Hack Days 2022)

hoff: Higher Order Functions (and Friends) Golang 1.18+ implementations of common methods/data structures using Go Generics Requirements Go 1.18 or ne

Shopify 19 Aug 12, 2022
Drone Plugin for detecting credentials or other sensitive data in your repository

A plugin to detect hard-coded secrets and sensitive data in your source code files. Building Build the plugin binary: scripts/build.sh Build the plug

Drone by Harness 1 Apr 21, 2022
Go library for detecting and expanding the user's home directory without cgo.

go-homedir This is a Go library for detecting the user's home directory without the use of cgo, so the library can be used in cross-compilation enviro

Mitchell Hashimoto 1.2k Aug 9, 2022
:exclamation:Basic Assertion Library used along side native go testing, with building blocks for custom assertions

Package assert Package assert is a Basic Assertion library used along side native go testing Installation Use go get. go get github.com/go-playground/

Go Playgound 41 Aug 4, 2022
A tool to dump and restore Prometheus data blocks.

promdump promdump dumps the head and persistent blocks of Prometheus. It supports filtering the persistent blocks by time range. Why This Tool When de

Ivan Sim 105 Aug 2, 2022
Geth client which picks the most profitable blocks to mine using a greedy algorithm

Greeden-Geth Greeden-Geth is a protocol-agnostic client which uses a greedy algorithm to pick the most profitable blocks to submit to the network out

Nathan 72 Aug 3, 2022
Flashbots utilities in Go: Blocks & Transactions API, and tools to spot bundle and block irregularities

Utilities for Flashbots Go API client for the mev-blocks API for information about Flashbots blocks and transactions Detect bundle errors: (a) out of

Chris Hager 31 Jul 20, 2022
Tanzu Framework provides a set of building blocks to build atop of the Tanzu platform and leverages Carvel packaging

Tanzu Framework provides a set of building blocks to build atop of the Tanzu platform and leverages Carvel packaging and plugins to provide users with a much stronger, more integrated experience than the loose coupling and stand-alone commands of the previous generation of tools.

VMware Tanzu 170 Aug 4, 2022
Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.

Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app. This is done by replacing variables in main during build with ldflags.

null 1 Nov 14, 2021
Log4Shell: a middleware plugin for Traefik which blocks JNDI attacks based on HTTP header values

Traefik (pronounced traffic) is a modern HTTP reverse proxy and load balancer that makes deploying microservices easy. Traefik integrates with your ex

Traefik Labs 39.2k Aug 9, 2022
Log4Shell is a middleware plugin for Traefik which blocks JNDI attacks based on HTTP header values.

Log4Shell Mitigation Log4Shell is a middleware plugin for Traefik which blocks JNDI attacks based on HTTP header values. Related to the Log4J CVE: htt

Traefik Labs 33 Jul 26, 2022
Fairly general building blocks used in Arista Go code and open-sourced for the benefit of all.

Arista Go library areflect Helper functions to work with the reflect package. Contains ForceExport(), which bypasses the check in reflect.Value that p

Arista Networks 180 Jul 29, 2022