diff --git a/.circleci/config.yml b/.circleci/config.yml index 69c12a79..23df0b60 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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: diff --git a/collector/exporter_test.go b/collector/exporter_test.go index 07ceea78..dbd0f0bd 100644 --- a/collector/exporter_test.go +++ b/collector/exporter_test.go @@ -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() { @@ -35,7 +42,7 @@ func TestExporter(t *testing.T) { exporter := New( context.Background(), - dsn, + testDSN, NewMetrics(), []Scraper{ ScrapeGlobalStatus{}, @@ -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() diff --git a/scripts/test_grant.sql b/scripts/test_grant.sql new file mode 100644 index 00000000..7543bda5 --- /dev/null +++ b/scripts/test_grant.sql @@ -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'; +