MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / pgwire_ddl_roundtrip

Function pgwire_ddl_roundtrip

nodedb/tests/pgwire_auth_wire.rs:14–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12
13#[tokio::test]
14async fn pgwire_ddl_roundtrip() {
15 let state = make_state();
16
17 let pg_listener =
18 nodedb::control::server::pgwire::listener::PgListener::bind("127.0.0.1:0".parse().unwrap())
19 .await
20 .unwrap();
21 let port = pg_listener.local_addr().port();
22
23 let (shutdown_bus, _) =
24 nodedb::control::shutdown::ShutdownBus::new(Arc::clone(&state.shutdown));
25 let shared_pg = Arc::clone(&state);
26 let test_startup_gate = Arc::clone(&state.startup);
27 let bus_pg = shutdown_bus.clone();
28 tokio::spawn(async move {
29 pg_listener
30 .run(
31 shared_pg,
32 nodedb::config::auth::AuthMode::Trust,
33 None,
34 Arc::new(tokio::sync::Semaphore::new(128)),
35 test_startup_gate,
36 bus_pg,
37 )
38 .await
39 .unwrap();
40 });
41
42 tokio::time::sleep(std::time::Duration::from_millis(30)).await;
43
44 let conn_str = format!("host=127.0.0.1 port={port} user=nodedb dbname=nodedb");
45 let (client, connection) = tokio_postgres::connect(&conn_str, tokio_postgres::NoTls)
46 .await
47 .unwrap();
48 tokio::spawn(async move {
49 let _ = connection.await;
50 });
51
52 client
53 .simple_query("CREATE USER wire_test WITH PASSWORD 'pass'")
54 .await
55 .unwrap();
56
57 let msgs = client.simple_query("SHOW SESSION").await.unwrap();
58 let username = msgs.iter().find_map(|m| match m {
59 SimpleQueryMessage::Row(row) => row.get(0).map(|s| s.to_string()),
60 _ => None,
61 });
62 assert_eq!(username, Some("nodedb".to_string()));
63
64 assert!(state.credentials.get_user("wire_test").is_some());
65}

Callers

nothing calls this directly

Calls 9

to_stringMethod · 0.80
make_stateFunction · 0.70
spawnFunction · 0.50
parseMethod · 0.45
local_addrMethod · 0.45
cloneMethod · 0.45
runMethod · 0.45
iterMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected