|
1 | | -use std::{borrow::Borrow, collections::HashMap}; |
| 1 | +use std::borrow::Borrow; |
2 | 2 |
|
3 | 3 | use crate::{ |
4 | 4 | bolt::{ExpectedResponse, Summary}, |
5 | 5 | Version, |
6 | 6 | }; |
7 | | -use serde::{ser::SerializeMap, Deserialize, Serialize}; |
| 7 | +use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize}; |
8 | 8 |
|
9 | 9 | #[derive(Debug, Clone, PartialEq, Eq)] |
10 | 10 | pub struct Hello<'a> { |
@@ -119,6 +119,13 @@ impl Serialize for ServerRouting<'_> { |
119 | 119 | pub struct Response { |
120 | 120 | pub(crate) server: String, |
121 | 121 | pub(crate) connection_id: String, |
| 122 | + pub(crate) hints: Option<ConnectionsHints>, |
| 123 | +} |
| 124 | + |
| 125 | +#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] |
| 126 | +pub struct ConnectionsHints { |
| 127 | + #[serde(rename = "connection.recv_timeout_seconds")] |
| 128 | + connection_recv_timeout_seconds: Option<u32>, |
122 | 129 | } |
123 | 130 |
|
124 | 131 | impl ExpectedResponse for Hello<'_> { |
@@ -255,4 +262,33 @@ mod tests { |
255 | 262 | assert_eq!(response.server, "Neo4j/4.1.4"); |
256 | 263 | assert_eq!(response.connection_id, "bolt-31"); |
257 | 264 | } |
| 265 | + |
| 266 | + #[test] |
| 267 | + fn parse_with_hints() { |
| 268 | + let data = bolt() |
| 269 | + .tiny_map(3) |
| 270 | + .tiny_string("server") |
| 271 | + .tiny_string("Neo4j/4.1.4") |
| 272 | + .tiny_string("connection_id") |
| 273 | + .tiny_string("bolt-31") |
| 274 | + .tiny_string("hints") |
| 275 | + .tiny_map(1) |
| 276 | + .string8("connection.recv_timeout_seconds") |
| 277 | + .tiny_int(120) |
| 278 | + .build(); |
| 279 | + |
| 280 | + let response = Response::parse(data).unwrap(); |
| 281 | + |
| 282 | + assert_eq!(response.server, "Neo4j/4.1.4"); |
| 283 | + assert_eq!(response.connection_id, "bolt-31"); |
| 284 | + assert!(response.hints.is_some()); |
| 285 | + assert_eq!( |
| 286 | + response |
| 287 | + .hints |
| 288 | + .unwrap() |
| 289 | + .connection_recv_timeout_seconds |
| 290 | + .unwrap(), |
| 291 | + 120 |
| 292 | + ); |
| 293 | + } |
258 | 294 | } |
0 commit comments