* Add repo unit test.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel::createGitlabRepo();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 创建gitlab远程版本库 @1
|
||||
- namesapce为空时第namespace条的0属性 @不能为空字符
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$repoTest = new repoTest();
|
||||
|
||||
$repo = new stdclass();
|
||||
$repo->product = '1,2';
|
||||
$repo->projects = '3,4';
|
||||
$repo->name = 'abc&&';
|
||||
$repo->serviceHost = 1;
|
||||
$repo->path = 'unit_test_project17';
|
||||
$repo->desc = 'unit_test_project desc';
|
||||
$repo->namespace = 1;
|
||||
$repo->SCM = 'Gitlab';
|
||||
$repo->acl = '{"acl":"open","groups":[""],"users":[""]}';
|
||||
|
||||
$_SERVER['REQUEST_URI'] = 'http://unittest/';
|
||||
|
||||
$repo->name = 'unitTestProject17';
|
||||
$result = $repoTest->createGitlabRepoTest($repo, $repo->namespace);
|
||||
if(isset($result->id)) $result = true;
|
||||
if(!empty($result->message->name[0]) and $result->message->name[0] == '已经被使用') $result = true;
|
||||
r($result) && p() && e('1'); //创建gitlab远程版本库
|
||||
|
||||
$result = $repoTest->createGitlabRepoTest($repo, 0);
|
||||
r($result->message) && p('namespace:0') && e('不能为空字符'); //namesapce为空时
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel::createRepo();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 使用空的名字创建repo群组 @return false
|
||||
- 使用空的群组URL创建repo群组 @return false
|
||||
- 使用错误repoID创建群组 @0
|
||||
- 通过repoID,projectID,分支对象正确创建GitLab分支 @1
|
||||
- 使用重复的分支信息创建分支第path条的0属性 @已经被使用
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$repoTest = new repoTest();
|
||||
|
||||
$repo = new stdclass();
|
||||
$repo->product = '1,2';
|
||||
$repo->projects = '3,4';
|
||||
$repo->name = 'abc&&';
|
||||
$repo->serviceHost = 1;
|
||||
$repo->path = 'unit_test_project17';
|
||||
$repo->desc = 'unit_test_project desc';
|
||||
$repo->namespace = 1;
|
||||
$repo->SCM = 'Gitlab';
|
||||
$repo->acl = '{"acl":"open","groups":[""],"users":[""]}';
|
||||
|
||||
$_SERVER['REQUEST_URI'] = 'http://unittest/';
|
||||
|
||||
r($repoTest->createRepoTest($repo)) && p('name') && e('名称应该只包含字母数字,破折号,下划线和点。'); //使用不符合规则的名字创建repo群组
|
||||
|
||||
$repo->name = 'unitTestProject17';
|
||||
$result = $repoTest->createRepoTest($repo);
|
||||
if(is_int($result)) $result = true;
|
||||
if(!empty($result->message->name[0]) and $result->message->name[0] == '已经被使用') $result = true;
|
||||
r($result) && p() && e('1'); //通过repoID,projectID,分支对象正确创建GitLab分支
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel::createGitlabRepo();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 删除gitlab版本库
|
||||
- 属性repoCount @0
|
||||
- 属性repoHistoryCount @0
|
||||
- 属性repoBranchCount @0
|
||||
- 属性repoFilesCount @0
|
||||
- 删除gitea版本库
|
||||
- 属性repoCount @0
|
||||
- 属性repoHistoryCount @0
|
||||
- 属性repoBranchCount @0
|
||||
- 属性repoFilesCount @0
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
zdTable('repo')->config('repo')->gen(5);
|
||||
zdTable('repohistory')->config('repohistory')->gen(6);
|
||||
zdTable('repofiles')->config('repofiles')->gen(7);
|
||||
zdTable('repobranch')->config('repobranch')->gen(2);
|
||||
|
||||
$repoTest = new repoTest();
|
||||
$gitlabID = 1;
|
||||
$giteaID = 3;
|
||||
|
||||
r($repoTest->deleteRepoTest($gitlabID)) && p('repoCount,repoHistoryCount,repoBranchCount,repoFilesCount') && e('0,0,0,0'); //删除gitlab版本库
|
||||
r($repoTest->deleteRepoTest($giteaID)) && p('repoCount,repoHistoryCount,repoBranchCount,repoFilesCount') && e('0,0,0,0'); //删除gitea版本库
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel::getApposeDiff();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取gitlab代码库对比信息文件第0条的fileName属性 @.gitlab-ci.yml
|
||||
- 获取gitlab代码库比信息行信息
|
||||
- 属性oldStartLine @0
|
||||
- 属性newStartLine @1
|
||||
- 获取svn代码库对比信息文件第0条的fileName属性 @README.md
|
||||
- 获取svn代码库对比信息文件 @81
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
zdTable('repo')->config('repo')->gen(5);
|
||||
|
||||
$repoTest = new repoTest();
|
||||
$gitlabID = 1;
|
||||
$oldRevision = 'c808480afe22d3a55d94e91c59a8f3170212ade0';
|
||||
$newRevision = '1b9405639ddef9585b3743b0637b4f79775409b7';
|
||||
|
||||
$result = $repoTest->getApposeDiffTest($gitlabID, $oldRevision, $newRevision);
|
||||
r($result) && p('0:fileName') && e('.gitlab-ci.yml'); //获取gitlab代码库对比信息文件
|
||||
r($result[1]->contents[0]) && p('oldStartLine,newStartLine') && e('0,1'); //获取gitlab代码库比信息行信息
|
||||
|
||||
$svnID = 4;
|
||||
$oldRevision = '1';
|
||||
$newRevision = '2';
|
||||
$result = $repoTest->getApposeDiffTest($svnID, $oldRevision, $newRevision);
|
||||
r($result) && p('0:fileName') && e('README.md'); //获取svn代码库对比信息文件
|
||||
r(count($result[0]->contents[0]->lines)) && p() && e('81'); //获取svn代码库对比信息文件
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->saveExistCommits4Branch();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 保存gitea版本库master分支,主分支为main
|
||||
- 第2条的revision属性 @3
|
||||
- 第2条的branch属性 @master
|
||||
- 保存后repobranch表记录数量 @3
|
||||
|
||||
*/
|
||||
|
||||
$dao->exec('truncate table zt_repohistory');
|
||||
$dao->exec('truncate table zt_repobranch');
|
||||
|
||||
zdTable('pipeline')->gen(4);
|
||||
zdTable('repo')->config('repo')->gen(5);
|
||||
zdTable('repohistory')->config('repohistory')->gen(6);
|
||||
zdTable('repofiles')->config('repofiles')->gen(7);
|
||||
zdTable('repobranch')->config('repobranch')->gen(2);
|
||||
|
||||
$repo = new repoTest();
|
||||
|
||||
$giteaID = 3;
|
||||
$branch = 'master';
|
||||
|
||||
$result = $repo->saveExistCommits4BranchTest($giteaID, $branch);
|
||||
r($result) && p('2:revision,branch') && e('3,master'); //保存gitea版本库master分支,主分支为main
|
||||
r(count($result)) && p() && e('3'); //保存后repobranch表记录数量
|
||||
@@ -326,13 +326,14 @@ class repoTest
|
||||
return $this->objectModel->dao->select('*')->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->fetch();
|
||||
}
|
||||
|
||||
public function saveExistCommits4BranchTest($repoID, $branch)
|
||||
public function saveExistCommits4BranchTest(int $repoID, string $branch)
|
||||
{
|
||||
$objects = $this->objectModel->saveExistCommits4Branch($repoID, $branch);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
$result = $this->objectModel->dao->select('*')->from(TABLE_REPOBRANCH)->where('repo')->eq($repoID)->fetchAll();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function updateCommitCountTest(int $repoID, int $count)
|
||||
@@ -796,4 +797,43 @@ class repoTest
|
||||
|
||||
return strpos($path, 'data/repo/unittest_gitea') !== false;
|
||||
}
|
||||
|
||||
public function createRepoTest(object $repo)
|
||||
{
|
||||
$result = $this->objectModel->createRepo($repo);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function createGitlabRepoTest(object $repo, int $namespace)
|
||||
{
|
||||
$result = $this->objectModel->createGitlabRepo($repo, $namespace);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function deleteRepoTest(int $repoID)
|
||||
{
|
||||
$result = $this->objectModel->deleteRepo($repoID);
|
||||
|
||||
$repoCount = $this->objectModel->dao->select('*')->from(TABLE_REPO)->where('id')->eq($repoID)->count();
|
||||
$repoHistoryCount = $this->objectModel->dao->select('*')->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->count();
|
||||
$repoBranchCount = $this->objectModel->dao->select('*')->from(TABLE_REPOBRANCH)->where('repo')->eq($repoID)->count();
|
||||
$repoFilesCount = $this->objectModel->dao->select('*')->from(TABLE_REPOFILES)->where('repo')->eq($repoID)->count();
|
||||
|
||||
return array('repoCount' => $repoCount, 'repoHistoryCount' => $repoHistoryCount, 'repoBranchCount' => $repoBranchCount, 'repoFilesCount' => $repoFilesCount);
|
||||
}
|
||||
|
||||
public function getApposeDiffTest(int $repoID, string $oldRevision, string $newRevision)
|
||||
{
|
||||
$scm = $this->objectModel->app->loadClass('scm');
|
||||
$repo = $this->objectModel->getByID($repoID);
|
||||
$scm->setEngine($repo);
|
||||
$diffs = $scm->diff('', $oldRevision, $newRevision, 'yes', 'isBranchOrTag');
|
||||
|
||||
$diffs = $this->objectModel->getApposeDiff($diffs);
|
||||
return $diffs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
title: table zt_repobranch
|
||||
desc: "代码分支"
|
||||
author: automated export
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: repo
|
||||
note: "代码库ID"
|
||||
range: 3
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: revision
|
||||
note: "代码库版本"
|
||||
range: 2-3
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: branch
|
||||
note: "对应分支"
|
||||
range: master,main
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
@@ -12,7 +12,7 @@ fields:
|
||||
format: ""
|
||||
- field: repo
|
||||
note: "代码库ID"
|
||||
range: "1,3{2},4"
|
||||
range: "1,3{2},4{3}"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
@@ -39,7 +39,7 @@ fields:
|
||||
format: ""
|
||||
- field: committer
|
||||
note: "作者"
|
||||
range: "admin,gitea{2},admin"
|
||||
range: "admin,gitea{2},admin{3}"
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
|
||||
Reference in New Issue
Block a user