diff --git a/pkg/tsdb/grafana-postgresql-datasource/postgres_test.go b/pkg/tsdb/grafana-postgresql-datasource/postgres_test.go index 01b89f9d17c..1cc5a6b13e8 100644 --- a/pkg/tsdb/grafana-postgresql-datasource/postgres_test.go +++ b/pkg/tsdb/grafana-postgresql-datasource/postgres_test.go @@ -15,7 +15,6 @@ import ( "github.com/stretchr/testify/require" "xorm.io/xorm" - "github.com/grafana/grafana/pkg/services/sqlstore/sqlutil" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/sqleng" @@ -1394,9 +1393,8 @@ func TestIntegrationPostgres(t *testing.T) { } func InitPostgresTestDB(t *testing.T) *xorm.Engine { - testDB := sqlutil.PostgresTestDB() - x, err := xorm.NewEngine(testDB.DriverName, strings.Replace(testDB.ConnStr, "dbname=grafanatest", - "dbname=grafanadstest", 1)) + connStr := postgresTestDBConnString() + x, err := xorm.NewEngine("postgres", connStr) require.NoError(t, err, "Failed to init postgres DB") x.DatabaseTZ = time.UTC @@ -1435,3 +1433,16 @@ func isTestDbPostgres() bool { return false } + +func postgresTestDBConnString() string { + host := os.Getenv("POSTGRES_HOST") + if host == "" { + host = "localhost" + } + port := os.Getenv("POSTGRES_PORT") + if port == "" { + port = "5432" + } + return fmt.Sprintf("user=grafanatest password=grafanatest host=%s port=%s dbname=grafanadstest sslmode=disable", + host, port) +} diff --git a/pkg/tsdb/mysql/mysql_test.go b/pkg/tsdb/mysql/mysql_test.go index 8e776ac0672..f64e51e2efb 100644 --- a/pkg/tsdb/mysql/mysql_test.go +++ b/pkg/tsdb/mysql/mysql_test.go @@ -5,7 +5,6 @@ import ( "fmt" "math/rand" "os" - "strings" "testing" "time" @@ -14,7 +13,6 @@ import ( "github.com/stretchr/testify/require" "xorm.io/xorm" - "github.com/grafana/grafana/pkg/services/sqlstore/sqlutil" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/sqleng" ) @@ -1294,9 +1292,8 @@ func TestIntegrationMySQL(t *testing.T) { } func InitMySQLTestDB(t *testing.T) *xorm.Engine { - testDB := sqlutil.MySQLTestDB() - x, err := xorm.NewEngine(testDB.DriverName, strings.Replace(testDB.ConnStr, "/grafana_tests", - "/grafana_ds_tests", 1)+"&parseTime=true&loc=UTC") + connStr := mySQLTestDBConnStr() + x, err := xorm.NewEngine("mysql", connStr) if err != nil { t.Fatalf("Failed to init mysql db %v", err) } @@ -1329,3 +1326,15 @@ func isTestDbMySQL() bool { return false } + +func mySQLTestDBConnStr() string { + host := os.Getenv("MYSQL_HOST") + if host == "" { + host = "localhost" + } + port := os.Getenv("MYSQL_PORT") + if port == "" { + port = "3306" + } + return fmt.Sprintf("grafana:password@tcp(%s:%s)/grafana_ds_tests?collation=utf8mb4_unicode_ci&sql_mode='ANSI_QUOTES'&parseTime=true&loc=UTC", host, port) +}