init and ping testdb

This commit is contained in:
Warren Gifford 2024-07-19 14:14:08 -07:00
parent 208c5daf9f
commit 8872541c2a
2 changed files with 19 additions and 1 deletions

View File

@ -23,5 +23,8 @@ go_test(
srcs = ["util_test.go"],
embed = [":upgrades"],
tags = ["requires-network"],
deps = ["//internal/observation"],
deps = [
"//internal/database/dbtest",
"//internal/observation",
],
)

View File

@ -4,6 +4,7 @@ import (
"os"
"testing"
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
"github.com/sourcegraph/sourcegraph/internal/observation"
)
@ -95,8 +96,22 @@ func TestCheckConnection_Ping(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
db := dbtest.NewDB(t)
defer db.Close()
var dbName string
err := db.QueryRow("SELECT current_database()").Scan(&dbName)
if err != nil {
t.Errorf("unexpected error: %v", err)
t.FailNow()
}
t.Setenv("CODEINTEL_PG_ALLOW_SINGLE_DB", "true")
t.Setenv("PGUSER", "sourcegraph")
t.Setenv("PGPASSWORD", "sourcegraph")
t.Setenv("PGDATABASE", dbName)
t.Setenv("PGSSLMODE", "disable")
t.Setenv("PGTZ", "UTC")
dsns, err := getApplianceDSNs()
if err != nil {