Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 脚本开放管理类API #2318 #2578

Merged

Conversation

liuliaozhong
Copy link
Collaborator

No description provided.

* 失败响应通用设置
*/
public static ResponseSpecification failResponseSpec() {
ResponseSpecBuilder builder = new ResponseSpecBuilder();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个响应并不通用,这个方法有点误导

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去掉了,errorCode调用处传入

req.setScriptId(script.getScriptId());
Operations.deletePublicScript(req);
// 清理脚本版本
EsbDeletePublicScriptVersionV3Req req1 = new EsbDeletePublicScriptVersionV3Req();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多余的操作,删除脚本也会同时删除脚本版本

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已去除

req.setVersion("v2");
req.setVersionDesc("v2_desc");
if (CollectionUtils.isEmpty(createdPublicScriptList)){
testCreatePublicScript();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试用例之间最好能保持独立行。这里可以调用 Operations 里边的通用方法创建一个公共脚本,然后基于这个创建好的脚本来新建脚本,个人觉得会更合理一些

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,测试用例之间不应该有依赖。已改

.spec(ApiUtil.successResponseSpec())
.body("data", notNullValue())
.body("data.id", greaterThan(0))
.body("data.script_id", notNullValue())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不够严谨,这个必须等同与请求传入的 script_id. 其他地方类似

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改

req.setContent(SHELL_SCRIPT_CONTENT_BASE64);
req.setVersion("v2");
req.setVersionDesc("v2_desc");
if (CollectionUtils.isEmpty(createdPublicScriptList)){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试用例之间最好能保持独立行。这里可以调用 Operations 里边的通用方法创建一个公共脚本,然后基于这个创建好的脚本来新建脚本,个人觉得会更合理一些

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改

.body("data.script_version_id", equalTo(req.getScriptVersionId().intValue()))
.body("data.script_id", equalTo(req.getScriptId()));
} else {
given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要在一个测试用例里边测试两种分支。if/else 的可以拆分为两个测试用例

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单独出来了

void testPublishPublicScriptVersion() {
EsbScriptVersionDetailV3DTO scriptVersionDTO;
if (CollectionUtils.isNotEmpty(createdPublicScriptList)) {
scriptVersionDTO = createdPublicScriptList.get(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createdPublicScriptList 这个变量仅仅用于最终删除使用。如果多个测试用例并发的执行的话,createdPublicScriptList的数据和状态都是不确定的,容易有并发问题。相关使用 createdPublicScriptList 的地方可以修改下

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改


// 版本号有特殊字符, 创建失败
req.setVersion("|");
given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
.body(JsonUtil.toJson(req))
.post(APIV3Urls.CREATE_PUBLIC_SCRIPT)
.then()
.spec(ApiUtil.failResponseSpec());
.spec(ApiUtil.failResponseSpec(ErrorCode.BAD_REQUEST));
createdPublicScriptList.add(createdPublicScript);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

创建好之后需要立即放入 createdPublicScriptList, 避免中间过程报错导致已创建的脚本没有被清理。其他地方类似

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

@wangyu096 wangyu096 merged commit aaa78a5 into TencentBlueKing:master Nov 3, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants