MCPcopy Create free account
hub / github.com/erans/pgsqlite / test_pg_stats_view_exists

Function test_pg_stats_view_exists

tests/pg_stats_test.rs:6–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5#[tokio::test]
6async fn test_pg_stats_view_exists() {
7 // Create a temporary database
8 let temp_dir = tempfile::tempdir().unwrap();
9 let db_path = temp_dir.path().join("test_pg_stats.db");
10 let db_handler = Arc::new(DbHandler::new(db_path.to_str().unwrap()).unwrap());
11
12 // Create session for catalog queries
13 let session_id = Uuid::new_v4();
14 db_handler.create_session_connection(session_id).await.unwrap();
15
16 // Create a sample table with data for statistics
17 db_handler.execute("CREATE TABLE sample_table (
18 id INTEGER PRIMARY KEY,
19 name VARCHAR(50),
20 age INTEGER,
21 email TEXT,
22 status VARCHAR(20) DEFAULT 'active',
23 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
24 is_verified BOOLEAN DEFAULT FALSE
25 )").await.unwrap();
26
27 // Insert some sample data
28 db_handler.execute("INSERT INTO sample_table (name, age, email, status, is_verified) VALUES
29 ('Alice Johnson', 25, 'alice@example.com', 'active', 1),
30 ('Bob Smith', 30, 'bob@example.com', 'inactive', 0),
31 ('Carol Davis', 28, 'carol@example.com', 'active', 1),
32 ('David Wilson', 35, 'david@example.com', 'pending', 0),
33 ('Eve Brown', 22, 'eve@example.com', 'active', 1)
34 ").await.unwrap();
35
36 // Test basic pg_stats view query
37 let result = db_handler.query_with_session("SELECT COUNT(*) FROM pg_stats", &session_id).await.unwrap();
38 assert!(!result.rows.is_empty(), "Should get a count result");
39
40 let count_bytes = result.rows[0][0].as_ref().unwrap();
41 let count_str = String::from_utf8(count_bytes.clone()).unwrap();
42 let count: i32 = count_str.parse().unwrap();
43
44 // Should have statistics for all columns in our sample table (7 columns)
45 assert!(count >= 7, "Should have statistics for at least 7 columns, got {}", count);
46 println!("✅ pg_stats view contains {} column statistics", count);
47}
48
49#[tokio::test]
50async fn test_pg_stats_column_structure() {

Callers

nothing calls this directly

Calls 4

query_with_sessionMethod · 0.80
executeMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected