* [misc] Enhance unit tests for gitlabModel::apiGetSingleBranch() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -209,17 +209,20 @@ class gitlabTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Api get signle branch.
|
||||
* Test apiGetSingleBranch method.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @param string $branch
|
||||
* @access public
|
||||
* @return object
|
||||
* @return object|array|null
|
||||
*/
|
||||
public function apiGetSingleBranchTest($gitlabID, $projectID, $branch)
|
||||
{
|
||||
return $this->gitlab->apiGetSingleBranch($gitlabID, $projectID, $branch);
|
||||
$result = $this->gitlab->apiGetSingleBranch($gitlabID, $projectID, $branch);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1310,4 +1313,21 @@ class gitlabTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test apiGetProjectMembers method.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @param int $userID
|
||||
* @access public
|
||||
* @return object|array|null
|
||||
*/
|
||||
public function apiGetProjectMembersTest(int $gitlabID, int $projectID, int $userID = 0): object|array|null
|
||||
{
|
||||
$result = $this->gitlab->apiGetProjectMembers($gitlabID, $projectID, $userID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,27 +6,38 @@ su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->apiGetSingleBranch();
|
||||
title=测试 gitlabModel::apiGetSingleBranch();
|
||||
timeout=0
|
||||
cid=1
|
||||
cid=0
|
||||
|
||||
- 查询正确的branch信息属性name @branch1
|
||||
- 使用不存在的gitlabID查询branch信息 @0
|
||||
- 使用不存在的projectID查询branch信息属性message @404 Project Not Found
|
||||
- 使用不存在的branch名称查询branch信息属性message @404 Branch Not Found
|
||||
- 使用空字符串作为分支名称查询branch信息属性message @404 Branch Not Found
|
||||
- 使用特殊字符作为分支名称查询branch信息属性message @404 Branch Not Found
|
||||
- 使用极长分支名称查询branch信息属性message @404 Branch Not Found
|
||||
|
||||
*/
|
||||
|
||||
zenData('pipeline')->gen(5);
|
||||
// 准备测试数据
|
||||
zendata('pipeline')->loadYaml('pipeline_apigetsinglebranch', false, 2)->gen(10);
|
||||
|
||||
$gitlab = new gitlabTest();
|
||||
|
||||
// 执行测试
|
||||
$branch1 = $gitlab->apiGetSingleBranchTest(1, 2, 'branch1');
|
||||
$branch2 = $gitlab->apiGetSingleBranchTest(0, 2, 'branch1');
|
||||
$branch3 = $gitlab->apiGetSingleBranchTest(1, 0, 'branch1');
|
||||
$branch4 = $gitlab->apiGetSingleBranchTest(1, 2, 'branch12345');
|
||||
$branch5 = $gitlab->apiGetSingleBranchTest(1, 2, '');
|
||||
$branch6 = $gitlab->apiGetSingleBranchTest(1, 2, 'feature/test@#$%');
|
||||
$branch7 = $gitlab->apiGetSingleBranchTest(1, 2, str_repeat('a', 300));
|
||||
|
||||
r($branch1) && p('name') && e('branch1'); // 查询正确的branch信息
|
||||
r($branch2) && p() && e('0'); // 使用不存在的gitlabID查询branch信息
|
||||
r($branch3) && p('message') && e('404 Project Not Found'); // 使用不存在的projectID查询branch信息
|
||||
r($branch4) && p('message') && e('404 Branch Not Found'); // 使用不存在的branch名称查询branch信息
|
||||
r($branch4) && p('message') && e('404 Branch Not Found'); // 使用不存在的branch名称查询branch信息
|
||||
r($branch5) && p('message') && e('404 Branch Not Found'); // 使用空字符串作为分支名称查询branch信息
|
||||
r($branch6) && p('message') && e('404 Branch Not Found'); // 使用特殊字符作为分支名称查询branch信息
|
||||
r($branch7) && p('message') && e('404 Branch Not Found'); // 使用极长分支名称查询branch信息
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
title: GitLab Pipeline测试数据
|
||||
desc: 用于apiGetSingleBranch方法测试的pipeline表数据
|
||||
author: Claude
|
||||
version: 1.0
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: Pipeline ID
|
||||
range: 1-10
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: type
|
||||
note: Pipeline类型
|
||||
range: gitlab{5},jenkins{3},sonarqube{2}
|
||||
format: ""
|
||||
- field: name
|
||||
note: Pipeline名称
|
||||
range: GitLab-Server-1,GitLab-Server-2,GitLab-Server-3,GitLab-Test-Server,GitLab-Dev-Server,Jenkins-CI,Jenkins-CD,Jenkins-Test,SonarQube-Main,SonarQube-QA
|
||||
format: ""
|
||||
- field: url
|
||||
note: Pipeline服务器URL
|
||||
range: http://gitlab1.test.com,http://gitlab2.test.com,http://gitlab3.test.com,http://gitlab-test.example.com,http://gitlab-dev.example.com,http://jenkins1.test.com,http://jenkins2.test.com,http://jenkins-test.test.com,http://sonar1.test.com,http://sonar2.test.com
|
||||
format: ""
|
||||
- field: account
|
||||
note: 账户名称
|
||||
range: admin,gitlab_user,jenkins_admin,sonar_user,test_user,dev_user,ci_user,cd_user,qa_user,ops_user
|
||||
format: ""
|
||||
- field: password
|
||||
note: 密码
|
||||
range: admin123,gitlab123,jenkins123,sonar123,test123,dev123,ci123,cd123,qa123,ops123
|
||||
format: ""
|
||||
- field: token
|
||||
note: API Token
|
||||
range: glpat-xxxxxxxxxxxxxxxxxxxx,jenkins-token-xxxxxxxx,sonar-token-xxxxxxxx,[]{7}
|
||||
format: ""
|
||||
- field: private
|
||||
note: 私钥
|
||||
range: '[]{10}'
|
||||
format: ""
|
||||
- field: instanceID
|
||||
note: 实例ID
|
||||
range: 0{3},1-3{7}
|
||||
format: ""
|
||||
- field: createdBy
|
||||
note: 创建者
|
||||
range: admin{5},system{3},user1,user2
|
||||
format: ""
|
||||
- field: createdDate
|
||||
note: 创建时间
|
||||
range: (Y-2)-(Y):30D
|
||||
format: YYYY-MM-DD hh:mm:ss
|
||||
- field: editedBy
|
||||
note: 修改者
|
||||
range: admin{3},user1{3},user2{2},[]{2}
|
||||
format: ""
|
||||
- field: editedDate
|
||||
note: 修改时间
|
||||
range: (Y-1)-(Y):15D
|
||||
format: YYYY-MM-DD hh:mm:ss
|
||||
- field: deleted
|
||||
note: 是否删除
|
||||
range: '0{9},1{1}'
|
||||
format: ""
|
||||
Reference in New Issue
Block a user