|
| 1 | +use qdrant_client::config::{CompressionEncoding, QdrantConfig}; |
| 2 | + |
| 3 | +#[test] |
| 4 | +fn header_adds_single_header() { |
| 5 | + let config = QdrantConfig::from_url("http://localhost:6334").header("x-custom-id", "my-client"); |
| 6 | + |
| 7 | + assert_eq!( |
| 8 | + config.custom_headers, |
| 9 | + vec![("x-custom-id".to_string(), "my-client".to_string())] |
| 10 | + ); |
| 11 | +} |
| 12 | + |
| 13 | +#[test] |
| 14 | +fn header_chain_preserves_order() { |
| 15 | + let config = QdrantConfig::from_url("http://localhost:6334") |
| 16 | + .header("x-a", "1") |
| 17 | + .header("x-b", "2") |
| 18 | + .header("x-a", "3"); |
| 19 | + |
| 20 | + assert_eq!( |
| 21 | + config.custom_headers, |
| 22 | + vec![ |
| 23 | + ("x-a".to_string(), "1".to_string()), |
| 24 | + ("x-b".to_string(), "2".to_string()), |
| 25 | + ("x-a".to_string(), "3".to_string()), |
| 26 | + ] |
| 27 | + ); |
| 28 | +} |
| 29 | + |
| 30 | +#[test] |
| 31 | +fn header_allows_duplicate_keys() { |
| 32 | + let config = QdrantConfig::from_url("http://localhost:6334") |
| 33 | + .header("openai-api-key", "k1") |
| 34 | + .header("openai-api-key", "k2"); |
| 35 | + |
| 36 | + assert_eq!(config.custom_headers.len(), 2); |
| 37 | + assert_eq!( |
| 38 | + config.custom_headers, |
| 39 | + vec![ |
| 40 | + ("openai-api-key".to_string(), "k1".to_string()), |
| 41 | + ("openai-api-key".to_string(), "k2".to_string()), |
| 42 | + ] |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +#[test] |
| 47 | +fn header_does_not_mutate_other_config() { |
| 48 | + let base = QdrantConfig::from_url("http://localhost:6334") |
| 49 | + .api_key("secret") |
| 50 | + .timeout(10u64) |
| 51 | + .connect_timeout(20u64) |
| 52 | + .compression(Some(CompressionEncoding::Gzip)) |
| 53 | + .skip_compatibility_check(); |
| 54 | + |
| 55 | + let with_header = base.clone().header("x-feature", "on"); |
| 56 | + |
| 57 | + assert_eq!(with_header.uri, base.uri); |
| 58 | + assert_eq!(with_header.timeout, base.timeout); |
| 59 | + assert_eq!(with_header.connect_timeout, base.connect_timeout); |
| 60 | + assert_eq!( |
| 61 | + with_header.keep_alive_while_idle, |
| 62 | + base.keep_alive_while_idle |
| 63 | + ); |
| 64 | + assert_eq!(with_header.api_key, base.api_key); |
| 65 | + assert_eq!(with_header.compression, base.compression); |
| 66 | + assert_eq!(with_header.check_compatibility, base.check_compatibility); |
| 67 | + assert_eq!(with_header.pool_size, base.pool_size); |
| 68 | + |
| 69 | + assert_eq!( |
| 70 | + with_header.custom_headers, |
| 71 | + vec![("x-feature".to_string(), "on".to_string())] |
| 72 | + ); |
| 73 | + assert!(base.custom_headers.is_empty()); |
| 74 | +} |
0 commit comments