mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-22 06:55:41 +00:00
Add coverage and code quality badges.
This commit is contained in:
parent
8ded56a7da
commit
ff8e0c5382
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,3 +6,6 @@ postgres_exporter_integration_test
|
||||
*-stamp
|
||||
.idea
|
||||
*.iml
|
||||
cover.out
|
||||
cover.*.out
|
||||
|
||||
|
@ -6,6 +6,7 @@ go:
|
||||
- '1.7'
|
||||
# Make sure we have p2 and the postgres client.
|
||||
before_install:
|
||||
- go get -v github.com/mattn/goveralls
|
||||
- sudo wget -O /usr/local/bin/p2 https://github.com/wrouesnel/p2cli/releases/download/r4/p2 &&
|
||||
sudo chmod +x /usr/local/bin/p2
|
||||
- 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:
|
||||
- make all
|
||||
- make docker
|
||||
- make test-integration
|
||||
- ./concatenate_coverage cover.out cover.test.out cover.integration.out
|
||||
- $HOME/gopath/bin/goveralls -coverprofile=cover.out -service=travis-ci
|
||||
after_success:
|
||||
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
|
||||
# Push a tagged build if a tag is found.
|
||||
|
21
Makefile
21
Makefile
@ -1,7 +1,8 @@
|
||||
|
||||
GO_SRC := $(shell find . -type f -name "*.go")
|
||||
GO_SRC := $(shell find -type f -name '*.go' ! -path '*/vendor/*')
|
||||
|
||||
CONTAINER_NAME ?= wrouesnel/postgres_exporter:latest
|
||||
VERSION ?= $(shell git describe --dirty)
|
||||
|
||||
all: vet test postgres_exporter
|
||||
|
||||
@ -10,24 +11,32 @@ cross: docker-build docker
|
||||
|
||||
# Simple go build
|
||||
postgres_exporter: $(GO_SRC)
|
||||
CGO_ENABLED=0 go build -a -ldflags "-extldflags '-static' -X main.Version=$(shell git describe --dirty)" -o postgres_exporter .
|
||||
CGO_ENABLED=0 go build -a -ldflags "-extldflags '-static' -X main.Version=$(VERSION)" -o postgres_exporter .
|
||||
|
||||
postgres_exporter_integration_test: $(GO_SRC)
|
||||
CGO_ENABLED=0 go test -c -tags integration \
|
||||
-a -ldflags "-extldflags '-static' -X main.Version=git:$(shell git describe --dirty)" -o postgres_exporter_integration_test .
|
||||
-a -ldflags "-extldflags '-static' -X main.Version=$(VERSION)" -o postgres_exporter_integration_test -cover -covermode count .
|
||||
|
||||
# Take a go build and turn it into a minimal container
|
||||
docker: postgres_exporter
|
||||
docker build -t $(CONTAINER_NAME) .
|
||||
|
||||
vet:
|
||||
go vet .
|
||||
go vet
|
||||
|
||||
# Check code conforms to go fmt
|
||||
style:
|
||||
! gofmt -s -l $(GO_SRC) 2>&1 | read 2>/dev/null
|
||||
|
||||
# Format the code
|
||||
fmt:
|
||||
gofmt -s -w $(GO_SRC)
|
||||
|
||||
test:
|
||||
go test -v -cover .
|
||||
go test -v -covermode count -coverprofile=cover.test.out
|
||||
|
||||
test-integration: postgres_exporter postgres_exporter_integration_test
|
||||
tests/test-smoke ./postgres_exporter ./postgres_exporter_integration_test
|
||||
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"
|
||||
|
||||
# Do a self-contained docker build - we pull the official upstream container
|
||||
# and do a self-contained build.
|
||||
|
@ -1,4 +1,6 @@
|
||||
[](https://travis-ci.org/wrouesnel/postgres_exporter)
|
||||
[](https://coveralls.io/github/wrouesnel/postgres_exporter?branch=master)
|
||||
[](https://goreportcard.com/report/github.com/wrouesnel/postgres_exporter)
|
||||
|
||||
# PostgresSQL Server Exporter
|
||||
|
||||
@ -108,3 +110,4 @@ AS
|
||||
GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;
|
||||
GRANT SELECT ON postgres_exporter.pg_stat_activity TO postgres_exporter;
|
||||
```
|
||||
|
||||
|
12
concatenate_coverage
Executable file
12
concatenate_coverage
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
# Concatenate a list of coverage reports
|
||||
# Usage: concatenate_coverage <out> [[test] ...]
|
||||
|
||||
output_file=$1
|
||||
shift
|
||||
cat $1 > $output_file
|
||||
shift
|
||||
|
||||
for f in $@ ; do
|
||||
tail -n +2 $f >> $output_file
|
||||
done
|
15
postgres_exporter_integration_test_script
Executable file
15
postgres_exporter_integration_test_script
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
# This script wraps the integration test binary so it produces concatenated
|
||||
# test output.
|
||||
|
||||
test_binary=$1
|
||||
shift
|
||||
output_cov=$1
|
||||
shift
|
||||
|
||||
echo "mode: count" > $output_cov
|
||||
|
||||
test_cov=$(mktemp)
|
||||
$test_binary -test.coverprofile=$test_cov $@
|
||||
tail -n +2 $test_cov >> $output_cov
|
||||
rm -f $test_cov
|
@ -81,6 +81,7 @@ smoketest_postgres() {
|
||||
wait_for_postgres localhost 55432
|
||||
|
||||
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@localhost:55432/?sslmode=disable" $test_binary --log.level=debug || exit $?
|
||||
|
||||
# exporter_pid=$!
|
||||
# trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME ; kill $exporter_pid; exit 1" EXIT INT TERM
|
||||
# wait_for_exporter
|
||||
|
Loading…
Reference in New Issue
Block a user