Chore: Update test database initialization (#81673)

* streamline initialization of test databases, support on-disk sqlite test db

* clean up test databases

* introduce testsuite helper

* use testsuite everywhere we use a test db

* update documentation

* improve error handling

* disable entity integration test until we can figure out locking error
This commit is contained in:
Dan Cech
2024-02-09 09:35:39 -05:00
committed by GitHub
parent de4acb27ce
commit 790e1feb93
104 changed files with 801 additions and 189 deletions
@@ -27,9 +27,14 @@ import (
secretskvs "github.com/grafana/grafana/pkg/services/secrets/kvstore"
secretsmng "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/tests/testsuite"
"github.com/grafana/grafana/pkg/tsdb/legacydata"
)
func TestMain(m *testing.M) {
testsuite.Run(m)
}
func TestHandleRequest(t *testing.T) {
t.Run("Should invoke plugin manager QueryData when handling request for query", func(t *testing.T) {
client := &fakePluginsClient{}
+11 -5
View File
@@ -5,7 +5,7 @@ import (
"database/sql"
"fmt"
"math/rand"
"strings"
"os"
"testing"
"time"
@@ -15,7 +15,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/services/sqlstore/sqlutil"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb/sqleng"
)
@@ -1475,9 +1474,16 @@ func TestGenerateConnectionString(t *testing.T) {
func initMSSQLTestDB(t *testing.T, jsonData sqleng.JsonData) *sql.DB {
t.Helper()
testDB := sqlutil.MSSQLTestDB()
db, err := sql.Open(testDB.DriverName, strings.Replace(testDB.ConnStr, "localhost",
serverIP, 1))
host := os.Getenv("MSSQL_HOST")
if host == "" {
host = serverIP
}
port := os.Getenv("MSSQL_PORT")
if port == "" {
port = "1433"
}
db, err := sql.Open("mssql", fmt.Sprintf("server=%s;port=%s;database=grafanatest;user id=grafana;password=Password!", host, port))
require.NoError(t, err)
db.SetMaxOpenConns(jsonData.MaxOpenConns)