|
| 1 | +use bson::{doc, Bson}; |
| 2 | + |
| 3 | +use crate::hello::HelloCommandResponse; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn parse_connection_id() { |
| 7 | + let mut parsed: HelloCommandResponse = bson::from_document(doc! { |
| 8 | + "connectionId": Bson::Int32(42), |
| 9 | + "maxBsonObjectSize": 0, |
| 10 | + "maxMessageSizeBytes": 0, |
| 11 | + }) |
| 12 | + .unwrap(); |
| 13 | + assert_eq!(parsed.connection_id, Some(42)); |
| 14 | + |
| 15 | + parsed = bson::from_document(doc! { |
| 16 | + "connectionId": Bson::Int64(13), |
| 17 | + "maxBsonObjectSize": 0, |
| 18 | + "maxMessageSizeBytes": 0, |
| 19 | + }) |
| 20 | + .unwrap(); |
| 21 | + assert_eq!(parsed.connection_id, Some(13)); |
| 22 | + |
| 23 | + parsed = bson::from_document(doc! { |
| 24 | + "connectionId": Bson::Double(1066.0), |
| 25 | + "maxBsonObjectSize": 0, |
| 26 | + "maxMessageSizeBytes": 0, |
| 27 | + }) |
| 28 | + .unwrap(); |
| 29 | + assert_eq!(parsed.connection_id, Some(1066)); |
| 30 | + |
| 31 | + parsed = bson::from_document(doc! { |
| 32 | + "maxBsonObjectSize": 0, |
| 33 | + "maxMessageSizeBytes": 0, |
| 34 | + }) |
| 35 | + .unwrap(); |
| 36 | + assert_eq!(parsed.connection_id, None); |
| 37 | +} |
0 commit comments