Commit ef9ebd01 authored by Alexey Palazhchenko's avatar Alexey Palazhchenko Committed by Ben Kochie

Add Docker Compose for integration tests (#228)

* Add Docker Compose for integration tests.

Closes #223.

* Add very basic integration test as an example.

* Remove `-v`.

* Remove duplicate line.
parent a3a0fc31
sudo: false
dist: trusty
sudo: required
language: go
go:
- 1.8.x
- tip
env:
- MYSQL_IMAGE=mysql/mysql-server:5.5
- MYSQL_IMAGE=mysql/mysql-server:5.6
- MYSQL_IMAGE=mysql/mysql-server:5.7
- MYSQL_IMAGE=mysql/mysql-server:8.0
services:
- docker
go_import_path: github.com/prometheus/mysqld_exporter
before_script:
- sudo service mysql stop
- docker --version
- docker-compose --version
- docker-compose up -d
script:
- make
- make test
......@@ -16,3 +16,14 @@ Prometheus uses GitHub to manage reviews of pull requests.
and the _Formatting and style_ section of Peter Bourgon's [Go: Best
Practices for Production
Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style).
## Local setup
The easiest way to make a local development setup is to use Docker Compose.
```
docker-compose up
make
make test
```
......@@ -22,15 +22,19 @@ DOCKER_IMAGE_NAME ?= mysqld-exporter
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
all: format build test
all: format build test-short
style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
test-short:
@echo ">> running short tests"
@$(GO) test -short -race $(pkgs)
test:
@echo ">> running tests"
@$(GO) test -short -race $(pkgs)
@$(GO) test -race $(pkgs)
format:
@echo ">> formatting code"
......
package collector
import (
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/smartystreets/goconvey/convey"
)
const dsn = "root@/mysql"
func TestExporter(t *testing.T) {
if testing.Short() {
t.Skip("-short is passed, skipping test")
}
exporter := New(dsn, Collect{
GlobalStatus: true,
})
convey.Convey("Metrics describing", t, func() {
ch := make(chan *prometheus.Desc)
go func() {
exporter.Describe(ch)
close(ch)
}()
for range ch {
}
})
convey.Convey("Metrics collection", t, func() {
ch := make(chan prometheus.Metric)
go func() {
exporter.Collect(ch)
close(ch)
}()
for m := range ch {
got := readMetric(m)
if got.labels[model.MetricNameLabel] == "mysql_up" {
convey.So(got.value, convey.ShouldEqual, 1)
}
}
})
}
# see CONTRIBUTING.md
---
version: '3'
services:
mysql:
image: ${MYSQL_IMAGE:-mysql/mysql-server:5.7}
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_ROOT_HOST=%
ports:
- 127.0.0.1:3306:3306
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment