mirror of
https://github.com/grafana/grafana.git
synced 2025-01-16 03:32:37 -06:00
mysql/postgres: vendor in unit-test helper function (#78744)
This commit is contained in:
parent
ce90a1f2be
commit
033446523b
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user