* Finish compile module unit test script.

This commit is contained in:
wangyuting
2023-12-29 13:57:38 +08:00
parent 700d9315b7
commit d786c1695a
15 changed files with 197 additions and 10 deletions
+4 -4
View File
@@ -178,8 +178,8 @@ class compileModel extends model
{
/* Get jobs by pipeline. */
$pipeline = json_decode($job->pipeline);
$projectID = isset($pipeline->project) ? $pipeline->project : '';
$jobs = $this->loadModel('gitlab')->apiGetJobs($job->server, $projectID, $compile->queue);
$projectID = isset($pipeline->project) ? $pipeline->project : 0;
$jobs = $this->loadModel('gitlab')->apiGetJobs($job->server, (int)$projectID, $compile->queue);
$this->loadModel('ci');
foreach($jobs as $gitlabJob)
@@ -189,7 +189,7 @@ class compileModel extends model
if(empty($gitlabJob->duration)) $gitlabJob->duration = '-';
$logs .= "<font style='font-weight:bold'>&gt;&gt;&gt; Job: $gitlabJob->name, Stage: $gitlabJob->stage, Status: $gitlabJob->status, Duration: $gitlabJob->duration Sec\r\n </font>";
$logs .= "Job URL: <a href=\"$gitlabJob->web_url\" target='_blank'>$gitlabJob->web_url</a> \r\n";
$logs .= $this->ci->transformAnsiToHtml($this->gitlab->apiGetJobLog($job->server, $projectID, $gitlabJob->id));
$logs .= $this->ci->transformAnsiToHtml($this->gitlab->apiGetJobLog($job->server, (int)$projectID, $gitlabJob->id));
}
}
@@ -254,7 +254,7 @@ class compileModel extends model
else
{
$server = zget($gitlabPairs, $job->server);
$this->syncGitLabBuildList($server, $job);
$this->syncGitlabBuildList($server, $job);
}
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/compile.class.php';
zdTable('compile')->gen(10);
zdTable('job')->gen(1);
zdTable('job')->config('job')->gen(1);
su('admin');
/**
+1 -1
View File
@@ -4,7 +4,7 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/compile.class.php';
zdTable('compile')->gen(10);
zdTable('job')->gen(1);
zdTable('job')->config('job')->gen(1);
zdTable('repo')->gen(1);
zdTable('pipeline')->gen(1);
su('admin');
+1 -1
View File
@@ -4,7 +4,7 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/compile.class.php';
zdTable('compile')->gen(1);
zdTable('job')->gen(1);
zdTable('job')->config('job')->gen(1);
su('admin');
/**
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
zdTable('compile')->gen(1);
su('admin');
/**
title=测试 compileModel->getByQueue();
cid=1
pid=1
检查当queue存在的时候是否能拿到数据 >> 构建1
检查当queue不存在的时候返回的结果 >> 0
*/
$tester->loadModel('compile');
r($tester->compile->getByQueue('1')) && p('name') && e('构建1'); //检查当queue存在的时候是否能拿到数据
r($tester->compile->getByQueue('2')) && p('name') && e('0'); //检查当queue不存在的时候返回的结果
+1 -1
View File
@@ -4,7 +4,7 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/compile.class.php';
zdTable('compile')->gen(1);
zdTable('job')->gen(1);
zdTable('job')->config('job')->gen(1);
su('admin');
/**
+1 -1
View File
@@ -4,7 +4,7 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/compile.class.php';
zdTable('compile')->gen(1);
zdTable('job')->gen(1);
zdTable('job')->config('job')->gen(1);
su('admin');
/**
+1 -1
View File
@@ -4,7 +4,7 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/compile.class.php';
zdTable('compile')->gen(1);
zdTable('job')->gen(1);
zdTable('job')->config('job')->gen(1);
su('admin');
/**
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
zdTable('job')->config('job')->gen(6);
zdTable('compile')->gen(6);
zdTable('pipeline')->gen(6);
su('admin');
/**
title=测试 compileModel->getLogs();
cid=1
pid=1
- 检查jenkins返回的logs。 @Started by
- 检查gitlab返回的logs。 @<font styl
*/
$compile = $tester->loadModel('compile')->getByID(1);
$job = $tester->loadModel('job')->getByID($compile->job);
r(substr($tester->compile->getLogs($job, $compile), 0, 10)) && p() && e('Started by'); //检查jenkins返回的logs。
$compile = $tester->loadModel('compile')->getByID(2);
$job = $tester->loadModel('job')->getByID($compile->job);
r(substr($tester->compile->getLogs($job, $compile), 0, 10)) && p() && e('<font styl'); //检查gitlab返回的logs。
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
zdTable('compile')->gen(10);
su('admin');
/**
title=测试 compileModel->getSuccessJobs();
cid=1
pid=1
- 检查传入参数为空时候的返回结果。 @0
- 检查传入正确参数时的返回结果。属性1 @1
*/
$tester->loadModel('compile');
r($tester->compile->getSuccessJobs(array())) && p() && e('0'); //检查传入参数为空时候的返回结果。
r($tester->compile->getSuccessJobs(array('1,2,3,4,5'))) && p(1) && e('1'); //检查传入正确参数时的返回结果。
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
$compile = zdTable('compile');
$compile->status->range('``,success,failure,created');
$compile->deleted->range('0,1');
$compile->gen(10);
su('admin');
/**
title=测试 compileModel->getUnexecutedList();
cid=1
pid=1
- 检查返回结果第二条数据的字段内容。
- 第1条的name属性 @构建5
- 第1条的status属性 @~~
- 检查返回结果的数量。 @3
*/
$tester->loadModel('compile');
r($tester->compile->getUnexecutedList()) && p('1:name,status') && e('构建5,~~'); //检查返回结果第二条数据的字段内容。
r(count($tester->compile->getUnexecutedList())) && p() && e('3'); //检查返回结果的数量。
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
zdTable('job')->config('job')->gen(6);
zdTable('compile')->gen(6);
zdTable('pipeline')->gen(6);
su('admin');
/**
title=测试 compileModel->syncCompile();
cid=1
pid=1
- 调用jenkins接口之前job为1的compile数量。 @1
- 调用jenkins接口之后job为1的compile数量。 @17
- 调用gitlab接口之前的compile数量。 @1
- 调用gitlab接口之后的compile数量。 @50
*/
$tester->loadModel('compile');
r(count($tester->compile->getListByJobID(1))) && p() && e(1); //调用jenkins接口之前job为1的compile数量。
$tester->compile->syncCompile(0, 1);
r(count($tester->compile->getListByJobID(1))) && p() && e(17); //调用jenkins接口之后job为1的compile数量。
r(count($tester->compile->getListByJobID(2))) && p() && e(1); //调用gitlab接口之前的compile数量。
$tester->compile->syncCompile(0, 2);
r(count($tester->compile->getListByJobID(2))) && p() && e(50); //调用gitlab接口之后的compile数量。
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
zdTable('job')->config('job')->gen(6);
zdTable('compile')->gen(6);
zdTable('pipeline')->gen(6);
su('admin');
/**
title=测试 compileModel->syncGitlabBuildList();
cid=1
pid=1
- 调用gitlab接口之前的compile数量。 @1
- 调用gitlab接口之后的compile数量。 @50
*/
$tester->loadModel('compile');
$gitlabPairs = $tester->loadModel('pipeline')->getList('gitlab');
$job = $tester->loadModel('job')->getByID(2);
$server = zget($gitlabPairs, $job->server);
r(count($tester->compile->getListByJobID(2))) && p() && e(1); //调用gitlab接口之前的compile数量。
$tester->compile->syncGitlabBuildList($server, $job);
r(count($tester->compile->getListByJobID(2))) && p() && e(50); //调用gitlab接口之后的compile数量。
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
zdTable('job')->config('job')->gen(6);
zdTable('compile')->gen(6);
zdTable('pipeline')->gen(6);
su('admin');
/**
title=测试 compileModel->syncJenkinsBuildList();
cid=1
pid=1
- 调用jenkins接口之前job为1的compile数量。 @1
- 调用jenkins接口之后job为1的compile数量。 @17
*/
$tester->loadModel('compile');
$jenkinsPairs = $tester->loadModel('pipeline')->getList('jenkins');
$job = $tester->loadModel('job')->getByID(1);
$server = zget($jenkinsPairs, $job->server);
r(count($tester->compile->getListByJobID(1))) && p() && e(1); //调用jenkins接口之前job为1的compile数量。
$tester->compile->syncJenkinsBuildList($server, $job);
r(count($tester->compile->getListByJobID(1))) && p() && e(17); //调用jenkins接口之后job为1的compile数量。
+8
View File
@@ -0,0 +1,8 @@
title: table zt_job
desc: "构建任务"
author: automated export
version: "1.0"
fields:
- field: pipeline
note: "流水线"
range: simple-job,`{"project":"2","reference":"master"}`