From 07347b2c488104215082768ec037d7e1ce8ba7bd Mon Sep 17 00:00:00 2001 From: ZzIsGod1019 <1498852723@qq.com> Date: Mon, 21 Oct 2024 17:31:25 +0800 Subject: [PATCH] tardis update version (#854) --- Cargo.toml | 6 +- backend/basic/src/enumeration.rs | 2 +- backend/basic/src/rbum/rbum_enumeration.rs | 2 +- backend/basic/src/test/init_test_container.rs | 28 ++++---- backend/basic/tests/test_rbum.rs | 3 +- backend/basic/tests/test_task_processor.rs | 3 +- .../src/plugin/anti_replay.rs | 1 - .../spacegate-plugins/src/plugin/auth.rs | 23 +++---- .../src/plugin/auth/tests.rs | 29 ++++----- backend/middlewares/event/Cargo.toml | 1 - backend/middlewares/event/tests/test_event.rs | 3 +- .../flow/src/dto/flow_state_dto.rs | 5 +- .../flow/src/dto/flow_transition_dto.rs | 4 +- .../middlewares/flow/tests/test_flow_api.rs | 3 +- .../tests/test_basic_schedual_service.rs | 15 ++--- .../middlewares/schedule/tests/test_multi.rs | 3 +- .../schedule/tests/test_schedule.rs | 3 +- backend/services/bios-all/Cargo.toml | 1 - backend/spi/spi-cache/tests/test_cache.rs | 3 +- .../spi/spi-conf/tests/spi_conf_api_test.rs | 2 +- .../spi-conf/tests/spi_conf_listener_test.rs | 2 +- .../tests/spi_conf_nacos_compatible_test.rs | 2 +- backend/spi/spi-graph/tests/test_graph.rs | 3 +- backend/spi/spi-kv/tests/test_kv.rs | 3 +- backend/spi/spi-log/tests/test_log.rs | 3 +- backend/spi/spi-object/tests/test_object.rs | 7 +- .../spi/spi-plugin/src/plugin_enumeration.rs | 2 +- backend/spi/spi-plugin/tests/test_plugin.rs | 3 +- backend/spi/spi-reldb/tests/test_reldb.rs | 3 +- .../spi/spi-search/src/search_enumeration.rs | 2 +- .../spi-search/tests/init_search_container.rs | 64 ++++++++++--------- backend/spi/spi-search/tests/test_search.rs | 5 +- .../spi/spi-stats/src/stats_enumeration.rs | 2 +- backend/spi/spi-stats/tests/test_stats.rs | 3 +- .../auth/tests/init_cache_container.rs | 13 ++-- backend/supports/auth/tests/test_auth.rs | 5 +- backend/supports/iam/Cargo.toml | 1 - backend/supports/iam/src/iam_enumeration.rs | 2 +- backend/supports/iam/tests/test_basic.rs | 46 +++++++------ backend/supports/iam/tests/test_iam_api.rs | 4 +- backend/supports/iam/tests/test_iam_serv.rs | 6 +- backend/supports/reach/src/dto/enums.rs | 14 ++-- .../supports/reach/tests/test_message_send.rs | 4 +- .../supports/reach/tests/test_reach_common.rs | 27 ++++---- .../supports/reach/tests/test_send_client.rs | 6 +- 45 files changed, 170 insertions(+), 202 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 284063a86..bb481df29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,12 +59,12 @@ fancy-regex = { version = "0" } run_script = { version = "0.10" } rust_decimal = { version = "1" } rust_decimal_macros = { version = "1" } -testcontainers-modules = { version = "0.3", features = ["redis"] } +testcontainers-modules = { version = "0.11", features = ["redis"] } strum = { version = "0.26", features = ["derive"] } # tardis -# tardis = { version = "0.1.0-rc.16" } +tardis = { version = "0.1.0-rc.17" } # tardis = { path = "../tardis/tardis" } -tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "03ef942" } +# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "9cc9b3e" } # asteroid-mq = { git = "https://github.com/4t145/asteroid-mq.git", rev = "d59c64d" } asteroid-mq = { git = "https://github.com/4t145/asteroid-mq.git", rev = "83a6643" } asteroid-mq-sdk = { git = "https://github.com/4t145/asteroid-mq.git", rev = "83a6643" } diff --git a/backend/basic/src/enumeration.rs b/backend/basic/src/enumeration.rs index 224e41723..d963288a3 100644 --- a/backend/basic/src/enumeration.rs +++ b/backend/basic/src/enumeration.rs @@ -1,6 +1,6 @@ //! Basic enumerations use serde::{Deserialize, Serialize}; -use tardis::derive_more::Display; +use strum::Display; #[cfg(feature = "default")] use tardis::web::poem_openapi; diff --git a/backend/basic/src/rbum/rbum_enumeration.rs b/backend/basic/src/rbum/rbum_enumeration.rs index ac8f78d35..d2dfdf774 100644 --- a/backend/basic/src/rbum/rbum_enumeration.rs +++ b/backend/basic/src/rbum/rbum_enumeration.rs @@ -1,13 +1,13 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; +use strum::Display; use tardis::basic::error::TardisError; use tardis::basic::result::TardisResult; #[cfg(feature = "default")] use tardis::db::sea_orm; #[cfg(feature = "default")] use tardis::db::sea_orm::{DbErr, QueryResult, TryGetError, TryGetable}; -use tardis::derive_more::Display; #[cfg(feature = "default")] use tardis::web::poem_openapi; diff --git a/backend/basic/src/test/init_test_container.rs b/backend/basic/src/test/init_test_container.rs index d59edf126..1d1373169 100644 --- a/backend/basic/src/test/init_test_container.rs +++ b/backend/basic/src/test/init_test_container.rs @@ -3,32 +3,32 @@ use std::env; use tardis::basic::result::TardisResult; use tardis::test::test_container::TardisTestContainer; -use tardis::testcontainers::clients::Cli; -use tardis::testcontainers::Container; -use tardis::testcontainers::GenericImage; +use tardis::testcontainers::ContainerAsync; use tardis::TardisFuns; +use testcontainers_modules::postgres::Postgres; +use testcontainers_modules::rabbitmq::RabbitMq; use testcontainers_modules::redis::Redis; -pub struct LifeHold<'a> { - pub reldb: Container<'a, GenericImage>, - pub redis: Container<'a, Redis>, - pub rabbit: Container<'a, GenericImage>, +pub struct LifeHold { + pub reldb: ContainerAsync, + pub redis: ContainerAsync, + pub rabbit: ContainerAsync, } -pub async fn init(docker: &Cli, sql_init_path: Option) -> TardisResult> { - let reldb_container = TardisTestContainer::postgres_custom(sql_init_path.as_deref(), docker); - let port = reldb_container.get_host_port_ipv4(5432); +pub async fn init(sql_init_path: Option) -> TardisResult { + let reldb_container = TardisTestContainer::postgres_custom(sql_init_path.as_deref()).await?; + let port = reldb_container.get_host_port_ipv4(5432).await?; let url = format!("postgres://postgres:123456@127.0.0.1:{port}/test"); env::set_var("TARDIS_FW.DB.URL", url); - let redis_container = TardisTestContainer::redis_custom(docker); - let port = redis_container.get_host_port_ipv4(6379); + let redis_container = TardisTestContainer::redis_custom().await?; + let port = redis_container.get_host_port_ipv4(6379).await?; let url = format!("redis://127.0.0.1:{port}/0"); env::set_var("TARDIS_FW.CACHE.URL", url); // TODO remove - let rabbit_container = TardisTestContainer::rabbit_custom(docker); - let port = rabbit_container.get_host_port_ipv4(5672); + let rabbit_container = TardisTestContainer::rabbit_custom().await?; + let port = rabbit_container.get_host_port_ipv4(5672).await?; let url = format!("amqp://guest:guest@127.0.0.1:{port}/%2f"); env::set_var("TARDIS_FW.MQ.URL", url); diff --git a/backend/basic/tests/test_rbum.rs b/backend/basic/tests/test_rbum.rs index 7b9c4f7a5..de59b9c09 100644 --- a/backend/basic/tests/test_rbum.rs +++ b/backend/basic/tests/test_rbum.rs @@ -34,8 +34,7 @@ mod test_scope; #[tokio::test] async fn test_rbum() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_iam_serv=trace,sqlx::query=off,sqlparser=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; let ctx = init_test_data().await?; test_scope::test().await?; test_rbum_domain::test(&ctx).await?; diff --git a/backend/basic/tests/test_task_processor.rs b/backend/basic/tests/test_task_processor.rs index 443dc2f6a..c921f02e2 100644 --- a/backend/basic/tests/test_task_processor.rs +++ b/backend/basic/tests/test_task_processor.rs @@ -8,8 +8,7 @@ use tardis::{testcontainers, tokio, TardisFuns}; #[tokio::test] async fn test_task_processor() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_iam_serv=trace,sqlx::query=off,sqlparser=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; let cache_client = TardisFuns::inst("".to_string(), None).cache(); diff --git a/backend/gateways/spacegate-plugins/src/plugin/anti_replay.rs b/backend/gateways/spacegate-plugins/src/plugin/anti_replay.rs index 74ec59922..e2a2511d6 100644 --- a/backend/gateways/spacegate-plugins/src/plugin/anti_replay.rs +++ b/backend/gateways/spacegate-plugins/src/plugin/anti_replay.rs @@ -137,7 +137,6 @@ impl Plugin for AntiReplayPlugin { // #[tokio::test] // async fn test_anti_replay() { -// let docker = testcontainers::clients::Cli::default(); // let _x = docker_init(&docker).await.unwrap(); // let gateway_name = "gateway_aaa_1"; // spacegate_shell::functions::cache_client::init(gateway_name, &env::var("TARDIS_FW.CACHE.URL").unwrap()).await.unwrap(); diff --git a/backend/gateways/spacegate-plugins/src/plugin/auth.rs b/backend/gateways/spacegate-plugins/src/plugin/auth.rs index d78687634..5e7ac23b0 100644 --- a/backend/gateways/spacegate-plugins/src/plugin/auth.rs +++ b/backend/gateways/spacegate-plugins/src/plugin/auth.rs @@ -11,6 +11,7 @@ use bios_auth::{ use http::header::HOST; use serde::{Deserialize, Serialize}; use spacegate_shell::{ + ext_redis::redis::AsyncCommands, hyper::{ self, header, http::{HeaderMap, HeaderName, HeaderValue, StatusCode}, @@ -34,9 +35,9 @@ use tardis::{ basic::{error::TardisError, result::TardisResult}, cache::AsyncCommands as _, config::config_dto::CacheModuleConfig, - tracing::{self as tracing, instrument, warn}, serde_json::{self, json}, tokio::{sync::RwLock, task::JoinHandle}, + tracing::{self as tracing, instrument, warn}, url::Url, web::web_resp::TardisResp, TardisFuns, @@ -368,19 +369,15 @@ async fn handle_mix_req(plugin_config: &AuthPlugin, req: SgRequest) -> Result(&body)?; let true_uri = parts.uri.to_string().replace(&plugin_config.mix_replace_url, &mix_body.uri).replace("//", "/"); - tracing::trace!(?true_uri," string true uri:"); - let mut true_uri_parts = - true_uri.parse::().map_err(|e| TardisError::custom("500", &format!(" url parse err {e}"), "500-parse_mix_req-url-error"))?.into_parts(); + tracing::trace!(?true_uri, " string true uri:"); + let mut true_uri_parts = true_uri.parse::().map_err(|e| TardisError::custom("500", &format!(" url parse err {e}"), "500-parse_mix_req-url-error"))?.into_parts(); let host = parts.uri.host().map(String::from).or(parts.headers.get(HOST).and_then(|x| x.to_str().map(String::from).ok())); if let Some(host) = host { - true_uri_parts.authority = Some(http::uri::Authority::from_str(&host).map_err(|e| { - TardisError::custom( - "500", - &format!(" error parse str {host} to authority :{e}"), - "500-parse_mix_req-authority-error", - ) - })?); + true_uri_parts.authority = Some( + http::uri::Authority::from_str(&host) + .map_err(|e| TardisError::custom("500", &format!(" error parse str {host} to authority :{e}"), "500-parse_mix_req-authority-error"))?, + ); } let old_scheme = parts.uri.scheme().cloned().unwrap_or_else(|| { if let Some(port) = true_uri_parts.authority.clone().and_then(|a| a.port_u16()) { @@ -397,8 +394,8 @@ async fn handle_mix_req(plugin_config: &AuthPlugin, req: SgRequest) -> Result { - pub redis: Container<'a, Redis>, +pub struct LifeHold { + pub redis: ContainerAsync, } -async fn docker_init(docker: &Cli) -> TardisResult> { - let redis_container = TardisTestContainer::redis_custom(docker); - let port = redis_container.get_host_port_ipv4(6379); +async fn docker_init() -> TardisResult { + let redis_container = TardisTestContainer::redis_custom().await?; + let port = redis_container.get_host_port_ipv4(6379).await?; let url = format!("redis://127.0.0.1:{port}/0",); env::set_var("TARDIS_FW.CACHE.URL", url); diff --git a/backend/middlewares/event/Cargo.toml b/backend/middlewares/event/Cargo.toml index 6262d9187..1bd3118e8 100644 --- a/backend/middlewares/event/Cargo.toml +++ b/backend/middlewares/event/Cargo.toml @@ -38,7 +38,6 @@ tardis = { workspace = true, features = [ "ws-client", "cluster", "web-server", - "k8s", ] } bios-basic = { path = "../../basic", features = ["default", "test"] } tokio = { version = "1", features = ["full"] } diff --git a/backend/middlewares/event/tests/test_event.rs b/backend/middlewares/event/tests/test_event.rs index 5a8587bf7..64e58bc49 100644 --- a/backend/middlewares/event/tests/test_event.rs +++ b/backend/middlewares/event/tests/test_event.rs @@ -18,8 +18,7 @@ use tardis::{tardis_static, testcontainers, tokio, TardisFuns}; async fn test_event() -> Result<(), Box> { env::set_var("RUST_LOG", "debug,tardis=trace,bios_mw_event=trace,test_event=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; init_data().await?; test_event_topic_api().await?; diff --git a/backend/middlewares/flow/src/dto/flow_state_dto.rs b/backend/middlewares/flow/src/dto/flow_state_dto.rs index 3635ac842..829e7a037 100644 --- a/backend/middlewares/flow/src/dto/flow_state_dto.rs +++ b/backend/middlewares/flow/src/dto/flow_state_dto.rs @@ -116,8 +116,9 @@ pub struct FlowStateDetailResp { /// Type of state /// /// 状态类型 +// #[sea_orm(rs_type = "String", db_type = "String(Some(255))")] #[derive(Clone, Default, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum, EnumIter, sea_orm::DeriveActiveEnum)] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "FlowSysStateKind")] pub enum FlowSysStateKind { #[default] #[sea_orm(string_value = "start")] @@ -129,7 +130,7 @@ pub enum FlowSysStateKind { } #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum, EnumIter, sea_orm::DeriveActiveEnum)] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "FlowStateKind")] pub enum FlowStateKind { #[sea_orm(string_value = "simple")] Simple, diff --git a/backend/middlewares/flow/src/dto/flow_transition_dto.rs b/backend/middlewares/flow/src/dto/flow_transition_dto.rs index c58a91964..cd7e87f34 100644 --- a/backend/middlewares/flow/src/dto/flow_transition_dto.rs +++ b/backend/middlewares/flow/src/dto/flow_transition_dto.rs @@ -368,7 +368,7 @@ pub struct FlowTransitionActionChangeAgg { /// 后置动作类型,目前有状态修改和字段修改两种。 #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Default, Serialize, poem_openapi::Enum, EnumIter, sea_orm::DeriveActiveEnum)] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "FlowTransitionActionChangeKind")] pub enum FlowTransitionActionChangeKind { /// 字段修改 #[default] @@ -403,7 +403,7 @@ pub struct FlowTransitionActionByVarChangeInfo { /// 修改方式(清空,更改内容,更改为其他字段的值,加减值等) #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum, EnumIter, sea_orm::DeriveActiveEnum)] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "FlowTransitionActionByVarChangeInfoChangedKind")] pub enum FlowTransitionActionByVarChangeInfoChangedKind { /// 清空 #[sea_orm(string_value = "clean")] diff --git a/backend/middlewares/flow/tests/test_flow_api.rs b/backend/middlewares/flow/tests/test_flow_api.rs index 4fdb93f51..25fa6c3aa 100644 --- a/backend/middlewares/flow/tests/test_flow_api.rs +++ b/backend/middlewares/flow/tests/test_flow_api.rs @@ -24,8 +24,7 @@ mod test_flow_scenes_fsm1; async fn test_flow_api() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,tardis=trace,bios_mw_event=trace,test_event=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; let web_server = TardisFuns::web_server(); flow_initializer::init(&web_server).await.unwrap(); diff --git a/backend/middlewares/schedule/tests/test_basic_schedual_service.rs b/backend/middlewares/schedule/tests/test_basic_schedual_service.rs index a927ba203..c7d88706f 100644 --- a/backend/middlewares/schedule/tests/test_basic_schedual_service.rs +++ b/backend/middlewares/schedule/tests/test_basic_schedual_service.rs @@ -11,7 +11,7 @@ use tardis::{ chrono::{self, Utc}, rand::random, test::test_container::TardisTestContainer, - testcontainers, tokio, TardisFuns, TardisFunsInst, + tokio, TardisFuns, TardisFunsInst, }; mod test_common; @@ -23,19 +23,18 @@ fn funs() -> TardisFunsInst { async fn test_basic_schedual_service() -> TardisResult<()> { // std::env::set_current_dir("middlewares/schedule").unwrap(); std::env::set_var("RUST_LOG", "info,sqlx=off,sea_orm=INFO"); - let docker = testcontainers::clients::Cli::default(); - let reldb_container = TardisTestContainer::postgres_custom(None, &docker); - let port = reldb_container.get_host_port_ipv4(5432); + let reldb_container = TardisTestContainer::postgres_custom(None).await?; + let port = reldb_container.get_host_port_ipv4(5432).await?; let url = format!("postgres://postgres:123456@127.0.0.1:{port}/test"); env::set_var("TARDIS_FW.DB.URL", url); - let redis_container = TardisTestContainer::redis_custom(&docker); - let port = redis_container.get_host_port_ipv4(6379); + let redis_container = TardisTestContainer::redis_custom().await?; + let port = redis_container.get_host_port_ipv4(6379).await?; let url = format!("redis://127.0.0.1:{port}/0"); env::set_var("TARDIS_FW.CACHE.URL", url); - let rabbit_container = TardisTestContainer::rabbit_custom(&docker); - let port = rabbit_container.get_host_port_ipv4(5672); + let rabbit_container = TardisTestContainer::rabbit_custom().await?; + let port = rabbit_container.get_host_port_ipv4(5672).await?; let url = format!("amqp://guest:guest@127.0.0.1:{port}/%2f"); env::set_var("TARDIS_FW.MQ.URL", url); diff --git a/backend/middlewares/schedule/tests/test_multi.rs b/backend/middlewares/schedule/tests/test_multi.rs index 5af5892a6..f930da250 100644 --- a/backend/middlewares/schedule/tests/test_multi.rs +++ b/backend/middlewares/schedule/tests/test_multi.rs @@ -32,8 +32,7 @@ fn funs() -> TardisFunsInst { async fn test_multi() -> TardisResult<()> { // std::env::set_current_dir("middlewares/schedule").unwrap(); std::env::set_var("RUST_LOG", "info,sqlx=off,sea_orm=INFO,bios_mw_schedule=TRACE,tardis=off"); - let docker = testcontainers::clients::Cli::default(); - let container_hold = init_test_container::init(&docker, None).await?; + let container_hold = init_test_container::init(None).await?; init_tardis().await?; let counter = mock_webserver().await?; diff --git a/backend/middlewares/schedule/tests/test_schedule.rs b/backend/middlewares/schedule/tests/test_schedule.rs index ce399f846..f265d8f93 100644 --- a/backend/middlewares/schedule/tests/test_schedule.rs +++ b/backend/middlewares/schedule/tests/test_schedule.rs @@ -20,8 +20,7 @@ mod test_schedule_item; async fn test_log() -> TardisResult<()> { // for debug // env::set_current_dir("middlewares/schedule").unwrap(); - let docker = testcontainers::clients::Cli::default(); - let container_hold = init_test_container::init(&docker, None).await?; + let container_hold = init_test_container::init(None).await?; env::set_var("RUST_LOG", "debug,test_schedual=trace,sqlx::query=off,bios_mw_schedule=trace,bios_spi_kv=trace"); init_data().await?; diff --git a/backend/services/bios-all/Cargo.toml b/backend/services/bios-all/Cargo.toml index 131a23720..78a67c78a 100644 --- a/backend/services/bios-all/Cargo.toml +++ b/backend/services/bios-all/Cargo.toml @@ -17,7 +17,6 @@ tardis = { workspace = true, features = [ "conf-remote", "cluster", "tracing", - "k8s", ] } bios-iam = { path = "../../supports/iam", features = ["spi_search", "spi_kv"] } bios-auth = { path = "../../supports/auth", features = ["web-server"] } diff --git a/backend/spi/spi-cache/tests/test_cache.rs b/backend/spi/spi-cache/tests/test_cache.rs index 28e7c8fe3..11fd7fb51 100644 --- a/backend/spi/spi-cache/tests/test_cache.rs +++ b/backend/spi/spi-cache/tests/test_cache.rs @@ -19,8 +19,7 @@ mod test_cache_proc; async fn test_cache() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_cache=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; init_data().await?; diff --git a/backend/spi/spi-conf/tests/spi_conf_api_test.rs b/backend/spi/spi-conf/tests/spi_conf_api_test.rs index 28da3b8bd..6ae19ec65 100644 --- a/backend/spi/spi-conf/tests/spi_conf_api_test.rs +++ b/backend/spi/spi-conf/tests/spi_conf_api_test.rs @@ -19,7 +19,7 @@ use spi_conf_test_common::*; #[tokio::test] async fn spi_conf_namespace_test() -> TardisResult<()> { std::env::set_var("RUST_LOG", "info,sqlx=off,sea_orm=info,spi_conf_namespace_test=info,bios_spi_conf=TRACE"); - let docker = testcontainers::clients::Cli::default(); + let container_hold = init_tardis(&docker).await?; start_web_server().await?; let mut client = TestHttpClient::new("https://127.0.0.1:8080/spi-conf".to_string()); diff --git a/backend/spi/spi-conf/tests/spi_conf_listener_test.rs b/backend/spi/spi-conf/tests/spi_conf_listener_test.rs index dfec1a3be..6ee5622c2 100644 --- a/backend/spi/spi-conf/tests/spi_conf_listener_test.rs +++ b/backend/spi/spi-conf/tests/spi_conf_listener_test.rs @@ -18,7 +18,7 @@ use spi_conf_test_common::*; #[tokio::test] async fn spi_conf_namespace_test() -> TardisResult<()> { std::env::set_var("RUST_LOG", "error,spi_conf_listener_test=debug,sqlx=off,sea_orm=off,bios_spi_conf=DEBUG"); - let docker = testcontainers::clients::Cli::default(); + let container_hold = init_tardis(&docker).await?; start_web_server().await?; let tardis_ctx = TardisContext::default(); diff --git a/backend/spi/spi-conf/tests/spi_conf_nacos_compatible_test.rs b/backend/spi/spi-conf/tests/spi_conf_nacos_compatible_test.rs index f8299b05a..32fb44587 100644 --- a/backend/spi/spi-conf/tests/spi_conf_nacos_compatible_test.rs +++ b/backend/spi/spi-conf/tests/spi_conf_nacos_compatible_test.rs @@ -25,7 +25,7 @@ async fn spi_conf_namespace_test() -> TardisResult<()> { "info,tardis=debug,spi_conf_listener_test=debug,sqlx=off,sea_orm=debug,bios_spi_conf=DEBUG,poem_grpc=TRACE,tonic=TRACE", ); std::env::set_var("PROFILE", "nacos"); - let docker = testcontainers::clients::Cli::default(); + let container_hold = init_tardis(&docker).await?; let _web_server_handle = start_web_server().await; let tardis_ctx = TardisContext::default(); diff --git a/backend/spi/spi-graph/tests/test_graph.rs b/backend/spi/spi-graph/tests/test_graph.rs index 9aa8b6fbc..7a0a0d2b0 100644 --- a/backend/spi/spi-graph/tests/test_graph.rs +++ b/backend/spi/spi-graph/tests/test_graph.rs @@ -23,8 +23,7 @@ async fn test_graph() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_graph=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, Some(format!("{}config", root_path))).await?; + let _x = init_test_container::init(Some(format!("{}config", root_path))).await?; init_data().await?; diff --git a/backend/spi/spi-kv/tests/test_kv.rs b/backend/spi/spi-kv/tests/test_kv.rs index ee43ee768..f09515c92 100644 --- a/backend/spi/spi-kv/tests/test_kv.rs +++ b/backend/spi/spi-kv/tests/test_kv.rs @@ -20,8 +20,7 @@ mod test_kv_item; async fn test_kv() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_kv=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; init_data().await?; diff --git a/backend/spi/spi-log/tests/test_log.rs b/backend/spi/spi-log/tests/test_log.rs index 0e581d90b..f073f84db 100644 --- a/backend/spi/spi-log/tests/test_log.rs +++ b/backend/spi/spi-log/tests/test_log.rs @@ -20,8 +20,7 @@ mod test_log_item; async fn test_log() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_log=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; init_data().await?; diff --git a/backend/spi/spi-object/tests/test_object.rs b/backend/spi/spi-object/tests/test_object.rs index d4ac5ec79..da88a9838 100644 --- a/backend/spi/spi-object/tests/test_object.rs +++ b/backend/spi/spi-object/tests/test_object.rs @@ -20,10 +20,9 @@ mod test_object_obj; async fn test_object() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_object=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let minio = TardisTestContainer::minio_custom(&docker); - let minio_url = format!("http://127.0.0.1:{}", minio.get_host_port_ipv4(9000)); - let _x = init_test_container::init(&docker, None).await?; + let minio = TardisTestContainer::minio_custom().await?; + let minio_url = format!("http://127.0.0.1:{}", minio.get_host_port_ipv4(9000).await?); + let _x = init_test_container::init(None).await?; init_data(&minio_url).await?; diff --git a/backend/spi/spi-plugin/src/plugin_enumeration.rs b/backend/spi/spi-plugin/src/plugin_enumeration.rs index 291d5db09..ac44b0503 100644 --- a/backend/spi/spi-plugin/src/plugin_enumeration.rs +++ b/backend/spi/spi-plugin/src/plugin_enumeration.rs @@ -1,9 +1,9 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; +use strum::Display; use tardis::db::sea_orm; use tardis::db::sea_orm::{DbErr, QueryResult, TryGetError, TryGetable}; -use tardis::derive_more::Display; use tardis::web::poem_openapi; #[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, strum::EnumString)] diff --git a/backend/spi/spi-plugin/tests/test_plugin.rs b/backend/spi/spi-plugin/tests/test_plugin.rs index 7814ae6a1..4a52ecf2e 100644 --- a/backend/spi/spi-plugin/tests/test_plugin.rs +++ b/backend/spi/spi-plugin/tests/test_plugin.rs @@ -26,8 +26,7 @@ mod test_plugin_exec; async fn test_plugin() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_plugin=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; init_data().await?; Ok(()) diff --git a/backend/spi/spi-reldb/tests/test_reldb.rs b/backend/spi/spi-reldb/tests/test_reldb.rs index 84290cbfe..f8f9e895d 100644 --- a/backend/spi/spi-reldb/tests/test_reldb.rs +++ b/backend/spi/spi-reldb/tests/test_reldb.rs @@ -20,8 +20,7 @@ mod test_reldb_exec; async fn test_reldb() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_reldb=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; init_data().await?; diff --git a/backend/spi/spi-search/src/search_enumeration.rs b/backend/spi/spi-search/src/search_enumeration.rs index 0b8165c4e..ad9b2311b 100644 --- a/backend/spi/spi-search/src/search_enumeration.rs +++ b/backend/spi/spi-search/src/search_enumeration.rs @@ -2,11 +2,11 @@ use std::str::FromStr; use bios_basic::{enumeration::BasicQueryOpKind, helper::db_helper}; use serde::{Deserialize, Serialize}; +use strum::Display; use tardis::{ basic::{error::TardisError, result::TardisResult}, chrono::{DateTime, NaiveDate, Utc}, db::sea_orm::{self, prelude::DateTimeWithTimeZone, DbErr, QueryResult, TryGetError, TryGetable}, - derive_more::Display, serde_json, web::poem_openapi, }; diff --git a/backend/spi/spi-search/tests/init_search_container.rs b/backend/spi/spi-search/tests/init_search_container.rs index 48dbe7380..451e6137b 100644 --- a/backend/spi/spi-search/tests/init_search_container.rs +++ b/backend/spi/spi-search/tests/init_search_container.rs @@ -2,40 +2,41 @@ use std::env; use tardis::basic::result::TardisResult; use tardis::test::test_container::TardisTestContainer; -use tardis::testcontainers::clients::Cli; -use tardis::testcontainers::core::WaitFor; -use tardis::testcontainers::{Container, GenericImage}; +use tardis::testcontainers::core::{Mount, WaitFor}; +use tardis::testcontainers::runners::AsyncRunner; +use tardis::testcontainers::{ContainerAsync, GenericImage, ImageExt}; use tardis::TardisFuns; +use testcontainers_modules::elastic_search::ElasticSearch; use testcontainers_modules::redis::Redis; -pub struct LifeHold<'a> { - pub search: Container<'a, GenericImage>, - pub redis: Container<'a, Redis>, - pub es: Container<'a, GenericImage>, +pub struct LifeHold { + pub search: ContainerAsync, + pub redis: ContainerAsync, + pub es: ContainerAsync, } -pub async fn init(docker: &Cli) -> TardisResult> { +pub async fn init() -> TardisResult { let root_path = ""; // let root_path = "spi/spi-search/"; env::set_var("RUST_LOG", "debug,test_rbum=trace,sqlx::query=off"); - let reldb_container = postgres_custom(Some(&format!("{}config", root_path)), docker); - let port = reldb_container.get_host_port_ipv4(5432); + let reldb_container = postgres_custom(Some(&format!("{}config", root_path))).await; + let port = reldb_container.get_host_port_ipv4(5432).await?; let url = format!("postgres://postgres:123456@127.0.0.1:{}/test", port); env::set_var("TARDIS_FW.DB.URL", url); - let redis_container = TardisTestContainer::redis_custom(docker); - let port = redis_container.get_host_port_ipv4(6379); + let redis_container = TardisTestContainer::redis_custom().await?; + let port = redis_container.get_host_port_ipv4(6379).await?; let url = format!("redis://127.0.0.1:{}/0", port); env::set_var("TARDIS_FW.CACHE.URL", url); - let es_container = TardisTestContainer::es_custom(docker); - let port = es_container.get_host_port_ipv4(9200); + let es_container = TardisTestContainer::es_custom().await?; + let port = es_container.get_host_port_ipv4(9200).await?; let url = format!("http://elastic:123456@127.0.0.1:{}", port); env::set_var("TARDIS_FW.ES.URL", url); - let mq_container = TardisTestContainer::rabbit_custom(docker); - let port = mq_container.get_host_port_ipv4(5672); + let mq_container = TardisTestContainer::rabbit_custom().await?; + let port = mq_container.get_host_port_ipv4(5672).await?; let url = format!("amqp://guest:guest@127.0.0.1:{port}/%2f"); std::env::set_var("TARDIS_FW.MQ.URL", url); @@ -48,7 +49,7 @@ pub async fn init(docker: &Cli) -> TardisResult> { }) } -pub fn postgres_custom<'a>(init_script_path: Option<&str>, docker: &'a Cli) -> Container<'a, GenericImage> { +pub async fn postgres_custom<'a>(init_script_path: Option<&str>) -> ContainerAsync { if let Some(init_script_path) = init_script_path { let path = env::current_dir() .expect("[Tardis.Test_Container] Current path get error") @@ -56,19 +57,22 @@ pub fn postgres_custom<'a>(init_script_path: Option<&str>, docker: &'a Cli) -> C .to_str() .unwrap_or_else(|| panic!("[Tardis.Test_Container] Script Path [{}] get error", init_script_path)) .to_string(); - docker.run( - GenericImage::new("abcfy2/zhparser", "15") - .with_env_var("POSTGRES_PASSWORD", "123456") - .with_env_var("POSTGRES_DB", "test") - .with_volume(path, "/docker-entrypoint-initdb.d/") - .with_wait_for(WaitFor::message_on_stderr("database system is ready to accept connections")), - ) + GenericImage::new("abcfy2/zhparser", "15") + .with_wait_for(WaitFor::message_on_stderr("database system is ready to accept connections")) + .with_mount(Mount::bind_mount(path, "/docker-entrypoint-initdb.d/")) + .with_env_var("POSTGRES_PASSWORD", "123456") + .with_env_var("POSTGRES_DB", "test") + .start() + .await + .expect("zhparser started") + // .with_volume(path, "/docker-entrypoint-initdb.d/") } else { - docker.run( - GenericImage::new("abcfy2/zhparser", "15") - .with_env_var("POSTGRES_PASSWORD", "123456") - .with_env_var("POSTGRES_DB", "test") - .with_wait_for(WaitFor::message_on_stderr("database system is ready to accept connections")), - ) + GenericImage::new("abcfy2/zhparser", "15") + .with_wait_for(WaitFor::message_on_stderr("database system is ready to accept connections")) + .with_env_var("POSTGRES_PASSWORD", "123456") + .with_env_var("POSTGRES_DB", "test") + .start() + .await + .expect("zhparser started") } } diff --git a/backend/spi/spi-search/tests/test_search.rs b/backend/spi/spi-search/tests/test_search.rs index 77f3b6972..c4b9f73d9 100644 --- a/backend/spi/spi-search/tests/test_search.rs +++ b/backend/spi/spi-search/tests/test_search.rs @@ -14,7 +14,7 @@ use tardis::basic::field::TrimString; use tardis::basic::result::TardisResult; use tardis::tokio::time::sleep; use tardis::web::web_resp::Void; -use tardis::{testcontainers, tokio, TardisFuns}; +use tardis::{tokio, TardisFuns}; mod init_search_container; mod test_search_item; @@ -22,8 +22,7 @@ mod test_search_item; async fn test_search() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_search=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_search_container::init(&docker).await?; + let _x = init_search_container::init().await?; init_data(spi_constants::SPI_ES_KIND_CODE, &env::var("TARDIS_FW.ES.URL").unwrap()).await?; init_data(spi_constants::SPI_PG_KIND_CODE, &env::var("TARDIS_FW.DB.URL").unwrap()).await?; diff --git a/backend/spi/spi-stats/src/stats_enumeration.rs b/backend/spi/spi-stats/src/stats_enumeration.rs index 7d964de5a..1bbc36f25 100644 --- a/backend/spi/spi-stats/src/stats_enumeration.rs +++ b/backend/spi/spi-stats/src/stats_enumeration.rs @@ -2,11 +2,11 @@ use std::str::FromStr; use bios_basic::{enumeration::BasicQueryOpKind, helper::db_helper}; use serde::{Deserialize, Serialize}; +use strum::Display; use tardis::{ basic::{error::TardisError, result::TardisResult}, chrono::{DateTime, Local, NaiveDate, Utc}, db::sea_orm::{self, prelude::DateTimeWithTimeZone, sea_query::ArrayType, DbErr, QueryResult, TryGetError, TryGetable}, - derive_more::Display, serde_json, web::poem_openapi, }; diff --git a/backend/spi/spi-stats/tests/test_stats.rs b/backend/spi/spi-stats/tests/test_stats.rs index aae0d0938..8c340817d 100644 --- a/backend/spi/spi-stats/tests/test_stats.rs +++ b/backend/spi/spi-stats/tests/test_stats.rs @@ -22,8 +22,7 @@ mod test_stats_record; async fn test_stats() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_stats=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; + let _x = init_test_container::init(None).await?; init_data().await?; diff --git a/backend/supports/auth/tests/init_cache_container.rs b/backend/supports/auth/tests/init_cache_container.rs index f8798624a..cdd34ef58 100644 --- a/backend/supports/auth/tests/init_cache_container.rs +++ b/backend/supports/auth/tests/init_cache_container.rs @@ -2,18 +2,17 @@ use std::env; use tardis::basic::result::TardisResult; use tardis::test::test_container::TardisTestContainer; -use tardis::testcontainers::clients::Cli; -use tardis::testcontainers::Container; +use tardis::testcontainers::ContainerAsync; use tardis::TardisFuns; use testcontainers_modules::redis::Redis; -pub struct LifeHold<'a> { - pub redis: Container<'a, Redis>, +pub struct LifeHold { + pub redis: ContainerAsync, } -pub async fn init(docker: &Cli) -> TardisResult> { - let redis_container = TardisTestContainer::redis_custom(docker); - let port = redis_container.get_host_port_ipv4(6379); +pub async fn init() -> TardisResult { + let redis_container = TardisTestContainer::redis_custom().await?; + let port = redis_container.get_host_port_ipv4(6379).await?; let url = format!("redis://127.0.0.1:{port}/0",); env::set_var("TARDIS_FW.CACHE.URL", url); diff --git a/backend/supports/auth/tests/test_auth.rs b/backend/supports/auth/tests/test_auth.rs index 4e389e8bc..8033da2bc 100644 --- a/backend/supports/auth/tests/test_auth.rs +++ b/backend/supports/auth/tests/test_auth.rs @@ -4,7 +4,7 @@ use std::time::Duration; use bios_auth::auth_initializer; use tardis::basic::result::TardisResult; use tardis::tokio::time::sleep; -use tardis::{testcontainers, tokio, TardisFuns}; +use tardis::{tokio, TardisFuns}; mod init_cache_container; mod test_auth_encrypt; mod test_auth_init; @@ -17,8 +17,7 @@ async fn test_auth() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,bios_auth=trace"); test_auth_res::test_res()?; - let docker = testcontainers::clients::Cli::default(); - let _x = init_cache_container::init(&docker).await?; + let _x = init_cache_container::init().await?; test_auth_match::test_match().await?; diff --git a/backend/supports/iam/Cargo.toml b/backend/supports/iam/Cargo.toml index 8c6b4dbb3..0b2987ca5 100644 --- a/backend/supports/iam/Cargo.toml +++ b/backend/supports/iam/Cargo.toml @@ -34,7 +34,6 @@ tardis = { workspace = true, features = [ "web-server", "web-client", "mail", - "k8s", ] } bios-basic = { path = "../../basic", features = ["default", "with-mq"] } bios-sdk-invoke = { path = "../../../frontend/sdks/invoke", features = ["default", "event"] } diff --git a/backend/supports/iam/src/iam_enumeration.rs b/backend/supports/iam/src/iam_enumeration.rs index 2c0d176c6..224f3127c 100644 --- a/backend/supports/iam/src/iam_enumeration.rs +++ b/backend/supports/iam/src/iam_enumeration.rs @@ -1,11 +1,11 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; +use strum::Display; use tardis::basic::error::TardisError; use tardis::basic::result::TardisResult; use tardis::db::sea_orm; use tardis::db::sea_orm::{DbErr, QueryResult, TryGetError, TryGetable}; -use tardis::derive_more::Display; use tardis::web::poem_openapi; #[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)] diff --git a/backend/supports/iam/tests/test_basic.rs b/backend/supports/iam/tests/test_basic.rs index eaa0dc08e..3761625b1 100644 --- a/backend/supports/iam/tests/test_basic.rs +++ b/backend/supports/iam/tests/test_basic.rs @@ -4,10 +4,10 @@ use tardis::basic::field::TrimString; use bios_iam::basic::dto::iam_cert_conf_dto::IamCertConfLdapAddOrModifyReq; use bios_iam::basic::serv::iam_cert_ldap_serv::AccountFieldMap; use tardis::basic::result::TardisResult; -use tardis::testcontainers::clients::Cli; use tardis::testcontainers::core::{ExecCommand, WaitFor}; -use tardis::testcontainers::Container; +use tardis::testcontainers::runners::AsyncRunner; use tardis::testcontainers::GenericImage; +use tardis::testcontainers::{ContainerAsync, ImageExt}; use tardis::TardisFuns; const BASE_LDIF: &str = "dn: cn=Barbara,dc=test,dc=com @@ -51,12 +51,12 @@ uid: tuser2 userpassword: 123456"; //if BASE_LDIF change,LDAP_ACCOUNT_NUB must change too pub const LDAP_ACCOUNT_NUB: u64 = 4; -pub struct LifeHold<'a> { - pub ldap: Container<'a, GenericImage>, +pub struct LifeHold { + pub ldap: ContainerAsync, } -pub async fn init(docker: &'_ Cli) -> TardisResult> { - let ldap_container = get_ldap_container(docker); +pub async fn init() -> TardisResult { + let ldap_container = get_ldap_container().await?; TardisFuns::init(Some("tests/config")).await?; // TardisFuns::init("core/iam/tests/config").await?; @@ -64,32 +64,30 @@ pub async fn init(docker: &'_ Cli) -> TardisResult> { Ok(LifeHold { ldap: ldap_container }) } -fn get_ldap_container(docker: &Cli) -> Container<'_, GenericImage> { +async fn get_ldap_container() -> TardisResult> { const ORGANISATION: &str = "test"; const ADMIN_PASSWORD: &str = "123456"; let domain: String = format!("{}.com", ORGANISATION); - let ldap_container = docker.run( - GenericImage::new("osixia/openldap", "latest") - .with_env_var("LDAP_ORGANISATION", ORGANISATION) - .with_env_var("LDAP_DOMAIN", domain) - .with_env_var("LDAP_ADMIN_PASSWORD", ADMIN_PASSWORD) - .with_wait_for(WaitFor::message_on_stdout("First start is done...")), - ); + let ldap_container = GenericImage::new("osixia/openldap", "latest") + .with_wait_for(WaitFor::message_on_stdout("First start is done...")) + .with_env_var("LDAP_ORGANISATION", ORGANISATION) + .with_env_var("LDAP_DOMAIN", domain) + .with_env_var("LDAP_ADMIN_PASSWORD", ADMIN_PASSWORD) + .start() + .await + .expect("ldap container start"); - let port = ldap_container.get_host_port_ipv4(389); + let port = ldap_container.get_host_port_ipv4(389).await?; let url = "ldap://127.0.0.1".to_string(); let base_dn = format!("DC={ORGANISATION},DC=com"); let admin_dn = format!("CN=admin,{base_dn}"); - ldap_container.exec(ExecCommand { - cmd: format!("echo \"{BASE_LDIF}\" > /home/base.ldif",), - ready_conditions: vec![], - }); - ldap_container.exec(ExecCommand { - cmd: format!("ldapadd -x -H ldap://127.0.0.1 -D \"{admin_dn}\" -w {ADMIN_PASSWORD} -f /home/base.ldif "), - ready_conditions: vec![WaitFor::millis(5)], - }); + ldap_container.exec(ExecCommand::new(vec![format!("echo \"{BASE_LDIF}\" > /home/base.ldif",)])); + ldap_container.exec( + ExecCommand::new(vec![format!("ldapadd -x -H ldap://127.0.0.1 -D \"{admin_dn}\" -w {ADMIN_PASSWORD} -f /home/base.ldif ")]) + .with_container_ready_conditions(vec![WaitFor::millis(5)]), + ); env::set_var("TARDIS_FW.LDAP.PORT", port.to_string()); env::set_var("TARDIS_FW.LDAP.URL", url); @@ -97,7 +95,7 @@ fn get_ldap_container(docker: &Cli) -> Container<'_, GenericImage> { env::set_var("TARDIS_FW.LDAP.ADMIN_DN", admin_dn); env::set_var("TARDIS_FW.LDAP.ADMIN_CN", "admin"); env::set_var("TARDIS_FW.LDAP.ADMIN_PASSWORD", ADMIN_PASSWORD); - ldap_container + Ok(ldap_container) } //生成测试通用ldap 配置 diff --git a/backend/supports/iam/tests/test_iam_api.rs b/backend/supports/iam/tests/test_iam_api.rs index c7b93e923..a2aa8318a 100644 --- a/backend/supports/iam/tests/test_iam_api.rs +++ b/backend/supports/iam/tests/test_iam_api.rs @@ -20,9 +20,7 @@ mod test_iam_scenes_tenant; async fn test_iam_api() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_iam_api=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; - let _y = test_basic::init(&docker).await?; + let _y = test_basic::init().await?; let funs = iam_constants::get_tardis_inst(); funs.mq().subscribe("rbum::event", |(_, _)| async { Ok(()) }).await?; diff --git a/backend/supports/iam/tests/test_iam_serv.rs b/backend/supports/iam/tests/test_iam_serv.rs index 5aac589fa..c7117fcfa 100644 --- a/backend/supports/iam/tests/test_iam_serv.rs +++ b/backend/supports/iam/tests/test_iam_serv.rs @@ -6,7 +6,7 @@ use bios_basic::test::init_test_container; use bios_iam::iam_constants; use tardis::basic::result::TardisResult; use tardis::tokio::time::sleep; -use tardis::{testcontainers, tokio, TardisFuns}; +use tardis::{tokio, TardisFuns}; mod test_basic; mod test_ca_app; @@ -32,9 +32,7 @@ mod test_key_cache; async fn test_iam_serv() -> TardisResult<()> { env::set_var("RUST_LOG", "debug,test_iam_serv=trace,sqlx::query=off"); - let docker = testcontainers::clients::Cli::default(); - let _x = init_test_container::init(&docker, None).await?; - let _y = test_basic::init(&docker).await?; + let _y = test_basic::init().await?; let funs = iam_constants::get_tardis_inst(); funs.mq().subscribe("rbum::entity_deleted", |(_, _)| async { Ok(()) }).await?; diff --git a/backend/supports/reach/src/dto/enums.rs b/backend/supports/reach/src/dto/enums.rs index 39c09e5a2..dece65ea3 100644 --- a/backend/supports/reach/src/dto/enums.rs +++ b/backend/supports/reach/src/dto/enums.rs @@ -10,7 +10,7 @@ use tardis::{ #[derive(Debug, poem_openapi::Enum, EnumIter, Clone, Copy, DeriveActiveEnum, PartialEq, Eq, Serialize, Deserialize, Hash, Default)] #[oai(rename_all = "SCREAMING_SNAKE_CASE")] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "ReachChannelKind")] pub enum ReachChannelKind { #[sea_orm(string_value = "SMS")] #[default] @@ -62,7 +62,7 @@ impl FromStr for ReachChannelKind { #[derive(Debug, poem_openapi::Enum, EnumIter, Clone, Copy, DeriveActiveEnum, PartialEq, Eq, Serialize, Deserialize, Hash)] #[oai(rename_all = "SCREAMING_SNAKE_CASE")] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "ReachReceiveKind")] pub enum ReachReceiveKind { #[sea_orm(string_value = "ACCOUNT")] Account, @@ -77,7 +77,7 @@ pub enum ReachReceiveKind { #[derive(Debug, poem_openapi::Enum, EnumIter, Clone, Copy, DeriveActiveEnum, PartialEq, Eq, Serialize, Deserialize, Default)] #[oai(rename_all = "SCREAMING_SNAKE_CASE")] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "ReachStatusKind")] pub enum ReachStatusKind { #[sea_orm(string_value = "DRAFT")] Draft, @@ -101,7 +101,7 @@ pub enum ReachStatusKind { #[derive(Debug, poem_openapi::Enum, EnumIter, Clone, Copy, DeriveActiveEnum, PartialEq, Eq, Serialize, Deserialize)] #[oai(rename_all = "SCREAMING_SNAKE_CASE")] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "ReachDndStrategyKind")] pub enum ReachDndStrategyKind { #[sea_orm(string_value = "IGNORE")] Ignore, @@ -112,7 +112,7 @@ pub enum ReachDndStrategyKind { #[derive(Debug, poem_openapi::Enum, EnumIter, Clone, Copy, DeriveActiveEnum, PartialEq, Eq, Serialize, Deserialize, Default)] #[oai(rename_all = "SCREAMING_SNAKE_CASE")] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "ReachLevelKind")] pub enum ReachLevelKind { #[sea_orm(string_value = "URGENT")] Urgent, @@ -128,7 +128,7 @@ pub enum ReachLevelKind { #[derive(Debug, poem_openapi::Enum, EnumIter, Clone, Copy, DeriveActiveEnum, PartialEq, Eq, Serialize, Deserialize, Default)] #[oai(rename_all = "SCREAMING_SNAKE_CASE")] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "ReachTimeoutStrategyKind")] pub enum ReachTimeoutStrategyKind { #[sea_orm(string_value = "IGNORE")] #[default] @@ -140,7 +140,7 @@ pub enum ReachTimeoutStrategyKind { #[derive(Debug, poem_openapi::Enum, EnumIter, Clone, Copy, DeriveActiveEnum, PartialEq, Eq, Serialize, Deserialize, Default)] #[oai(rename_all = "SCREAMING_SNAKE_CASE")] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] -#[sea_orm(rs_type = "String", db_type = "String(Some(255))")] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "ReachTemplateKind")] pub enum ReachTemplateKind { #[sea_orm(string_value = "VCODE")] #[default] diff --git a/backend/supports/reach/tests/test_message_send.rs b/backend/supports/reach/tests/test_message_send.rs index f582375ce..31d580d0a 100644 --- a/backend/supports/reach/tests/test_message_send.rs +++ b/backend/supports/reach/tests/test_message_send.rs @@ -10,8 +10,8 @@ pub async fn test_ct_api() -> TardisResult<()> { // std::env::set_current_dir("./supports/reach/")?; std::env::set_var("RUST_LOG", "debug,bios_reach=trace,sqlx=off,sea_orm=debug,tardis=TRACE"); // std::env::set_var("RUST_LOG", "test_ct=info"); - let docker = testcontainers::clients::Cli::default(); - let holder = init_tardis(&docker).await?; + + let holder = init_tardis().await?; let scene_code = "TEST-SCENE-CODE"; let scene_name = "测试场景"; bios_reach::reach_initializer::reach_init_trigger_scene(&ReachTriggerSceneTree::new(scene_name, scene_code, [])).await?; diff --git a/backend/supports/reach/tests/test_reach_common.rs b/backend/supports/reach/tests/test_reach_common.rs index 603e5a6d5..193ef16b4 100644 --- a/backend/supports/reach/tests/test_reach_common.rs +++ b/backend/supports/reach/tests/test_reach_common.rs @@ -12,7 +12,7 @@ use bios_reach::reach_send_channel::SendChannelMap; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::sync::{Arc, OnceLock}; -use tardis::testcontainers::GenericImage; +use tardis::testcontainers::ContainerAsync; use tardis::tokio::sync::RwLock; use tardis::web::poem_openapi::param::Path; use tardis::web::poem_openapi::payload::{Form, Json}; @@ -22,15 +22,16 @@ use tardis::web::web_server::{WebServerModule, WebServerModuleOption}; use tardis::{ basic::{dto::TardisContext, result::TardisResult}, test::test_container::TardisTestContainer, - testcontainers::{clients::Cli, Container}, TardisFuns, }; use tardis::{log, rand, serde_json}; +use testcontainers_modules::postgres::Postgres; +use testcontainers_modules::rabbitmq::RabbitMq; use testcontainers_modules::redis::Redis; -pub struct Holder<'d> { - pub db: Container<'d, GenericImage>, - pub cache: Container<'d, Redis>, - pub mq: Container<'d, GenericImage>, +pub struct Holder { + pub db: ContainerAsync, + pub cache: ContainerAsync, + pub mq: ContainerAsync, pub sms_mocker: HwSmsMockerApi, pub iam_mocker: IamMockerApi, } @@ -45,17 +46,17 @@ pub fn get_test_ctx() -> &'static TardisContext { } #[allow(dead_code)] -pub async fn init_tardis(docker: &Cli) -> TardisResult { - let reldb_container = TardisTestContainer::postgres_custom(None, docker); - let port = reldb_container.get_host_port_ipv4(5432); +pub async fn init_tardis() -> TardisResult { + let reldb_container = TardisTestContainer::postgres_custom(None).await?; + let port = reldb_container.get_host_port_ipv4(5432).await?; let url = format!("postgres://postgres:123456@127.0.0.1:{port}/test"); std::env::set_var("TARDIS_FW.DB.URL", url); - let redis_container = TardisTestContainer::redis_custom(docker); - let port = redis_container.get_host_port_ipv4(6379); + let redis_container = TardisTestContainer::redis_custom().await?; + let port = redis_container.get_host_port_ipv4(6379).await?; let url = format!("redis://127.0.0.1:{port}/0"); std::env::set_var("TARDIS_FW.CACHE.URL", url); - let rabbit_container = TardisTestContainer::rabbit_custom(docker); - let port = rabbit_container.get_host_port_ipv4(5672); + let rabbit_container = TardisTestContainer::rabbit_custom().await?; + let port = rabbit_container.get_host_port_ipv4(5672).await?; let url = format!("amqp://guest:guest@127.0.0.1:{port}/%2f"); std::env::set_var("TARDIS_FW.MQ.URL", url); diff --git a/backend/supports/reach/tests/test_send_client.rs b/backend/supports/reach/tests/test_send_client.rs index 7af8dab04..b4f9edc9c 100644 --- a/backend/supports/reach/tests/test_send_client.rs +++ b/backend/supports/reach/tests/test_send_client.rs @@ -26,8 +26,7 @@ pub async fn test_hw_sms() -> TardisResult<()> { std::env::set_var("PROFILE", "prod"); std::env::set_var("RUST_LOG", "info,sqlx=off,sea_orm=debug,tardis=TRACE,bios_reach=trace,reqwest=trace"); - let docker = testcontainers::clients::Cli::default(); - let holder = init_tardis(&docker).await?; + let holder = init_tardis().await?; let ctx = get_test_ctx(); let funs = get_tardis_inst(); let client = reach_invoke::Client::new("http://127.0.0.1:8080/reach", ctx, &funs); @@ -46,8 +45,7 @@ pub async fn test_mail() -> TardisResult<()> { std::env::set_var("PROFILE", "prod"); std::env::set_var("RUST_LOG", "info,sqlx=off,sea_orm=debug,tardis=TRACE,bios_reach=trace,reqwest=trace"); - let docker = testcontainers::clients::Cli::default(); - let holder = init_tardis(&docker).await?; + let holder = init_tardis().await?; let ctx = get_test_ctx(); let funs = get_tardis_inst(); let client = reach_invoke::Client::new("http://127.0.0.1:8080/reach", ctx, &funs);