Skip to content

Commit 33038e2

Browse files
committed
test: add config parser unit test
1 parent 648147e commit 33038e2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/config.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,27 @@ pub fn load_config(path: &str) -> GatewayConfig {
2121
file.read_to_string(&mut contents).unwrap();
2222
toml::from_str(&contents).unwrap()
2323
}
24+
25+
#[cfg(test)]
26+
mod tests {
27+
use super::*;
28+
29+
#[test]
30+
fn parses_config() -> Result<(), std::io::Error> {
31+
let config = load_config("./tests/test_config.toml");
32+
let test_service = config
33+
.services
34+
.get("test-service")
35+
.expect("test service not found");
36+
37+
assert_eq!(config.auth_url, "https://example.com");
38+
assert_eq!(test_service.path, "/testservice");
39+
assert_eq!(
40+
test_service.target_host,
41+
"https://my-service.default.svc.cluster.local"
42+
);
43+
assert_eq!(test_service.target_port, 8080);
44+
45+
Ok(())
46+
}
47+
}

tests/test_config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
auth_url="https://example.com"
2+
3+
[services.test-service]
4+
path="/testservice"
5+
target_host="https://my-service.default.svc.cluster.local"
6+
target_port=8080

0 commit comments

Comments
 (0)