From 34481239b03c92586b44163ec16898a0a6342a43 Mon Sep 17 00:00:00 2001 From: Adil Hafeez Date: Thu, 6 Feb 2025 10:31:52 -0800 Subject: [PATCH] add tests --- crates/prompt_gateway/src/tools.rs | 103 +++++++++++++++++++++ crates/prompt_gateway/tests/integration.rs | 2 +- 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/crates/prompt_gateway/src/tools.rs b/crates/prompt_gateway/src/tools.rs index 5ef8b1fb..b3b3d07e 100644 --- a/crates/prompt_gateway/src/tools.rs +++ b/crates/prompt_gateway/src/tools.rs @@ -52,3 +52,106 @@ pub fn compute_request_path_body( Ok((path, body)) } + +#[cfg(test)] +mod test { + use common::configuration::{HttpMethod, Parameter}; + + #[test] + fn test_compute_request_path_body() { + let endpoint_path = "/cluster.open-cluster-management.io/v1/managedclusters/{cluster_name}"; + let tool_params = serde_yaml::from_str( + r#" + cluster_name: test1 + hello: hello world + "#, + ) + .unwrap(); + let prompt_target_params = vec![Parameter { + name: "country".to_string(), + parameter_type: None, + description: "test target".to_string(), + required: None, + enum_values: None, + default: Some("US".to_string()), + in_path: None, + format: None, + }]; + let http_method = HttpMethod::Get; + let (path, body) = super::compute_request_path_body( + endpoint_path, + &tool_params, + &prompt_target_params, + &http_method, + ) + .unwrap(); + assert_eq!( + path, + "/cluster.open-cluster-management.io/v1/managedclusters/test1?hello=hello%20world&country=US" + ); + assert_eq!(body, None); + } + + #[test] + fn test_compute_request_path_body_empty_params() { + let endpoint_path = "/cluster.open-cluster-management.io/v1/managedclusters/"; + let tool_params = serde_yaml::from_str(r#"{}"#).unwrap(); + let prompt_target_params = vec![Parameter { + name: "country".to_string(), + parameter_type: None, + description: "test target".to_string(), + required: None, + enum_values: None, + default: Some("US".to_string()), + in_path: None, + format: None, + }]; + let http_method = HttpMethod::Get; + let (path, body) = super::compute_request_path_body( + endpoint_path, + &tool_params, + &prompt_target_params, + &http_method, + ) + .unwrap(); + assert_eq!( + path, + "/cluster.open-cluster-management.io/v1/managedclusters/?country=US" + ); + assert_eq!(body, None); + } + + #[test] + fn test_compute_request_path_body_override_default_val() { + let endpoint_path = "/cluster.open-cluster-management.io/v1/managedclusters/"; + let tool_params = serde_yaml::from_str( + r#" + country: UK + "#, + ) + .unwrap(); + let prompt_target_params = vec![Parameter { + name: "country".to_string(), + parameter_type: None, + description: "test target".to_string(), + required: None, + enum_values: None, + default: Some("US".to_string()), + in_path: None, + format: None, + }]; + let http_method = HttpMethod::Get; + let (path, body) = super::compute_request_path_body( + endpoint_path, + &tool_params, + &prompt_target_params, + &http_method, + ) + .unwrap(); + assert_eq!( + path, + "/cluster.open-cluster-management.io/v1/managedclusters/?country=UK" + ); + assert_eq!(body, None); + } +} diff --git a/crates/prompt_gateway/tests/integration.rs b/crates/prompt_gateway/tests/integration.rs index 4cc6f656..4af98166 100644 --- a/crates/prompt_gateway/tests/integration.rs +++ b/crates/prompt_gateway/tests/integration.rs @@ -386,7 +386,7 @@ fn prompt_gateway_request_to_llm_gateway() { ("x-arch-upstream", "api_server"), (":authority", "api_server"), ("x-envoy-max-retries", "3"), - (":path", "/weather") + (":path", "/weather"), ]), Some(expected_body), None,