Skip to content

Commit 1fd030d

Browse files
committed
Add exporter GRANT to integration tests
Add a test of the GRANT statement to the exporter integration test. Fixes: #622 Signed-off-by: SuperQ <[email protected]>
1 parent ca1b9af commit 1fd030d

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Diff for: .circleci/config.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ jobs:
1818
file: mysqld_exporter
1919
integration:
2020
docker:
21-
- image: circleci/golang:1.17
21+
- image: cimg/go:1.17
2222
- image: << parameters.mysql_image >>
2323
environment:
2424
MYSQL_ALLOW_EMPTY_PASSWORD: yes
2525
MYSQL_ROOT_HOST: '%'
26+
DATA_SOURCE_NAME: 'exporter:integration-test@/'
2627
parameters:
2728
mysql_image:
2829
type: string
@@ -31,6 +32,8 @@ jobs:
3132
- setup_remote_docker
3233
- run: docker version
3334
- run: docker-compose --version
35+
- run: sudo apt-get install -y mysql-client
36+
- run: mysql < scripts/test_grant.sql
3437
- run: make build
3538
- run: make test
3639
codespell:

Diff for: collector/exporter_test.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ import (
2626
"github.com/smartystreets/goconvey/convey"
2727
)
2828

29-
const dsn = "root@/mysql"
29+
var testDSN = "root@/mysql"
30+
31+
func init() {
32+
testDSNEnv := os.Getenv("DATA_SOURCE_NAME")
33+
if testDSNEnv != ""
34+
testDSN = testDSNEnv
35+
}
36+
}
3037

3138
func TestExporter(t *testing.T) {
3239
if testing.Short() {
@@ -35,7 +42,7 @@ func TestExporter(t *testing.T) {
3542

3643
exporter := New(
3744
context.Background(),
38-
dsn,
45+
testDSN,
3946
NewMetrics(),
4047
[]Scraper{
4148
ScrapeGlobalStatus{},
@@ -79,7 +86,7 @@ func TestGetMySQLVersion(t *testing.T) {
7986
logger = level.NewFilter(logger, level.AllowDebug())
8087

8188
convey.Convey("Version parsing", t, func() {
82-
db, err := sql.Open("mysql", dsn)
89+
db, err := sql.Open("mysql", testDSN)
8390
convey.So(err, convey.ShouldBeNil)
8491
defer db.Close()
8592

Diff for: scripts/test_grant.sql

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'integration-test' WITH MAX_USER_CONNECTIONS 3;
2+
GRANT PROCESS, REPLICATION CLIENT TO 'exporter'@'localhost';
3+
GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
4+
GRANT SELECT ON information_schema.* TO 'exporter'@'localhost';
5+

0 commit comments

Comments
 (0)