Permalink
Browse files

Clean up build and test setup

* Replace Makefile.COMMON approach with promu
* Upgraded example app (which wasn't compiling) to a first test function
  • Loading branch information...
grobie committed Sep 6, 2016
1 parent 9bd8de9 commit 9e8b7a09a6d603c3992e7a2a3045e9f72888522c
Showing with 134 additions and 182 deletions.
  1. +13 −0 .promu.yml
  2. +56 −3 Makefile
  3. +0 −132 Makefile.COMMON
  4. +1 −0 VERSION
  5. +64 −0 bind_exporter_test.go
  6. +0 −47 example/test_parse.go
  7. 0 example/example.xml → fixtures/v2.xml
View
@@ -0,0 +1,13 @@
repository:
path: github.com/digitalocean/bind_exporter
build:
ldflags: |
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- LICENSE
- NOTICE
View
@@ -11,7 +11,60 @@
# See the License for the specific language governing permissions and
# limitations under the License.
VERSION := 0.1.1
TARGET := bind_exporter
GO := GO15VENDOREXPERIMENT=1 go
PROMU := $(GOPATH)/bin/promu
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
include Makefile.COMMON
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_NAME ?= bind-exporter
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
ifdef DEBUG
bindata_flags = -debug
endif
all: format build test
test:
@echo ">> running tests"
@$(GO) test -short $(pkgs)
style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
format:
@echo ">> formatting code"
@$(GO) fmt $(pkgs)
vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)
build: promu
@echo ">> building binaries"
@$(PROMU) build --prefix $(PREFIX)
tarball: promu
@echo ">> building release tarball"
@$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
docker:
@echo ">> building docker image"
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
assets:
@echo ">> writing assets"
-@$(GO) get -u github.com/jteeuwen/go-bindata/...
@go-bindata $(bindata_flags) -pkg ui -o ui/bindata.go ui/...
@go-bindata $(bindata_flags) -pkg deftmpl -o template/internal/deftmpl/bindata.go template/default.tmpl
promu:
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
$(GO) get -u github.com/prometheus/promu
.PHONY: all style format build test vet assets tarball docker promu
View

This file was deleted.

Oops, something went wrong.
View
@@ -0,0 +1 @@
0.2.0-dev
View
@@ -0,0 +1,64 @@
package main
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/expfmt"
)
func TestBindExporter(t *testing.T) {
tests := []string{
`bind_up 1`,
`bind_incoming_queries_total{type="A"} 100`,
`bind_incoming_requests_total{name="QUERY"} 100`,
`bind_responses_total{result="Success"} 100`,
`bind_resolver_response_errors_total{error="FORMERR",view="_bind"} 0`,
`bind_resolver_response_errors_total{error="FORMERR",view="_default"} 0`,
`bind_resolver_response_errors_total{error="NXDOMAIN",view="_bind"} 0`,
`bind_resolver_response_errors_total{error="NXDOMAIN",view="_default"} 0`,
`bind_resolver_response_errors_total{error="OtherError",view="_bind"} 0`,
`bind_resolver_response_errors_total{error="OtherError",view="_default"} 0`,
`bind_resolver_response_errors_total{error="SERVFAIL",view="_bind"} 0`,
`bind_resolver_response_errors_total{error="SERVFAIL",view="_default"} 0`,
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "fixtures/v2.xml")
}))
defer ts.Close()
o, err := collect(NewExporter(ts.URL, 100*time.Millisecond))
if err != nil {
t.Fatal(err)
}
for _, test := range tests {
if !bytes.Contains(o, []byte(test)) {
t.Errorf("expected to find %q", string(test))
}
}
}
func collect(c prometheus.Collector) ([]byte, error) {
r := prometheus.NewRegistry()
if err := r.Register(c); err != nil {
return nil, err
}
m, err := r.Gather()
if err != nil {
return nil, err
}
var b bytes.Buffer
enc := expfmt.NewEncoder(&b, expfmt.FmtText)
for _, f := range m {
if err := enc.Encode(f); err != nil {
return nil, err
}
}
return b.Bytes(), nil
}
View

This file was deleted.

Oops, something went wrong.
File renamed without changes.

0 comments on commit 9e8b7a0

Please sign in to comment.