Skip to content

Commit

Permalink
Add exporter GRANT to integration tests
Browse files Browse the repository at this point in the history
Add a test of the GRANT statement to the exporter integration test.

Fixes: #622

Signed-off-by: SuperQ <[email protected]>
  • Loading branch information
SuperQ committed Mar 5, 2022
1 parent ca1b9af commit ac7bfc8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
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';

0 comments on commit ac7bfc8

Please sign in to comment.