mirror of
https://github.com/prometheus/mysqld_exporter.git
synced 2025-04-18 09:24:02 +03:00
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.
This commit is contained in:
parent
a3a0fc3187
commit
ef9ebd0185
21
.travis.yml
21
.travis.yml
@ -1,11 +1,28 @@
|
||||
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
|
||||
```
|
||||
|
8
Makefile
8
Makefile
@ -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"
|
||||
|
47
collector/exporter_test.go
Normal file
47
collector/exporter_test.go
Normal file
@ -0,0 +1,47 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
11
docker-compose.yml
Normal file
11
docker-compose.yml
Normal file
@ -0,0 +1,11 @@
|
||||
# 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
|
Loading…
x
Reference in New Issue
Block a user