feat(proxy): add render_config method and UpstreamService mock

- Add render_config to ProxyServiceTrait and implement it

- Add mockall automock to UpstreamService

- Remove unused OverrideRef import
This commit is contained in:
GW_MC
2026-07-05 05:29:19 +00:00
parent b7891ec200
commit a7863b9e87
3 changed files with 14 additions and 1 deletions

View File

@@ -39,6 +39,9 @@ pub trait ProxyServiceTrait: Send + Sync + 'static {
) -> ProxyServiceResult<ProxyConfigSummary>;
async fn delete_config(&self, id: uuid::Uuid) -> ProxyServiceResult<bool>;
// Render
async fn render_config(&self, proxy_id: uuid::Uuid) -> ProxyServiceResult<String>;
// Binding
async fn get_active_agent_config(
&self,

View File

@@ -32,6 +32,15 @@ impl ProxyServiceTrait for ProxyServiceImpl {
self.repo.get_merged_proxy_config(proxy_id).await
}
async fn render_config(&self, proxy_id: uuid::Uuid) -> ProxyServiceResult<String> {
let config = self.repo.get_merged_proxy_config(proxy_id).await?;
let renderer = self
.renderers
.get(&config.r#type)
.ok_or(ProxyServiceError::RendererNotFound)?;
Ok(renderer.render(&config))
}
async fn list_configs(&self) -> ProxyServiceResult<Vec<ProxyConfigSummary>> {
self.repo.list_proxy_configs().await
}

View File

@@ -2,7 +2,7 @@ use sea_orm::{ActiveModelTrait, ActiveValue::Set, DatabaseConnection, EntityTrai
use uuid::Uuid;
use crate::service::proxy::types::{
OverrideRef, ProxyServiceError, ProxyServiceResult, UpstreamConfig,
ProxyServiceError, ProxyServiceResult, UpstreamConfig,
};
pub struct CreateUpstreamParams {
@@ -34,6 +34,7 @@ fn model_to_config(model: crate::db::entities::upstream::Model) -> UpstreamConfi
}
}
#[cfg_attr(test, mockall::automock)]
#[async_trait::async_trait]
pub trait UpstreamService: Send + Sync + 'static {
async fn get(&self, id: Uuid) -> ProxyServiceResult<UpstreamConfig>;