Skip to content

Commit

Permalink
test: add config parser unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
zenlex committed Mar 10, 2024
1 parent 648147e commit 33038e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
6 changes: 6 additions & 0 deletions tests/test_config.toml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 33038e2

Please sign in to comment.