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 <ruangyotn@skyller.co>
This commit is contained in:
Ruangyot Nanchiang 2025-03-25 18:31:09 +07:00 committed by GitHub
parent eaec50d8a2
commit e903e65e27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -68,7 +68,7 @@ pub struct ServiceConfig<Err = DefaultError> {
}
impl<Err: ErrorRenderer> ServiceConfig<Err> {
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<DefaultError> = ServiceConfig::new();
assert!(cfg.services.is_empty());
assert!(cfg.external.is_empty());
}
}