#![allow(clippy::unwrap_used)]
use super::*;
#[test]
fn test_adapter_creation() {
let adapter = FraiseWireAdapter::new("postgres://localhost/test");
assert_eq!(adapter.database_type(), DatabaseType::PostgreSQL);
assert_eq!(adapter.chunk_size, 1024);
}
#[test]
fn test_adapter_with_chunk_size() {
let adapter = FraiseWireAdapter::new("postgres://localhost/test").with_chunk_size(512);
assert_eq!(adapter.chunk_size, 512);
}
#[test]
fn test_pool_metrics() {
let adapter = FraiseWireAdapter::new("postgres://localhost/test");
let metrics = adapter.pool_metrics();
assert_eq!(metrics.total_connections, 0);
assert_eq!(metrics.idle_connections, 0);
assert_eq!(metrics.active_connections, 0);
assert_eq!(metrics.waiting_requests, 0);
}
#[test]
fn a_relevance_ordering_is_refused_rather_than_escaped() {
let clause = OrderByClause::by_relevance(crate::types::sql_hints::RelevanceOrder {
fields: vec!["label".to_string()],
query: "'; DROP TABLE users; --".to_string(),
});
let err = order_by_columns(Some(&[clause])).unwrap_err().to_string();
assert!(err.contains("cannot supply"), "got: {err}");
assert!(!err.contains("DROP TABLE"), "the refusal must not echo the search text: {err}");
let plain = OrderByClause::new("createdAt".to_string(), crate::OrderDirection::Desc);
assert_eq!(
order_by_columns(Some(&[plain])).unwrap().unwrap(),
"data->>'created_at' DESC, data->>'id' ASC"
);
}
#[test]
fn it_does_not_claim_composed_reads() {
assert!(!FraiseWireAdapter::new("postgres://localhost/test").supports_composed_reads());
}