* [unittest] adjust gitlab unit test case.

This commit is contained in:
caoyanyi
2025-06-05 16:03:51 +08:00
parent 8e5b35b306
commit a770a36df3
6 changed files with 41 additions and 13 deletions
@@ -263,7 +263,7 @@ class gitlabTest
public function addPushWebhookTest(int $repoID, string $token, int $projectID = 0)
{
$repo = $this->tester->loadModel('repo')->getByID($repoID);
if($projectID) $repo->project = $projectID;
if($projectID) $repo->serviceProject = $projectID;
$result = $this->gitlab->addPushWebhook($repo, $token);
if(is_array($result)) $result = false;
+1 -1
View File
@@ -48,4 +48,4 @@ $result = $gitlab->apiCreateGroup($gitlabID, $group);
if(!empty($result->name) and $result->name == $group->name) $result = true;
if(!empty($result->message) and $result->message == 'Failed to save group {:path=>["已经被使用"]}') $result = true;
r($result) && p() && e('1'); //通过gitlabID,projectID,分支对象正确创建GitLab分支
r($gitlab->apiCreateGroup($gitlabID, $group)) && p('message') && e('Failed to save group {:path=>["已经被使用"]}'); //使用重复的分支信息创建分支
r($gitlab->apiCreateGroup($gitlabID, $group)) && p('message') && e('Failed to save group {:path=>["已经被使用"]}'); //使用重复的分支信息创建分支
+10 -3
View File
@@ -9,6 +9,8 @@ timeout=0
cid=1
- 使用空的userID删除gitlab群组 @0
- 使用错误的gitlabID删除gitlab群组 @404 User Not Found
- 使用错误的userID删除gitlab群组 @404 Not Found
- 使用错误gitlabID删除群组 @0
- 通过gitlabID,projectID,分支对象正确删除GitLab用户 @1
@@ -16,6 +18,8 @@ cid=1
zenData('pipeline')->gen(5);
global $app;
$app->rawMethod = 'browse';
$gitlab = $tester->loadModel('gitlab');
$gitlabID = 1;
@@ -24,12 +28,13 @@ $gitlabID = 1;
$user = new stdclass();
$user->name = 'apiCreatedUser';
$user->username = 'apiuser17';
$user->email = 'apiuser17@test.com';
$user->password = '12345678';
$user->email = time() . 'apiuser17@test.com';
$user->password = '123Qwe!@#';
$gitlab->apiCreateUser($gitlabID, $user);
/* Get userID. */
$gitlabUsers = $gitlab->apiGetUsers($gitlabID);
$userID = 0;
foreach($gitlabUsers as $gitlabUser)
{
if($gitlabUser->account == 'apiuser17')
@@ -40,8 +45,10 @@ foreach($gitlabUsers as $gitlabUser)
}
r($gitlab->apiDeleteUser($gitlabID, 0)) && p() && e('0'); //使用空的userID删除gitlab群组
r($gitlab->apiDeleteUser($gitlabID, 1000)) && p('message') && e('404 User Not Found'); //使用错误的userID删除gitlab群组
r($gitlab->apiDeleteUser($gitlabID, -1)) && p('error') && e('404 Not Found'); //使用错误的userID删除gitlab群组
r($gitlab->apiDeleteUser(0, $userID)) && p() && e('0'); //使用错误gitlabID删除群组
$result = $gitlab->apiDeleteUser($gitlabID, $userID);
if(is_null($result)) $result = true;
r($result) && p() && e('1'); //通过gitlabID,projectID,分支对象正确删除GitLab用户
r($result) && p() && e('1'); //通过gitlabID,projectID,分支对象正确删除GitLab用户
+5 -1
View File
@@ -19,6 +19,10 @@ cid=1
zenData('pipeline')->gen(5);
zenData('oauth')->loadYaml('oauth')->gen(4);
global $app;
$app->rawModule = 'gitlab';
$app->rawMethod = 'browse';
$gitlab = $tester->loadModel('gitlab');
$gitlabID = 1;
@@ -37,4 +41,4 @@ $gitlabID = 1;
$onlyLinked = false;
$orderBy = 'id_asc';
$result = $gitlab->apiGetUsers($gitlabID, $onlyLinked, $orderBy);
r($result) && p('0:account') && e('root'); //通过gitlabID,onlyLinked,按用户名升序获取GitLab用户列表
r($result) && p('0:account') && e('root'); //通过gitlabID,onlyLinked,按用户名升序获取GitLab用户列表
+19 -6
View File
@@ -11,28 +11,35 @@ cid=1
- 使用空的userID创建gitlab群组 @0
- 使用错误gitlabID创建群组 @0
- 通过gitlabID,用户对象正确更新用户名字属性name @apiUpdatedUser
- 通过gitlabID,用户对象错误更新用户名字属性name @404 User Not Found
- 通过gitlabID,用户对象错误更新用户名字属性name @404 Not Found
*/
zenData('pipeline')->gen(5);
global $app;
$app->rawModule = 'gitlab';
$app->rawMethod = 'browse';
$gitlab = $tester->loadModel('gitlab');
$gitlabID = 1;
/* Create user. */
$user = new stdclass();
$user->name = 'apiCreatedUser';
$user->username = 'apiuser17';
$user->email = 'apiuser17@test.com';
$user->password = '12345678';
$user->name = 'apiCreatedUser1';
$user->username = 'apiuser18';
$user->email = 'apiuser18@test.com';
$user->password = '123Qwe!@#';
$gitlab->apiCreateUser($gitlabID, $user);
/* Get userID. */
$gitlabUsers = $gitlab->apiGetUsers($gitlabID);
$userID = 0;
foreach($gitlabUsers as $gitlabUser)
{
if($gitlabUser->account == 'apiuser17')
if($gitlabUser->account == 'apiuser18')
{
$userID = $gitlabUser->id;
break;
@@ -46,4 +53,10 @@ r($gitlab->apiUpdateUser($gitlabID, $user)) && p() && e('0'); //使用空的user
r($gitlab->apiUpdateUser(0, $user)) && p() && e('0'); //使用错误gitlabID创建群组
$user->id = $userID;
r($gitlab->apiUpdateUser($gitlabID, $user)) && p('name') && e('apiUpdatedUser'); //通过gitlabID,用户对象正确更新用户名字
r($gitlab->apiUpdateUser($gitlabID, $user)) && p('name') && e('apiUpdatedUser'); //通过gitlabID,用户对象正确更新用户名字
$user->id = 100000;
r($gitlab->apiUpdateUser($gitlabID, $user)) && p('message') && e('404 User Not Found'); //通过gitlabID,用户对象错误更新用户名字
$user->id = -1;
r($gitlab->apiUpdateUser($gitlabID, $user)) && p('error') && e('404 Not Found'); //通过gitlabID,用户对象错误更新用户名字
+5 -1
View File
@@ -25,6 +25,10 @@ zenData('pipeline')->gen(5);
zenData('oauth')->loadYaml('oauth')->gen(5);
zenData('user')->gen(10);
global $app;
$app->rawModule = 'gitlab';
$app->rawMethod = 'browse';
$gitlab = new gitlabTest();
$gitlabID = 1;
@@ -34,4 +38,4 @@ $matchedUsers = $gitlab->getMatchedUsersTest($gitlabID, $gitlabUsers, $zentaoUse
r($matchedUsers) && p('1:account,zentaoAccount') && e('root,user3'); // 获取gitlab服务器1匹配的用户列表。
r(count($matchedUsers)) && p('') && e('3'); // 获取gitlab服务器1匹配的用户数量。
r($gitlab->getMatchedUsersTest($gitlabID, array(), $zentaoUsers)) && p('') && e('0'); // 当gitlab用户为空时获取gitlab服务器1匹配的用户数量。
r($gitlab->getMatchedUsersTest($gitlabID, $gitlabUsers, array())) && p('4:account,zentaoAccount') && e('user6,user6'); // 当禅道用户为空时获取gitlab服务器1匹配的用户数量。
r($gitlab->getMatchedUsersTest($gitlabID, $gitlabUsers, array())) && p('4:account,zentaoAccount') && e('user6,user6'); // 当禅道用户为空时获取gitlab服务器1匹配的用户数量。