Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

2.0 KB
Raw Blame
use dbx_core::connection::{connection_configs_pool_equivalent, connection_configs_session_credentials_compatible};
use dbx_core::models::connection::ConnectionConfig;

#[test]
fn sidebar_visibility_preserves_sessions_without_ignoring_target_changes() {
    let base: ConnectionConfig = serde_json::from_value(serde_json::json!({
        "id": "sidebar", "name": "Sidebar", "db_type": "oracle", "host": "localhost",
        "port": 1521, "username": "test", "password": "", "save_password": false
    }))
    .unwrap();
    for field in ["show_database_links", "show_native_jobs", "show_user_admin"] {
        for before in [None, Some(true), Some(false)] {
            for after in [None, Some(true), Some(false)] {
                let set = |config: &mut ConnectionConfig, value| match field {
                    "show_database_links" => config.show_database_links = value,
                    "show_native_jobs" => config.show_native_jobs = value,
                    _ => config.show_user_admin = value,
                };
                let mut initial = base.clone();
                let mut edited = base.clone();
                set(&mut initial, before);
                set(&mut edited, after);
                assert!(connection_configs_pool_equivalent(&initial, &edited));
                assert!(connection_configs_session_credentials_compatible(&initial, &edited));

                for target in ["host", "username", "tls"] {
                    let mut changed_target = edited.clone();
                    match target {
                        "host" => changed_target.host = "other.example.test".into(),
                        "username" => changed_target.username = "other-user".into(),
                        _ => changed_target.ssl = !initial.ssl,
                    }
                    assert!(!connection_configs_pool_equivalent(&initial, &changed_target));
                    assert!(!connection_configs_session_credentials_compatible(&initial, &changed_target));
                }
            }
        }
    }
}