fix(backend): secure production startup and migrations
This commit is contained in:
@@ -4,15 +4,14 @@ package search
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"senlinai-agent/backend/internal/models"
|
||||
"senlinai-agent/backend/internal/testutil"
|
||||
)
|
||||
|
||||
func TestPostgresSearchMatchesChinesePartialKeywords(t *testing.T) {
|
||||
@@ -111,13 +110,7 @@ func TestPostgresSearchUsesStableFairLimitAndRuneBoundedSnippets(t *testing.T) {
|
||||
|
||||
func newPostgresSearchTestDB(t *testing.T) *gorm.DB {
|
||||
t.Helper()
|
||||
dsn := os.Getenv("TEST_DATABASE_URL")
|
||||
require.NotEmpty(t, dsn, "TEST_DATABASE_URL is required for integration tests and must point to an isolated database")
|
||||
database, err := gorm.Open(postgres.Open(dsn), &gorm.Config{TranslateError: true})
|
||||
require.NoError(t, err)
|
||||
transaction := database.Begin()
|
||||
require.NoError(t, transaction.Error)
|
||||
t.Cleanup(func() { transaction.Rollback() })
|
||||
require.NoError(t, models.AutoMigrate(transaction))
|
||||
return transaction
|
||||
database := testutil.OpenIsolatedPostgres(t, &gorm.Config{TranslateError: true})
|
||||
require.NoError(t, models.AutoMigrate(database))
|
||||
return database
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user