()
| 76 | |
| 77 | #[tokio::test] |
| 78 | async fn test_pg_class_queries() { |
| 79 | // Create a test database handler with temporary file |
| 80 | let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos(); |
| 81 | let db_path = format!("/tmp/catalog_test_pg_class_{timestamp}.db"); |
| 82 | let db = Arc::new(DbHandler::new(&db_path).unwrap()); |
| 83 | |
| 84 | // Create a session |
| 85 | let session = Arc::new(SessionState::new("test_user".to_string(), "test_db".to_string())); |
| 86 | |
| 87 | // Create a connection for the session |
| 88 | db.create_session_connection(session.id).await.unwrap(); |
| 89 | |
| 90 | // Create a test table in the session |
| 91 | db.execute_with_session("CREATE TABLE test_table (id INTEGER PRIMARY KEY, name TEXT)", &session.id).await.unwrap(); |
| 92 | |
| 93 | // Test pg_class query |
| 94 | let query = "SELECT relname, relkind FROM pg_catalog.pg_class"; |
| 95 | let result = CatalogInterceptor::intercept_query(query, db.clone(), Some(session.clone())).await; |
| 96 | assert!(result.is_some()); |
| 97 | |
| 98 | let response = result.unwrap().unwrap(); |
| 99 | // Now we properly implement column projection |
| 100 | assert_eq!(response.columns, vec!["relname", "relkind"]); |
| 101 | assert_eq!(response.columns.len(), 2); |
| 102 | |
| 103 | // Find our test table |
| 104 | let mut found_table = false; |
| 105 | for row in &response.rows { |
| 106 | assert_eq!(row.len(), 2, "Should only have 2 columns"); |
| 107 | if let Some(Some(name_bytes)) = row.first() { // relname is at index 0 now |
| 108 | let name = String::from_utf8_lossy(name_bytes); |
| 109 | if name == "test_table" { |
| 110 | found_table = true; |
| 111 | // Check relkind is 'r' for regular table |
| 112 | if let Some(Some(kind_bytes)) = row.get(1) { // relkind is at index 1 now |
| 113 | assert_eq!(kind_bytes, b"r"); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | assert!(found_table, "test_table should be in pg_class"); |
| 119 | |
| 120 | // Cleanup |
| 121 | let _ = std::fs::remove_file(&db_path); |
| 122 | let _ = std::fs::remove_file(format!("{db_path}-wal")); |
| 123 | let _ = std::fs::remove_file(format!("{db_path}-shm")); |
| 124 | } |
| 125 | |
| 126 | #[tokio::test] |
| 127 | async fn test_pg_attribute_queries() { |
nothing calls this directly
no test coverage detected