* Add unit case.
This commit is contained in:
+68
-7
@@ -22,12 +22,23 @@ class ciTest
|
||||
return $lang->devops->menu->code;
|
||||
}
|
||||
|
||||
public function getCompileByID($compileID)
|
||||
{
|
||||
global $tester;
|
||||
return $tester->dao->select('compile.*, job.engine,job.pipeline, pipeline.name as jenkinsName,job.server,pipeline.url,pipeline.account,pipeline.token,pipeline.password')
|
||||
->from(TABLE_COMPILE)->alias('compile')
|
||||
->leftJoin(TABLE_JOB)->alias('job')->on('compile.job=job.id')
|
||||
->leftJoin(TABLE_PIPELINE)->alias('pipeline')->on('job.server=pipeline.id')
|
||||
->where('compile.id')->eq($compileID)
|
||||
->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync compile status.
|
||||
*
|
||||
* @param int $jobID
|
||||
* @access public
|
||||
* @return string
|
||||
* @return string|object
|
||||
*/
|
||||
public function syncCompileStatusTest($jobID)
|
||||
{
|
||||
@@ -41,12 +52,7 @@ class ciTest
|
||||
->andWhere('compileStatus')->eq('created')
|
||||
->fetchPairs();
|
||||
|
||||
$compile = $tester->dao->select('compile.*, job.engine,job.pipeline, pipeline.name as jenkinsName,job.server,pipeline.url,pipeline.account,pipeline.token,pipeline.password')
|
||||
->from(TABLE_COMPILE)->alias('compile')
|
||||
->leftJoin(TABLE_JOB)->alias('job')->on('compile.job=job.id')
|
||||
->leftJoin(TABLE_PIPELINE)->alias('pipeline')->on('job.server=pipeline.id')
|
||||
->where('compile.id')->eq($compileID)
|
||||
->fetch();
|
||||
$compile = $this->getCompileByID($compileID);
|
||||
|
||||
$this->objectModel->syncCompileStatus($compile, $notCompileMR);
|
||||
$compile = $tester->loadModel('compile')->getByID($compileID);
|
||||
@@ -54,4 +60,59 @@ class ciTest
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $compile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync gitlab task status.
|
||||
*
|
||||
* @param int $jobID
|
||||
* @access public
|
||||
* @return string|bool
|
||||
*/
|
||||
public function syncGitlabTaskStatusTest($jobID)
|
||||
{
|
||||
global $tester;
|
||||
$tester->loadModel('job')->exec($jobID);
|
||||
$compileID = $tester->dao->select('id')->from(TABLE_COMPILE)->orderBy('id_desc')->fetch('id');
|
||||
$compile = $this->getCompileByID($compileID);
|
||||
|
||||
$this->objectModel->syncGitlabTaskStatus($compile);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update build status.
|
||||
*
|
||||
* @param int $compileID
|
||||
* @param string $status
|
||||
* @access public
|
||||
* @return string|object
|
||||
*/
|
||||
public function updateBuildStatusTest($compileID, $status)
|
||||
{
|
||||
$compile = $this->getCompileByID($compileID);
|
||||
$this->objectModel->updateBuildStatus($compile, $status);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
global $tester;
|
||||
$compile = $tester->loadModel('compile')->getByID($compileID);
|
||||
return $compile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send request.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $data
|
||||
* @param string $userPWD
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function sendRequestTest($url, $data, $userPWD)
|
||||
{
|
||||
$return = $this->objectModel->sendRequest($url, $data, $userPWD);
|
||||
return $return ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/ci.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 ciModel->sendRequest();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
成功执行jenkins构建 >> 1
|
||||
错误的密码执行jenkins构建 >> 0
|
||||
空的参数执行jenkins构建 >> 1
|
||||
错误的路径执行jenkins构建 >> 0
|
||||
|
||||
*/
|
||||
|
||||
$ci = new ciTest();
|
||||
|
||||
$url = 'http://10.0.1.161:58080/job/dave/buildWithParameters/api/json';
|
||||
$errorUrl = 'http://10.0.1.161:58080/job/test/buildWithParameters/api/json';
|
||||
|
||||
$userPWD = 'admin:1196c85ba525a268570df9da627e3a7b2d';
|
||||
$errorPWD = 'admin:1';
|
||||
|
||||
$emptyData = new stdclass();
|
||||
|
||||
$normalData = new stdclass();
|
||||
$normalData->PARAM_TAG = 'tag_test1';
|
||||
|
||||
r($ci->sendRequestTest($url, $normalData, $userPWD)) && p() && e('1'); //成功执行jenkins构建
|
||||
r($ci->sendRequestTest($url, $normalData, $errorPWD)) && p() && e('0'); //错误的密码执行jenkins构建
|
||||
r($ci->sendRequestTest($url, $emptyData, $userPWD)) && p() && e('1'); //空的参数执行jenkins构建
|
||||
r($ci->sendRequestTest($errorUrl, $normalData, $userPWD)) && p() && e('0'); //错误的路径执行jenkins构建
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/ci.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 ciModel->syncGitlabTaskStatus();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
同步gitlab构建结果 >> 1
|
||||
|
||||
*/
|
||||
|
||||
$ci = new ciTest();
|
||||
|
||||
r($ci->syncGitlabTaskStatusTest(2)) && p() && e(1); //同步jenkins构建结果
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/ci.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 ciModel->updateBuildStatus();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
更新构建任务状态为构建中 >> building
|
||||
更新构建任务状态为成功 >> success
|
||||
更新构建任务状态为失败 >> failure
|
||||
|
||||
*/
|
||||
|
||||
$ci = new ciTest();
|
||||
|
||||
r($ci->updateBuildStatusTest(1, 'building')) && p('status') && e('building'); //更新构建任务状态为构建中
|
||||
r($ci->updateBuildStatusTest(1, 'success')) && p('status') && e('success'); //更新构建任务状态为成功
|
||||
r($ci->updateBuildStatusTest(1, 'failure')) && p('status') && e('failure'); //更新构建任务状态为失败
|
||||
@@ -37,6 +37,9 @@ switch($argv[1])
|
||||
case 'caselib':
|
||||
ztfRun('model/caselib');
|
||||
break;
|
||||
case 'ci':
|
||||
ztfRun('model/ci');
|
||||
break;
|
||||
case 'company':
|
||||
ztfRun('model/company');
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user