* Add unit test.

This commit is contained in:
liyuchun
2022-05-07 01:22:13 +00:00
parent 8e01d7111e
commit bc11d6a8a0
7 changed files with 112 additions and 11 deletions
+1 -1
View File
@@ -486,7 +486,7 @@ class jobModel extends model
}
/**
* Exec jenkins pipeline.
* Exec jenkins pipeline.
*
* @param object $job
* @param object $repo
+57
View File
@@ -0,0 +1,57 @@
<?php
class ciTest
{
public function __construct()
{
global $tester;
$this->objectModel = $tester->loadModel('ci');
}
/**
* Set menu.
*
* @access public
* @return array
*/
public function setMenuTest()
{
$_SESSION['repoID'] = 1;
$this->objectModel->setMenu();
global $lang;
return $lang->devops->menu->code;
}
/**
* Sync compile status.
*
* @param int $jobID
* @access public
* @return string
*/
public function syncCompileStatusTest($jobID)
{
global $tester;
$tester->loadModel('job')->exec($jobID);
$compileID = $tester->dao->select('id')->from(TABLE_COMPILE)->orderBy('id_desc')->fetch('id');
$notCompileMR = $tester->dao->select('id,jobID')
->from(TABLE_MR)
->where('jobID')->gt(0)
->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();
$this->objectModel->syncCompileStatus($compile, $notCompileMR);
$compile = $tester->loadModel('compile')->getByID($compileID);
if(dao::isError()) return dao::getError();
return $compile;
}
}
+6
View File
@@ -41,6 +41,12 @@ fields:
- field: engine
note: "引擎"
range: jenkins,gitlab
- field: server
note: "服务器ID"
range: 3,1
- field: pipeline
note: "流水线"
range: dave,[{"project":"1569"}]
- field: triggerType
note: "触发方式"
range: tag,commit,schedule
+9 -9
View File
@@ -3,24 +3,24 @@ author: Zeng gang
version: "1.0"
fields:
- field: id
range: 1-2
range: 1-3
- field: type
range: gitlab,sonarqube
range: gitlab,sonarqube,jenkins
- field: name
range: gitlab服务器,sonarqube服务器
range: gitlab服务器,sonarqube服务器,jenkins服务器
- field: url
range: [http://192.168.1.161:51080],[http://192.168.1.161:59001]
range: [http://10.0.1.161:51080],[http://10.0.1.161:59001],[http://10.0.1.161:58080]
- field: account
range: [],[admin]
range: [],[admin]{2}
- field: password
range: [],[UDJzc3cwcmQ=]
range: [],[UDJzc3cwcmQ=],[]
- field: token
range: x88fZokrp5hShia2jyBN,YWRtaW46UDJzc3cwcmQ=
range: x88fZokrp5hShia2jyBN,YWRtaW46UDJzc3cwcmQ=,1196c85ba525a268570df9da627e3a7b2d
- field: private
range: 08bcc98f75d7d40053dc80722bdc117b,228b25587479f2fc7570428e8bcbabdc
range: 08bcc98f75d7d40053dc80722bdc117b,228b25587479f2fc7570428e8bcbabdc,ec8e41481723685d9106c88be5967c41
- field: createdBy
range: admin
- field: createdDate
range: [2021-12-09 11:23:35],[2022-01-12 08:47:37]
range: [2021-12-09 11:23:35],[2022-01-12 08:47:37],[2022-01-12 08:47:37]
- field: deleted
range: 0
+1 -1
View File
@@ -105,7 +105,7 @@ $builder->webhook = array('rows' => 7, 'extends' => array('webhook'));
$builder->entry = array('rows' => 1, 'extends' => array('entry'));
$builder->weeklyreport = array('rows' => 10, 'extends' => array('weeklyreport'));
$builder->pipeline = array('rows' => 2, 'extends' => array('pipeline'));
$builder->pipeline = array('rows' => 3, 'extends' => array('pipeline'));
$builder->holiday = array('rows' => 100, 'extends' => array('holiday'));
$builder->repo = array('rows' => 1, 'extends' => array('repo'));
$builder->job = array('rows' => 2, 'extends' => array('job'));
+19
View File
@@ -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->setMenu();
cid=1
pid=1
替换devops模块的参数 >> 代码|repo|browse|repoID=1
*/
$ci = new ciTest();
r($ci->setMenuTest()) && p('link') && e('代码|repo|browse|repoID=1'); //替换devops模块导航的参数
+19
View File
@@ -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->syncCompileStatus();
cid=1
pid=1
同步jenkins构建结果 >> created
*/
$ci = new ciTest();
r($ci->syncCompileStatusTest(1)) && p('status') && e('created'); //同步jenkins构建结果