From bc11d6a8a0877e5ae3bdb58e6e3c45227a4eb5a8 Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Sat, 7 May 2022 01:22:13 +0000 Subject: [PATCH] * Add unit test. --- module/job/model.php | 2 +- test/class/ci.class.php | 57 +++++++++++++++++++++++++++++ test/data/job.yaml | 6 +++ test/data/pipeline.yaml | 18 ++++----- test/data/zentao/config.php | 2 +- test/model/ci/setmenu.php | 19 ++++++++++ test/model/ci/synccompilestatus.php | 19 ++++++++++ 7 files changed, 112 insertions(+), 11 deletions(-) create mode 100644 test/class/ci.class.php create mode 100644 test/model/ci/setmenu.php create mode 100644 test/model/ci/synccompilestatus.php diff --git a/module/job/model.php b/module/job/model.php index f88120da2a..751924af9e 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -486,7 +486,7 @@ class jobModel extends model } /** - * Exec jenkins pipeline. + * Exec jenkins pipeline. * * @param object $job * @param object $repo diff --git a/test/class/ci.class.php b/test/class/ci.class.php new file mode 100644 index 0000000000..7d00aceb4b --- /dev/null +++ b/test/class/ci.class.php @@ -0,0 +1,57 @@ +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; + } +} diff --git a/test/data/job.yaml b/test/data/job.yaml index 08c13e0738..2d07519293 100644 --- a/test/data/job.yaml +++ b/test/data/job.yaml @@ -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 diff --git a/test/data/pipeline.yaml b/test/data/pipeline.yaml index 60ad7e0b48..c4295ea9d7 100644 --- a/test/data/pipeline.yaml +++ b/test/data/pipeline.yaml @@ -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 diff --git a/test/data/zentao/config.php b/test/data/zentao/config.php index 8f3f9bbd03..d2711081ae 100644 --- a/test/data/zentao/config.php +++ b/test/data/zentao/config.php @@ -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')); diff --git a/test/model/ci/setmenu.php b/test/model/ci/setmenu.php new file mode 100644 index 0000000000..1b2c298dc3 --- /dev/null +++ b/test/model/ci/setmenu.php @@ -0,0 +1,19 @@ +#!/usr/bin/env php +setMenu(); +cid=1 +pid=1 + +替换devops模块的参数 >> 代码|repo|browse|repoID=1 + +*/ + +$ci = new ciTest(); + +r($ci->setMenuTest()) && p('link') && e('代码|repo|browse|repoID=1'); //替换devops模块导航的参数 diff --git a/test/model/ci/synccompilestatus.php b/test/model/ci/synccompilestatus.php new file mode 100644 index 0000000000..80d017226e --- /dev/null +++ b/test/model/ci/synccompilestatus.php @@ -0,0 +1,19 @@ +#!/usr/bin/env php +syncCompileStatus(); +cid=1 +pid=1 + +同步jenkins构建结果 >> created + +*/ + +$ci = new ciTest(); + +r($ci->syncCompileStatusTest(1)) && p('status') && e('created'); //同步jenkins构建结果