Skip to content

Commit ff8e0c5

Browse files
committed
Add coverage and code quality badges.
1 parent 8ded56a commit ff8e0c5

File tree

7 files changed

+52
-6
lines changed

7 files changed

+52
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ postgres_exporter_integration_test
66
*-stamp
77
.idea
88
*.iml
9+
cover.out
10+
cover.*.out
11+

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ go:
66
- '1.7'
77
# Make sure we have p2 and the postgres client.
88
before_install:
9+
- go get -v github.com/mattn/goveralls
910
- sudo wget -O /usr/local/bin/p2 https://github.com/wrouesnel/p2cli/releases/download/r4/p2 &&
1011
sudo chmod +x /usr/local/bin/p2
1112
- sudo wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.9.0-rc4/docker-compose-Linux-x86_64 &&
@@ -16,6 +17,8 @@ script:
1617
- make all
1718
- make docker
1819
- make test-integration
20+
- ./concatenate_coverage cover.out cover.test.out cover.integration.out
21+
- $HOME/gopath/bin/goveralls -coverprofile=cover.out -service=travis-ci
1922
after_success:
2023
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
2124
# Push a tagged build if a tag is found.

Makefile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

2-
GO_SRC := $(shell find . -type f -name "*.go")
2+
GO_SRC := $(shell find -type f -name '*.go' ! -path '*/vendor/*')
33

44
CONTAINER_NAME ?= wrouesnel/postgres_exporter:latest
5+
VERSION ?= $(shell git describe --dirty)
56

67
all: vet test postgres_exporter
78

@@ -10,24 +11,32 @@ cross: docker-build docker
1011

1112
# Simple go build
1213
postgres_exporter: $(GO_SRC)
13-
CGO_ENABLED=0 go build -a -ldflags "-extldflags '-static' -X main.Version=$(shell git describe --dirty)" -o postgres_exporter .
14+
CGO_ENABLED=0 go build -a -ldflags "-extldflags '-static' -X main.Version=$(VERSION)" -o postgres_exporter .
1415

1516
postgres_exporter_integration_test: $(GO_SRC)
1617
CGO_ENABLED=0 go test -c -tags integration \
17-
-a -ldflags "-extldflags '-static' -X main.Version=git:$(shell git describe --dirty)" -o postgres_exporter_integration_test .
18+
-a -ldflags "-extldflags '-static' -X main.Version=$(VERSION)" -o postgres_exporter_integration_test -cover -covermode count .
1819

1920
# Take a go build and turn it into a minimal container
2021
docker: postgres_exporter
2122
docker build -t $(CONTAINER_NAME) .
2223

2324
vet:
24-
go vet .
25+
go vet
26+
27+
# Check code conforms to go fmt
28+
style:
29+
! gofmt -s -l $(GO_SRC) 2>&1 | read 2>/dev/null
30+
31+
# Format the code
32+
fmt:
33+
gofmt -s -w $(GO_SRC)
2534

2635
test:
27-
go test -v -cover .
36+
go test -v -covermode count -coverprofile=cover.test.out
2837

2938
test-integration: postgres_exporter postgres_exporter_integration_test
30-
tests/test-smoke ./postgres_exporter ./postgres_exporter_integration_test
39+
tests/test-smoke "$(shell pwd)/postgres_exporter" "$(shell pwd)/postgres_exporter_integration_test_script $(shell pwd)/postgres_exporter_integration_test $(shell pwd)/cover.integration.out"
3140

3241
# Do a self-contained docker build - we pull the official upstream container
3342
# and do a self-contained build.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[![Build Status](https://travis-ci.org/wrouesnel/postgres_exporter.svg?branch=master)](https://travis-ci.org/wrouesnel/postgres_exporter)
2+
[![Coverage Status](https://coveralls.io/repos/github/wrouesnel/postgres_exporter/badge.svg?branch=master)](https://coveralls.io/github/wrouesnel/postgres_exporter?branch=master)
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/wrouesnel/postgres_exporter)](https://goreportcard.com/report/github.com/wrouesnel/postgres_exporter)
24

35
# PostgresSQL Server Exporter
46

@@ -108,3 +110,4 @@ AS
108110
GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;
109111
GRANT SELECT ON postgres_exporter.pg_stat_activity TO postgres_exporter;
110112
```
113+

concatenate_coverage

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# Concatenate a list of coverage reports
3+
# Usage: concatenate_coverage <out> [[test] ...]
4+
5+
output_file=$1
6+
shift
7+
cat $1 > $output_file
8+
shift
9+
10+
for f in $@ ; do
11+
tail -n +2 $f >> $output_file
12+
done
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# This script wraps the integration test binary so it produces concatenated
3+
# test output.
4+
5+
test_binary=$1
6+
shift
7+
output_cov=$1
8+
shift
9+
10+
echo "mode: count" > $output_cov
11+
12+
test_cov=$(mktemp)
13+
$test_binary -test.coverprofile=$test_cov $@
14+
tail -n +2 $test_cov >> $output_cov
15+
rm -f $test_cov

tests/test-smoke

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ smoketest_postgres() {
8181
wait_for_postgres localhost 55432
8282

8383
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@localhost:55432/?sslmode=disable" $test_binary --log.level=debug || exit $?
84+
8485
# exporter_pid=$!
8586
# trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME ; kill $exporter_pid; exit 1" EXIT INT TERM
8687
# wait_for_exporter

0 commit comments

Comments
 (0)