From c27093125aed8434c16655af7e7f415d84859dc7 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 4 Jul 2025 17:03:20 -0600 Subject: test: start to build table tests --- tests/authorization/check_service_test.rs | 55 ++++++++++++++----------------- 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'tests/authorization') diff --git a/tests/authorization/check_service_test.rs b/tests/authorization/check_service_test.rs index fe45712d..4ff7a89b 100644 --- a/tests/authorization/check_service_test.rs +++ b/tests/authorization/check_service_test.rs @@ -146,39 +146,34 @@ mod tests { // {status: tonic::Code::PermissionDenied, http: &HTTPRequest{Method: "GET", Path: "/dashboard"}}, // {status: tonic::Code::PermissionDenied, http: &HTTPRequest{Method: "GET", Path: "/dashboard", Headers: invalidHeaders}}, // {status: tonic::Code::PermissionDenied, http: &HTTPRequest{Method: "POST", Path: "/sparkles"}}, - // - // http: - // method: \"GET\", - // headers: { - // \":method\": \"GET\", - // \":authority\": \"localhost:10000\", - // \":path\": \"/sparkles\", - // }, - // path: \"/sparkles\", - // host: \"localhost:10000\", - let request = tonic::Request::new(build_request(|item: &mut HttpRequest| { - let path = String::from("/"); - let method = String::from("GET"); - let host = String::from("sparkle.staging.runway.gitlab.net"); - - item.method = method.clone(); - item.path = path.clone(); - item.host = host.clone(); - item.headers = build_headers(vec![ - (String::from(":path"), path), - (String::from(":method"), method), - (String::from(":authority"), host), - ]); - })); + let test_cases = vec![( + "GET", + "/", + "sparkle.staging.runway.gitlab.net", + tonic::Code::Ok, + )]; - let response = subject().check(request).await; - assert!(response.is_ok()); + for (method, path, host, expected_status_code) in test_cases { + let request = tonic::Request::new(build_request(|item: &mut HttpRequest| { + item.method = method.to_string(); + item.path = path.to_string(); + item.host = host.to_string(); + item.headers = build_headers(vec![ + (String::from(":path"), path.to_string()), + (String::from(":method"), method.to_string()), + (String::from(":authority"), host.to_string()), + ]); + })); - let check_response = response.unwrap().into_inner(); - assert!(check_response.status.is_some()); + let response = subject().check(request).await; + assert!(response.is_ok()); - let status = check_response.status.unwrap(); - assert_eq!(status.code, tonic::Code::Ok as i32); + let check_response = response.unwrap().into_inner(); + assert!(check_response.status.is_some()); + + let status = check_response.status.unwrap(); + assert_eq!(status.code, expected_status_code as i32); + } } } -- cgit v1.2.3