Skip to content

Commit

Permalink
tardis update version (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Oct 21, 2024
1 parent 577f440 commit 07347b2
Show file tree
Hide file tree
Showing 45 changed files with 170 additions and 202 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion backend/basic/src/enumeration.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion backend/basic/src/rbum/rbum_enumeration.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
28 changes: 14 additions & 14 deletions backend/basic/src/test/init_test_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Postgres>,
pub redis: ContainerAsync<Redis>,
pub rabbit: ContainerAsync<RabbitMq>,
}

pub async fn init(docker: &Cli, sql_init_path: Option<String>) -> TardisResult<LifeHold<'_>> {
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<String>) -> TardisResult<LifeHold> {
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);

Expand Down
3 changes: 1 addition & 2 deletions backend/basic/tests/test_rbum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
3 changes: 1 addition & 2 deletions backend/basic/tests/test_task_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 10 additions & 13 deletions backend/gateways/spacegate-plugins/src/plugin/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
Expand Down Expand Up @@ -368,19 +369,15 @@ async fn handle_mix_req(plugin_config: &AuthPlugin, req: SgRequest) -> Result<Sg

let mix_body = TardisFuns::json.str_to_obj::<MixRequestBody>(&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::<http::Uri>().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::<http::Uri>().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()) {
Expand All @@ -397,8 +394,8 @@ async fn handle_mix_req(plugin_config: &AuthPlugin, req: SgRequest) -> Result<Sg
let true_uri = http::Uri::from_parts(true_uri_parts)?;
tracing::trace!(" raw url:[{}],true url:[{}]", parts.uri.to_string(), true_uri);
parts.uri = true_uri;
parts.method = Method::from_str(&mix_body.method.to_ascii_uppercase())
.map_err(|e| TardisError::custom("500", &format!(" method parse err {e}"), "500-parse_mix_req-method-error"))?;
parts.method =
Method::from_str(&mix_body.method.to_ascii_uppercase()).map_err(|e| TardisError::custom("500", &format!(" method parse err {e}"), "500-parse_mix_req-method-error"))?;

let mut headers = req_headers;
headers.extend(mix_body.headers);
Expand Down
29 changes: 12 additions & 17 deletions backend/gateways/spacegate-plugins/src/plugin/auth/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@ use super::*;

use tardis::crypto::crypto_sm2_4::{TardisCryptoSm2, TardisCryptoSm2PrivateKey};
use tardis::serde_json::Value;
use tardis::{
test::test_container::TardisTestContainer,
testcontainers::{self, clients::Cli, Container},
tokio,
};
use tardis::{test::test_container::TardisTestContainer, testcontainers::ContainerAsync, tokio};
use testcontainers_modules::redis::Redis;

#[tokio::test]
async fn test() {
env::set_var("RUST_LOG", "info,spacegate-plugins=trace,bios_auth=trace,tardis=trace");
tracing_subscriber::fmt::init();

let docker = testcontainers::clients::Cli::default();
let _x = docker_init(&docker).await.unwrap();
let _x = docker_init().await.unwrap();

// test_auth_plugin_ctx().await;
test_auth_plugin_crypto().await;
Expand Down Expand Up @@ -133,7 +128,7 @@ async fn test() {
// }

async fn test_auth_plugin_crypto() {
log::info!("========test_auth_plugin_crypto=====");
tardis::log::info!("========test_auth_plugin_crypto=====");

let filter_auth = SgPluginAuthConfig {
cache_url: env::var("TARDIS_FW.CACHE.URL").unwrap(),
Expand Down Expand Up @@ -168,7 +163,7 @@ async fn test_auth_plugin_crypto() {
let test_body_value = r#"test_body_value!@#$%^&*():"中文测试"#;

//========don't need to decrypt======
log::info!("========don't need to decrypt=====");
tardis::log::info!("========don't need to decrypt=====");
let req = Request::builder()
.method(Method::POST)
.uri(Uri::from_static("http://sg.idealworld.group/test1"))
Expand All @@ -183,7 +178,7 @@ async fn test_auth_plugin_crypto() {
assert_eq!(String::from_utf8_lossy(req_body).to_string(), test_body_value.to_string());

// =========request GET============
log::info!("========request GET=====");
tardis::log::info!("========request GET=====");
let (_crypto_data, bios_crypto_value) = crypto_req("", server_public_key.serialize().unwrap().as_ref(), front_pub_key.serialize().unwrap().as_ref(), true);

let req = Request::builder()
Expand All @@ -200,7 +195,7 @@ async fn test_auth_plugin_crypto() {
assert!(req_body.get_dumped().unwrap().bytes().count() == 0);

//=========request POST============
log::info!("========request POST=====");
tardis::log::info!("========request POST=====");
let (crypto_data, bios_crypto_value) = crypto_req(
test_body_value,
server_public_key.serialize().unwrap().as_ref(),
Expand All @@ -225,7 +220,7 @@ async fn test_auth_plugin_crypto() {
assert_eq!(req_body, test_body_value.to_string());

//======response============
log::info!("========response=====");
tardis::log::info!("========response=====");
let mock_resp = r#"mock_resp:test_body_value!@#$%^&*():"中文测试"#;

let mut resp = Response::builder().header("Test_Header", "test_header").status(200).body(SgBody::full(mock_resp)).unwrap();
Expand Down Expand Up @@ -381,13 +376,13 @@ fn crypto_resp(body: &str, crypto_header: &str, front_pri_key: &TardisCryptoSm2P
TardisFuns::crypto.sm4.decrypt_cbc(body, sm4_key, sm4_iv).unwrap()
}

pub struct LifeHold<'a> {
pub redis: Container<'a, Redis>,
pub struct LifeHold {
pub redis: ContainerAsync<Redis>,
}

async fn docker_init(docker: &Cli) -> TardisResult<LifeHold<'_>> {
let redis_container = TardisTestContainer::redis_custom(docker);
let port = redis_container.get_host_port_ipv4(6379);
async fn docker_init() -> TardisResult<LifeHold> {
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);

Expand Down
1 change: 0 additions & 1 deletion backend/middlewares/event/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 1 addition & 2 deletions backend/middlewares/event/tests/test_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use tardis::{tardis_static, testcontainers, tokio, TardisFuns};
async fn test_event() -> Result<(), Box<dyn std::error::Error>> {
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?;
Expand Down
5 changes: 3 additions & 2 deletions backend/middlewares/flow/src/dto/flow_state_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions backend/middlewares/flow/src/dto/flow_transition_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")]
Expand Down
3 changes: 1 addition & 2 deletions backend/middlewares/flow/tests/test_flow_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions backend/middlewares/schedule/tests/test_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
3 changes: 1 addition & 2 deletions backend/middlewares/schedule/tests/test_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
1 change: 0 additions & 1 deletion backend/services/bios-all/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 1 addition & 2 deletions backend/spi/spi-cache/tests/test_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down
Loading

0 comments on commit 07347b2

Please sign in to comment.