Skip to content

Commit a74f174

Browse files
gakonstampcode-com
andcommitted
test: add config parsing tests for clickhouse failover_urls
Amp-Thread-ID: https://ampcode.com/threads/T-019c2ff6-d0a1-76c0-b130-595e2412a456 Co-authored-by: Amp <amp@ampcode.com>
1 parent 07d3c7e commit a74f174

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

src/config.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,54 @@ mod tests {
308308
assert_eq!(config.window_secs, 60);
309309
assert_eq!(config.max_sse_connections, 5);
310310
}
311+
312+
#[test]
313+
fn test_clickhouse_config_with_failover() {
314+
let toml_str = r#"
315+
name = "test"
316+
chain_id = 1
317+
rpc_url = "http://localhost:8545"
318+
pg_url = "postgres://localhost/test"
319+
320+
[clickhouse]
321+
enabled = true
322+
url = "http://clickhouse-1:8123"
323+
failover_urls = ["http://clickhouse-2:8123", "http://clickhouse-3:8123"]
324+
"#;
325+
326+
let config: ChainConfig = toml::from_str(toml_str).unwrap();
327+
let ch = config.clickhouse.unwrap();
328+
329+
assert!(ch.enabled);
330+
assert_eq!(ch.url, "http://clickhouse-1:8123");
331+
assert_eq!(ch.failover_urls.len(), 2);
332+
assert_eq!(
333+
ch.all_urls(),
334+
vec![
335+
"http://clickhouse-1:8123",
336+
"http://clickhouse-2:8123",
337+
"http://clickhouse-3:8123",
338+
]
339+
);
340+
}
341+
342+
#[test]
343+
fn test_clickhouse_config_without_failover() {
344+
let toml_str = r#"
345+
name = "test"
346+
chain_id = 1
347+
rpc_url = "http://localhost:8545"
348+
pg_url = "postgres://localhost/test"
349+
350+
[clickhouse]
351+
enabled = true
352+
url = "http://clickhouse:8123"
353+
"#;
354+
355+
let config: ChainConfig = toml::from_str(toml_str).unwrap();
356+
let ch = config.clickhouse.unwrap();
357+
358+
assert!(ch.failover_urls.is_empty());
359+
assert_eq!(ch.all_urls(), vec!["http://clickhouse:8123"]);
360+
}
311361
}

0 commit comments

Comments
 (0)