mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-12 00:49:42 +08:00
- PostgreSQL 空 database 时按 postgres、template1、用户名同名库回退连接 - 移除后端对 database=postgres 的硬编码写死逻辑 - 连接弹窗新增 PostgreSQL 默认连接数据库(可选)配置项 - refs #120
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package db
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
)
|
|
|
|
func TestResolvePostgresConnectDatabases_ExplicitDatabase(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{
|
|
Type: "postgres",
|
|
Database: "analytics",
|
|
User: "app_user",
|
|
}
|
|
|
|
got := resolvePostgresConnectDatabases(cfg)
|
|
want := []string{"analytics"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("unexpected databases, got=%v want=%v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestResolvePostgresConnectDatabases_FallbackOrder(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{
|
|
Type: "postgres",
|
|
User: "app_user",
|
|
}
|
|
|
|
got := resolvePostgresConnectDatabases(cfg)
|
|
want := []string{"postgres", "template1", "app_user"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("unexpected databases, got=%v want=%v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestResolvePostgresConnectDatabases_DeduplicateUserDefault(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{
|
|
Type: "postgres",
|
|
User: "postgres",
|
|
}
|
|
|
|
got := resolvePostgresConnectDatabases(cfg)
|
|
want := []string{"postgres", "template1"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("unexpected databases, got=%v want=%v", got, want)
|
|
}
|
|
}
|