mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-12 16:02:48 +08:00
🐛 fix(data-sync): 修复已保存连接同步时未恢复密文
- Data Sync 分析/预览/同步入口统一恢复源库和目标库连接密文 - 避免已保存 PostgreSQL 连接因空密码触发 28P01 - 保留前端选择的源/目标数据库覆盖值 - 增加保存连接密文恢复回归测试 Refs #413
This commit is contained in:
78
internal/app/methods_sync_test.go
Normal file
78
internal/app/methods_sync_test.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"GoNavi-Wails/internal/connection"
|
||||
datasync "GoNavi-Wails/internal/sync"
|
||||
)
|
||||
|
||||
func TestResolveDataSyncConfigSecretsRestoresSavedSourceAndTargetPasswords(t *testing.T) {
|
||||
app := NewAppWithSecretStore(newFakeAppSecretStore())
|
||||
app.configDir = t.TempDir()
|
||||
|
||||
_, err := app.SaveConnection(connection.SavedConnectionInput{
|
||||
ID: "source-pg",
|
||||
Name: "Source PostgreSQL",
|
||||
Config: connection.ConnectionConfig{
|
||||
ID: "source-pg",
|
||||
Type: "postgres",
|
||||
Host: "source.local",
|
||||
Port: 5432,
|
||||
User: "postgres",
|
||||
Password: "source-secret",
|
||||
Database: "schedule",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("SaveConnection source returned error: %v", err)
|
||||
}
|
||||
_, err = app.SaveConnection(connection.SavedConnectionInput{
|
||||
ID: "target-pg",
|
||||
Name: "Target PostgreSQL",
|
||||
Config: connection.ConnectionConfig{
|
||||
ID: "target-pg",
|
||||
Type: "postgres",
|
||||
Host: "target.local",
|
||||
Port: 5432,
|
||||
User: "postgres",
|
||||
Password: "target-secret",
|
||||
Database: "warehouse",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("SaveConnection target returned error: %v", err)
|
||||
}
|
||||
|
||||
resolved, err := app.resolveDataSyncConfigSecrets(datasync.SyncConfig{
|
||||
SourceConfig: connection.ConnectionConfig{
|
||||
ID: "source-pg",
|
||||
Type: "postgres",
|
||||
Host: "source.local",
|
||||
Port: 5432,
|
||||
User: "postgres",
|
||||
Database: "schedule",
|
||||
},
|
||||
TargetConfig: connection.ConnectionConfig{
|
||||
ID: "target-pg",
|
||||
Type: "postgres",
|
||||
Host: "target.local",
|
||||
Port: 5432,
|
||||
User: "postgres",
|
||||
Database: "warehouse",
|
||||
},
|
||||
Tables: []string{"jobs"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("resolveDataSyncConfigSecrets returned error: %v", err)
|
||||
}
|
||||
if resolved.SourceConfig.Password != "source-secret" {
|
||||
t.Fatalf("expected source password to be restored, got %q", resolved.SourceConfig.Password)
|
||||
}
|
||||
if resolved.TargetConfig.Password != "target-secret" {
|
||||
t.Fatalf("expected target password to be restored, got %q", resolved.TargetConfig.Password)
|
||||
}
|
||||
if resolved.SourceConfig.Database != "schedule" || resolved.TargetConfig.Database != "warehouse" {
|
||||
t.Fatalf("expected selected databases to be preserved, got source=%q target=%q", resolved.SourceConfig.Database, resolved.TargetConfig.Database)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user