diff --git a/module/gitlab/test/gitlab.class.php b/module/gitlab/test/gitlab.class.php index 4110b4e37e..4ec3b0ebd0 100644 --- a/module/gitlab/test/gitlab.class.php +++ b/module/gitlab/test/gitlab.class.php @@ -367,4 +367,25 @@ class gitlabTest return $result; } + + public function apiErrorHandlingTest(object $response) + { + $result = $this->gitlab->apiErrorHandling($response); + + if(dao::isError()) return dao::getError(); + + return $result; + } + + public function updateCodePathTest(int $gitlabID, int $projectID, int $repoID) + { + $result = $this->gitlab->updateCodePath($gitlabID, $projectID, $repoID); + + if($result) + { + return $this->gitlab->loadModel('repo')->getByID($repoID); + } + + return $result; + } } diff --git a/module/gitlab/test/model/apierrorhandling.php b/module/gitlab/test/model/apierrorhandling.php new file mode 100644 index 0000000000..058fd2e6ab --- /dev/null +++ b/module/gitlab/test/model/apierrorhandling.php @@ -0,0 +1,35 @@ +#!/usr/bin/env php +gen(5); + +$gitlab = new gitlabTest(); + +$response1 = new stdclass(); +$response1->error = '错误1'; + +$response2 = new stdclass(); +$response2->message = 'Failed to save group {:path=>["已经被使用"]}'; + +$response3 = new stdclass(); +$response3->message = new stdclass(); +$response3->message->name = array('已经被使用'); + +r($gitlab->apiErrorHandlingTest($response1)) && p('0') && e('错误1'); //错误处理1 +r($gitlab->apiErrorHandlingTest($response2)) && p('0') && e('保存失败,群组URL路径已经被使用。'); //错误处理2 +r($gitlab->apiErrorHandlingTest($response3)) && p('name:0') && e('已经被使用'); //错误处理3 diff --git a/module/gitlab/test/model/apigetpipeline.php b/module/gitlab/test/model/apigetpipeline.php new file mode 100644 index 0000000000..2bc7d4cb79 --- /dev/null +++ b/module/gitlab/test/model/apigetpipeline.php @@ -0,0 +1,38 @@ +#!/usr/bin/env php +apiGetPipeline(); +timeout=0 +cid=1 + +- 查询正确的pipeline信息 + - 属性iid @60 + - 属性project_id @2 +- 使用不存在的gitlabID查询pipeline信息 @0 +- 使用不存在的projectID查询pipeline信息属性message @404 Project Not Found +- 使用不存在的branch查询pipeline信息 @0 + +*/ + +zdTable('pipeline')->gen(5); + +$gitlab = $tester->loadModel('gitlab'); + +$gitlabID = 1; +$projectID = 2; +$branch = 'master'; + +$pipeline1 = $gitlab->apiGetPipeline($gitlabID, $projectID, $branch); +$pipeline2 = $gitlab->apiGetPipeline(0, $projectID, $branch); +$pipeline3 = $gitlab->apiGetPipeline($gitlabID, 0, $branch); +$pipeline4 = $gitlab->apiGetPipeline($gitlabID, $projectID, 'branch123'); + +r(end($pipeline1)) && p('iid,project_id') && e('60,2'); // 查询正确的pipeline信息 +r($pipeline2) && p() && e('0'); // 使用不存在的gitlabID查询pipeline信息 +r($pipeline3) && p('message') && e('404 Project Not Found'); // 使用不存在的projectID查询pipeline信息 +r($pipeline4) && p() && e('0'); // 使用不存在的branch查询pipeline信息 diff --git a/module/gitlab/test/model/updatecodepath.php b/module/gitlab/test/model/updatecodepath.php new file mode 100644 index 0000000000..0c522cca1c --- /dev/null +++ b/module/gitlab/test/model/updatecodepath.php @@ -0,0 +1,35 @@ +#!/usr/bin/env php +updateCodePath(); +timeout=0 +cid=1 + +- 更新版本库的代码地址属性path @http://gitlabdev.qc.oop.cc/gitlab-instance-76af86df/testhtml +- 使用不存在的gitlabID更新代码库的代码地址 @0 +- 使用不存在的projectID更新代码库的代码地址 @0 + +*/ + +$repo = zdTable('repo')->config('repo'); +$repo->path->range(''); +$repo->gen(4); + +$gitlab = new gitlabTest(); + +$gitlabID = 1; +$projectID = 2; +$repoID = 1; + +$result1 = $gitlab->updateCodePathTest($gitlabID, $projectID, $repoID); +$result2 = $gitlab->updateCodePathTest(0, $projectID, $repoID); +$result3 = $gitlab->updateCodePathTest($gitlabID, 0, $repoID); + +r($result1) && p('path') && e('http://gitlabdev.qc.oop.cc/gitlab-instance-76af86df/testhtml'); // 更新版本库的代码地址 +r($result2) && p() && e('0'); // 使用不存在的gitlabID更新代码库的代码地址 +r($result3) && p() && e('0'); // 使用不存在的projectID更新代码库的代码地址 \ No newline at end of file