From 33038e26790e960b5cef2fe4106f40eb0a851fa4 Mon Sep 17 00:00:00 2001 From: zenlex Date: Sat, 9 Mar 2024 22:15:36 -0600 Subject: [PATCH] test: add config parser unit test --- src/config.rs | 24 ++++++++++++++++++++++++ tests/test_config.toml | 6 ++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/test_config.toml diff --git a/src/config.rs b/src/config.rs index 16a06e5..8acde30 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,3 +21,27 @@ pub fn load_config(path: &str) -> GatewayConfig { file.read_to_string(&mut contents).unwrap(); toml::from_str(&contents).unwrap() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parses_config() -> Result<(), std::io::Error> { + let config = load_config("./tests/test_config.toml"); + let test_service = config + .services + .get("test-service") + .expect("test service not found"); + + assert_eq!(config.auth_url, "https://example.com"); + assert_eq!(test_service.path, "/testservice"); + assert_eq!( + test_service.target_host, + "https://my-service.default.svc.cluster.local" + ); + assert_eq!(test_service.target_port, 8080); + + Ok(()) + } +} diff --git a/tests/test_config.toml b/tests/test_config.toml new file mode 100644 index 0000000..e0587b1 --- /dev/null +++ b/tests/test_config.toml @@ -0,0 +1,6 @@ +auth_url="https://example.com" + +[services.test-service] +path="/testservice" +target_host="https://my-service.default.svc.cluster.local" +target_port=8080