* Add gitlab unit test.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::apiErrorHandling();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 错误处理1 @错误1
|
||||
- 错误处理2 @保存失败,群组URL路径已经被使用。
|
||||
- 错误处理3第name条的0属性 @已经被使用
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->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
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->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信息
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/gitlab.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试gitlabModel->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更新代码库的代码地址
|
||||
Reference in New Issue
Block a user