From e903e65e279a4d4281ce2b27f811f6ba257feb48 Mon Sep 17 00:00:00 2001 From: Ruangyot Nanchiang Date: Tue, 25 Mar 2025 18:31:09 +0700 Subject: [PATCH] add public ServiceConfig::register constructor to support external configuration (#250) (#539) * add public ServiceConfig::register constructor to support external configuration (#250) * fix: doctest ServiceConfig::register() error (#250) * add unit testing for ServiceConfig::register() * replace pub(crate) to pub in ServiceConfig::new() (#250) --------- Co-authored-by: RuangyotN --- ntex/src/web/config.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ntex/src/web/config.rs b/ntex/src/web/config.rs index 91c5034c..c7edceb6 100644 --- a/ntex/src/web/config.rs +++ b/ntex/src/web/config.rs @@ -68,7 +68,7 @@ pub struct ServiceConfig { } impl ServiceConfig { - pub(crate) fn new() -> Self { + pub fn new() -> Self { Self { services: Vec::new(), state: Extensions::new(), @@ -132,7 +132,7 @@ mod tests { use crate::http::{Method, StatusCode}; use crate::util::Bytes; use crate::web::test::{call_service, init_service, read_body, TestRequest}; - use crate::web::{self, App, HttpRequest, HttpResponse}; + use crate::web::{self, App, DefaultError, HttpRequest, HttpResponse}; #[crate::rt_test] async fn test_configure_state() { @@ -205,4 +205,11 @@ mod tests { let resp = call_service(&srv, req).await; assert_eq!(resp.status(), StatusCode::OK); } + + #[test] + fn test_new_service_config() { + let cfg: ServiceConfig = ServiceConfig::new(); + assert!(cfg.services.is_empty()); + assert!(cfg.external.is_empty()); + } }