diff --git a/module/repo/test/model/creategitlabrepo.php b/module/repo/test/model/creategitlabrepo.php new file mode 100644 index 0000000000..6ddeadbe4b --- /dev/null +++ b/module/repo/test/model/creategitlabrepo.php @@ -0,0 +1,42 @@ +#!/usr/bin/env php +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为空时 \ No newline at end of file diff --git a/module/repo/test/model/createrepo.php b/module/repo/test/model/createrepo.php new file mode 100644 index 0000000000..349334f771 --- /dev/null +++ b/module/repo/test/model/createrepo.php @@ -0,0 +1,45 @@ +#!/usr/bin/env php +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分支 + diff --git a/module/repo/test/model/deleterepo.php b/module/repo/test/model/deleterepo.php new file mode 100644 index 0000000000..2d1b58b0cd --- /dev/null +++ b/module/repo/test/model/deleterepo.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +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版本库 \ No newline at end of file diff --git a/module/repo/test/model/getapposediff.php b/module/repo/test/model/getapposediff.php new file mode 100644 index 0000000000..3e3bfe8d45 --- /dev/null +++ b/module/repo/test/model/getapposediff.php @@ -0,0 +1,39 @@ +#!/usr/bin/env php +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代码库对比信息文件 \ No newline at end of file diff --git a/module/repo/test/model/saveexistcommits4branch.php b/module/repo/test/model/saveexistcommits4branch.php new file mode 100644 index 0000000000..216620fea8 --- /dev/null +++ b/module/repo/test/model/saveexistcommits4branch.php @@ -0,0 +1,36 @@ +#!/usr/bin/env php +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表记录数量 diff --git a/module/repo/test/repo.class.php b/module/repo/test/repo.class.php index b3dd598c1d..2ddb33fc51 100644 --- a/module/repo/test/repo.class.php +++ b/module/repo/test/repo.class.php @@ -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; + } } diff --git a/module/repo/test/yaml/repobranch.yaml b/module/repo/test/yaml/repobranch.yaml new file mode 100644 index 0000000000..e4aefbc8b0 --- /dev/null +++ b/module/repo/test/yaml/repobranch.yaml @@ -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: "" diff --git a/module/repo/test/yaml/repohistory.yaml b/module/repo/test/yaml/repohistory.yaml index 7227ebc669..abe1c80e39 100644 --- a/module/repo/test/yaml/repohistory.yaml +++ b/module/repo/test/yaml/repohistory.yaml @@ -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