golang-live-coverage-report

module
v0.0.0-...-2977300 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2020 License: MIT

README

golang-live-coverage-report

Golang coverage report was official supported by go test -coverprofile.

This tool makes it available for integration test of long-run project, e.g. a web server.

Most code is copied from golang cmd/cover and testing pakcage.

Support golang 1.11+.

Demo

  1. Run the following script

    # prepare temp directory
    mkdir /tmp/gopath
    cd /tmp/gopath
    
    # go get
    GOPATH=/tmp/gopath go get github.com/ikarishinjieva/golang-live-coverage-report/cmd/golang-live-coverage-report
    
    # build demo
    cd /tmp/gopath/src/github.com/ikarishinjieva/golang-live-coverage-report/examples/
    GOPATH=/tmp/gopath PATH=$GOPATH/bin:$PATH make
    
    # start demo server
    ./demo 
    
  2. open a browser with http://localhost:8080/report, you will see a report like:

Coverage Report 1

  1. open http://localhost:8080/run_once, to run the target function once

  2. open http://localhost:8080/report again, you will see the report with some code line already covered

Coverage Report 2

How to use

The brief steps of this tool are:

  1. Before building your project, run golang-live-coverage-report -pre-build ... {files-included-in-the-report}:

    1.1 This tool will copy the files to temporary directory (-raw-code-build-dir)

    1.2 This tool will inject some codes into the files

    1.3 This tool will generate a bootstrap golang file (-bootstrap-outfile), the package name could be specified by -bootstrap-package-name

  2. Build your project:

    2.1 Add a HTTP handler using GenerateHtmlReport() in your code, example is here

    2.2 Compile your project with the bootstrap file

    2.3 Remember to exclude the temporary directory in step 1.1 when compiling

    2.4 Copy the temporary directory to {your building directory}/{path specified by '-raw-code-deploy-dir'}

  3. After building your project, run golang-live-coverage-report -post-build ... {files-included-in-the-report} to rollback the changes:

    3.1 Remove the bootstrap file in step 1.3

    3.2 Rollback the injected files, with files in temporary directory in step 1.1

    3.3 Remove the temporary directory in step 1.1

  4. The entire process example is here

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL