Skip to content

pzurek/example-go

 
 

Repository files navigation

Codecov Go Example

https://codecov.io @codecov hello@codecov.io

This repository serves as an example on how to use Codecov Global for Go.

Note: use -covermode=atomic or -covermode=count to show how many times a statement was executed.

Travis CI

Add to your .travis.yml file.

language: go

go:
  - 1.2

before_install:
  - go get github.com/onsi/gomega
  - go get github.com/onsi/ginkgo
  - go get code.google.com/p/go.tools/cmd/cover

script:
  - go test -coverprofile=coverage.txt -covermode=atomic

after_success:
  - bash <(curl -s https://codecov.io/bash)

All other CI you can simply run bash <(curl -s https://codecov.io/bash).

Private Repos

Set CODECOV_TOKEN in your environment variables.

Add to your .travis.yml file.

env:
  global:
    - CODECOV_TOKEN=:uuid-repo-token

after_success:
  - bash <(curl -s https://codecov.io/bash)

Caveat: Multiple files

If you see this cannot use test profile flag with multiple packages then use this shell template to execute your tests and store coverage output

#!/usr/bin/env bash

set -e
echo "" > coverage.txt

for d in $(find ./* -maxdepth 10 -type d); do
    if ls $d/*.go &> /dev/null; then
        go test -coverprofile=profile.out -covermode=atomic $d
        if [ -f profile.out ]; then
            cat profile.out >> coverage.txt
            rm profile.out
        fi
    fi
done

Then run this file as your test (ex. ./test.sh)

Reference http://stackoverflow.com/a/21142256/2055281

View source and learn more about Codecov Global Uploader

About

Go coverage example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 77.5%
  • Shell 22.5%