Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ jobs:
file: mysqld_exporter
integration:
docker:
- image: circleci/golang:1.17
- image: cimg/go:1.17
- image: << parameters.mysql_image >>
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_ROOT_HOST: '%'
DATA_SOURCE_NAME: 'exporter:integration-test@/'
parameters:
mysql_image:
type: string
Expand All @@ -31,6 +32,8 @@ jobs:
- setup_remote_docker
- run: docker version
- run: docker-compose --version
- run: sudo apt-get install -y mysql-client
- run: mysql < scripts/test_grant.sql
- run: make build
- run: make test
codespell:
Expand Down
13 changes: 10 additions & 3 deletions collector/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ import (
"github.com/smartystreets/goconvey/convey"
)

const dsn = "root@/mysql"
var testDSN = "root@/mysql"

func init() {
testDSNEnv := os.Getenv("DATA_SOURCE_NAME")
if testDSNEnv != ""
testDSN = testDSNEnv
}
}

func TestExporter(t *testing.T) {
if testing.Short() {
Expand All @@ -35,7 +42,7 @@ func TestExporter(t *testing.T) {

exporter := New(
context.Background(),
dsn,
testDSN,
NewMetrics(),
[]Scraper{
ScrapeGlobalStatus{},
Expand Down Expand Up @@ -79,7 +86,7 @@ func TestGetMySQLVersion(t *testing.T) {
logger = level.NewFilter(logger, level.AllowDebug())

convey.Convey("Version parsing", t, func() {
db, err := sql.Open("mysql", dsn)
db, err := sql.Open("mysql", testDSN)
convey.So(err, convey.ShouldBeNil)
defer db.Close()

Expand Down
5 changes: 5 additions & 0 deletions scripts/test_grant.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'integration-test' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT TO 'exporter'@'localhost';
GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
GRANT SELECT ON information_schema.* TO 'exporter'@'localhost';