Skip to content

Commit

Permalink
Add coveralls integration (luraproject#5)
Browse files Browse the repository at this point in the history
* coveralls config added
* avoid testing the examples
* typo fixed
* coveralls badge added
* use the coverage.sh trick
  • Loading branch information
kpacha authored Dec 6, 2016
1 parent 64b9d63 commit 42401c5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ language: go
go:
- 1.7.4
- tip

script:
- make coveralls
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.PHONY: all deps test build run benchmark cover

PACKAGES = $(shell go list ./... | grep -v /examples/)

all: deps test build

deps:
Expand All @@ -9,11 +11,11 @@ deps:

test:
go fmt ./...
go test -cover ./...
go test -cover $(PACKAGES)
go vet ./...

benchmark:
go test -bench=. -benchtime=3s ./...
go test -bench=. -benchtime=3s $(PACKAGES)

build: build_gin_example build_mux_example

Expand All @@ -22,3 +24,7 @@ build_gin_example:

build_mux_example:
cd examples/mux/ && make && cd ../.. && cp examples/mux/krakend_mux_example* .

coveralls: all
go get github.com/mattn/goveralls
sh coverage.sh --coveralls
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# KrakenD

[![Travis-CI](https://travis-ci.org/devopsfaith/krakend.svg?branch=master)](https://travis-ci.org/devopsfaith/krakend) [![Go Report Card](https://goreportcard.com/badge/github.com/devopsfaith/krakend)](https://goreportcard.com/report/github.com/devopsfaith/krakend) [![GoDoc](https://godoc.org/github.com/devopsfaith/krakend?status.svg)](https://godoc.org/github.com/devopsfaith/krakend)
[![Travis-CI](https://travis-ci.org/devopsfaith/krakend.svg?branch=master)](https://travis-ci.org/devopsfaith/krakend) [![Go Report Card](https://goreportcard.com/badge/github.com/devopsfaith/krakend)](https://goreportcard.com/report/github.com/devopsfaith/krakend) [![Coverage Status](https://coveralls.io/repos/github/devopsfaith/krakend/badge.svg?branch=master)](https://coveralls.io/github/devopsfaith/krakend?branch=master) [![GoDoc](https://godoc.org/github.com/devopsfaith/krakend?status.svg)](https://godoc.org/github.com/devopsfaith/krakend)

Ultra performant API Gateway with middlewares

Expand Down
53 changes: 53 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh
# Generate test coverage statistics for Go packages.
#
# Works around the fact that `go test -coverprofile` currently does not work
# with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909
#
# Usage: script/coverage [--html|--coveralls]
#
# --html Additionally create HTML report and open it in browser
# --coveralls Push coverage statistics to coveralls.io
#
# File taken from https://github.com/mlafeldt/chef-runner/blob/v0.7.0/script/coverage

set -e

workdir=.cover
profile="$workdir/cover.out"
mode=count

generate_cover_data() {
rm -rf "$workdir"
mkdir "$workdir"

for pkg in "$@"; do
f="$workdir/$(echo $pkg | tr / -).cover"
go test -covermode="$mode" -coverprofile="$f" "$pkg"
done

echo "mode: $mode" >"$profile"
grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
}

show_cover_report() {
go tool cover -${1}="$profile"
}

push_to_coveralls() {
echo "Pushing coverage statistics to coveralls.io"
goveralls -coverprofile="$profile"
}

generate_cover_data $(go list ./... | grep -v /examples/)
show_cover_report func
case "$1" in
"")
;;
--html)
show_cover_report html ;;
--coveralls)
push_to_coveralls ;;
*)
echo >&2 "error: invalid option: $1"; exit 1 ;;
esac
2 changes: 1 addition & 1 deletion examples/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type customProxyFactory struct {
}

// New implements the Factory interface
func (cf customRouterFactory) New(cfg *config.EndpointConfig) (p proxy.Proxy, err error) {
func (cf customProxyFactory) New(cfg *config.EndpointConfig) (p proxy.Proxy, err error) {
p, err = cf.factory.New(cfg)
if err == nil {
p = proxy.NewLoggingMiddleware(cf.logger, cfg.Endpoint)(p)
Expand Down

0 comments on commit 42401c5

Please sign in to comment.