Smail/backend/services/dbmigration/portable_connection_test.go
smail f68c367042
Some checks are pending
Security Checks / security (push) Waiting to run
实现三种数据库迁移并完善认证与迁移写入保护
2026-09-06 01:31:29 +08:00

35 lines
1.0 KiB
Go

package dbmigration
import (
"net/url"
"testing"
"git.pcux.cn/xuans/Smail/config"
"github.com/lib/pq"
)
func TestPortablePostgresUsesSupportedRuntimeTLSMode(t *testing.T) {
for _, name := range []string{"", "smail_next"} {
driver, dsn, err := runtimeSQLDSN(config.DatabaseConfig{
Type: config.DatabaseTypePostgreSQL, Host: "::1", Port: 5432, Username: "review",
}, "test-only-password", name)
if err != nil || driver != "postgres" {
t.Fatal("PostgreSQL connection was not built")
}
parsed, err := url.Parse(dsn)
if err != nil {
t.Fatal(err)
}
query := parsed.Query()
if query.Get("sslmode") != "require" || query.Get("timezone") != "UTC" || query.Get("search_path") != "public" {
t.Fatal("migration connection differs from supported runtime TLS or time settings")
}
if _, err := pq.NewConnector(dsn); err != nil {
t.Fatal("driver rejected generated connection parameters")
}
if name == "" && parsed.Path != "/postgres" {
t.Fatal("maintenance connection did not select postgres database")
}
}
}