Skip to content

Commit

Permalink
add tests for env render
Browse files Browse the repository at this point in the history
  • Loading branch information
4t145 committed Aug 26, 2024
1 parent fbd4773 commit a6d3452
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 5 deletions.
4 changes: 0 additions & 4 deletions backend/spi/spi-conf/src/dto/conf_config_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub struct ConfigDescriptor {
#[oai(default, validator(min_length = 1, max_length = 256))]
pub namespace_id: NamespaceId,
/// 配置分组名
#[oai(validator(min_length = 1, max_length = 256))]
pub group: String,
/// 配置名
#[oai(validator(min_length = 1, max_length = 256))]
Expand Down Expand Up @@ -102,11 +101,8 @@ pub struct ConfigPublishRequest {
pub config_tags: Vec<String>,
/// 配置描述
pub desc: Option<String>,
///
pub r#use: Option<String>,
///
pub effect: Option<String>,
/// -
pub schema: Option<String>,
}

Expand Down
88 changes: 87 additions & 1 deletion backend/spi/spi-conf/tests/spi_conf_api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn spi_conf_namespace_test() -> TardisResult<()> {
owner: "app001".to_string(),
..Default::default()
})?;
let funs = TardisFuns::inst_with_db_conn(DOMAIN_CODE.to_string(), None);
let _funs = TardisFuns::inst_with_db_conn(DOMAIN_CODE.to_string(), None);
let RegisterResponse { username, password } = client
.put(
"/ci/auth/register_bundle",
Expand Down Expand Up @@ -320,6 +320,92 @@ pub async fn test_curd(client: &mut TestHttpClient) -> TardisResult<()> {
assert_eq!(response[0].data_id, "conf-2");
assert_eq!(response[1].data_id, "conf-1");
assert_eq!(response[2].data_id, "conf-0");

// 12 test .env file
const ENV_TEST_NAMESPACE_ID: &str = "test config";
let _response = client
.post::<_, bool>(
"/ci/namespace",
&NamespaceAttribute {
namespace: ENV_TEST_NAMESPACE_ID.into(),
namespace_show_name: "测试环境变量命名空间".to_string(),
namespace_desc: Some("测试环境变量命名空间".to_string()),
},
)
.await;
let _response = client
.post::<_, bool>(
"/ci/cs/config",
&json!( {
"content": r#"
TYPE=ALPHA
VALUE=123
URL=http://www.baidu.com
# this is a comment
"#,
"group": "".to_string(),
"data_id": ".env".to_string(),
"schema": "env",
"namespace_id": NAMESPACE_ID.to_string(),
}),
)
.await;
let config_to_be_render = r#"
[conf]
type=$ENV{TYPE}
value=$ENV{VALUE}
url=$ENV{URL}
"#;
let _response = client
.post::<_, bool>(
"/ci/cs/config",
&json!( {
"content": config_to_be_render,
"namespace_id": NAMESPACE_ID.to_string(),
"group": "DEFAULT-GROUP".to_string(),
"data_id": "conf-env".to_string(),
"schema": "toml",
}),
)
.await;
let response = client.get::<ConfigItem>(&format!("/ci/cs/config/detail?namespace_id={NAMESPACE_ID}&group=DEFAULT-GROUP&data_id=conf-env")).await;
assert_eq!(
response.content,
r#"
[conf]
type=ALPHA
value=123
url=http://www.baidu.com
"#
);
// UPDATE the .env file
let _response = client
.post::<_, bool>(
"/ci/cs/config",
&json!( {
"content": r#"
TYPE=BETA
VALUE=456
URL=http://www.google.com
"#,
"group": "".to_string(),
"data_id": ".env".to_string(),
"schema": "env",
"namespace_id": NAMESPACE_ID.to_string(),
}),
)
.await;
let response = client.get::<ConfigItem>(&format!("/ci/cs/config/detail?namespace_id={NAMESPACE_ID}&group=DEFAULT-GROUP&data_id=conf-env")).await;
assert_eq!(
response.content,
r#"
[conf]
type=BETA
value=456
url=http://www.google.com
"#
);

Ok(())
}

Expand Down

0 comments on commit a6d3452

Please sign in to comment.