From f85ee5881b8b396f9bc467e101c71c66ff77fb97 Mon Sep 17 00:00:00 2001 From: zenggang Date: Thu, 4 Jan 2024 03:18:13 +0000 Subject: [PATCH] * Add repo unit test. --- module/repo/model.php | 4 +- .../repo/test/model/getgitlabfilesbypath.php | 47 +++++++++++++++++++ module/repo/test/model/gethistoryrevision.php | 33 +++++++++++++ module/repo/test/model/gettreebygraphql.php | 40 ++++++++++++++++ module/repo/test/repo.class.php | 21 +++++++++ 5 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 module/repo/test/model/getgitlabfilesbypath.php create mode 100644 module/repo/test/model/gethistoryrevision.php create mode 100644 module/repo/test/model/gettreebygraphql.php diff --git a/module/repo/model.php b/module/repo/model.php index b96d198d1a..eb6d2754fb 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -2516,9 +2516,9 @@ class repoModel extends model * @param bool $withCommit * @param string $condition * @access public - * @return string|false + * @return string|object|false */ - public function getHistoryRevision(int $repoID, string $revision, bool $withCommit = false, string $condition = 'eq'): string|false + public function getHistoryRevision(int $repoID, string $revision, bool $withCommit = false, string $condition = 'eq'): string|object|false { $field = $withCommit ? 'revision, commit' : 'revision'; return $this->dao->select($field)->from(TABLE_REPOHISTORY) diff --git a/module/repo/test/model/getgitlabfilesbypath.php b/module/repo/test/model/getgitlabfilesbypath.php new file mode 100644 index 0000000000..1da81e9910 --- /dev/null +++ b/module/repo/test/model/getgitlabfilesbypath.php @@ -0,0 +1,47 @@ +#!/usr/bin/env php +getGitlabFilesByPath(); +timeout=0 +cid=1 + +- 获取gitlab类型版本库1的master分支文件列表 + - 第0条的name属性 @public + - 第0条的kind属性 @dir +- 获取gitlab类型版本库1的master分支文件列表数量 @1 +- 获取gitlab类型版本库1的master分支public路径下文件列表 + - 第0条的name属性 @index.html + - 第0条的kind属性 @file +- 获取gitlab类型版本库1的master分支public路径下文件列表数量 @1 +- 获取gitlab类型版本库1的branch1分支文件列表 + - 第2条的name属性 @README.md + - 第2条的kind属性 @file +- 获取gitlab类型版本库1的brnach1分支文件列表数量 @1 + +*/ + +zdTable('pipeline')->gen(5); +zdTable('repo')->config('repo')->gen(5); + +$repoIds = array(1); +$paths = array('', 'public'); +$branches = array('master', 'branch1'); + +$repo = new repoTest(); + +$result = $repo->getGitlabFilesByPathTest($repoIds[0], $paths[0], $branches[0]); +r($result) && p('0:name,kind') && e('public,dir'); // 获取gitlab类型版本库1的master分支文件列表 +r(count($result) > 3) && p() && e('1'); // 获取gitlab类型版本库1的master分支文件列表数量 + +$result = $repo->getGitlabFilesByPathTest($repoIds[0], $paths[1], $branches[0]); +r($result) && p('0:name,kind') && e('index.html,file'); // 获取gitlab类型版本库1的master分支public路径下文件列表 +r(count($result) > 1) && p() && e('1'); // 获取gitlab类型版本库1的master分支public路径下文件列表数量 + +$result = $repo->getGitlabFilesByPathTest($repoIds[0], $paths[0], $branches[1]); +r($result) && p('2:name,kind') && e('README.md,file'); // 获取gitlab类型版本库1的branch1分支文件列表 +r(count($result) > 2) && p() && e('1'); // 获取gitlab类型版本库1的brnach1分支文件列表数量 diff --git a/module/repo/test/model/gethistoryrevision.php b/module/repo/test/model/gethistoryrevision.php new file mode 100644 index 0000000000..6251752d51 --- /dev/null +++ b/module/repo/test/model/gethistoryrevision.php @@ -0,0 +1,33 @@ +#!/usr/bin/env php +config('repo')->gen(4); +zdTable('repohistory')->config('repohistory')->gen(3); + +$repoModel = $tester->loadModel('repo'); + +$repoID = 3; +$revision = 'd30919bdb9b4cf8e2698f4a6a30e41910427c01c'; +$withCommit = true; +$condition = 'lt'; + +r($repoModel->getHistoryRevision($repoID, $revision)) && p() && e('d30919bdb9b4cf8e2698f4a6a30e41910427c01c'); //查询提交记录版本号 +r($repoModel->getHistoryRevision($repoID, $revision, $withCommit)) && p('revision,commit') && e('d30919bdb9b4cf8e2698f4a6a30e41910427c01c,2'); //查询提交记录版本号withCommmit参数为true +r($repoModel->getHistoryRevision($repoID, $revision, $withCommit, $condition)) && p('revision,commit') && e('0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb,1'); //查询提交记录版本号withCommmit参数为true diff --git a/module/repo/test/model/gettreebygraphql.php b/module/repo/test/model/gettreebygraphql.php new file mode 100644 index 0000000000..249867beb1 --- /dev/null +++ b/module/repo/test/model/gettreebygraphql.php @@ -0,0 +1,40 @@ +#!/usr/bin/env php +getTreeByGraphql(); +timeout=0 +cid=1 + +- 获取gitlab类型版本库1的master分支文件夹列表第0条的name属性 @public +- 获取gitlab类型版本库1的master分支文件列表第2条的name属性 @sonar-project.properties +- 获取gitlab类型版本库1的master分支public路径下文件夹列表数量 @0 +- 获取gitlab类型版本库1的master分支public路径下文件列表第0条的name属性 @index.html +- 获取gitlab类型版本库1的branch1分支文件夹列表第0条的name属性 @public +- 获取gitlab类型版本库1的branch1分支文件列表第1条的name属性 @README.md + +*/ + +zdTable('pipeline')->gen(5); +zdTable('repo')->config('repo')->gen(5); + +$repoIds = array(1); +$paths = array('', 'public'); +$branches = array('master', 'branch1'); +$types = array('trees', 'blobs'); + +$repo = new repoTest(); + +r($repo->getTreeByGraphqlTest($repoIds[0], $paths[0], $branches[0], $types[0])) && p('0:name') && e('public'); // 获取gitlab类型版本库1的master分支文件夹列表 +r($repo->getTreeByGraphqlTest($repoIds[0], $paths[0], $branches[0], $types[1])) && p('2:name') && e('sonar-project.properties'); // 获取gitlab类型版本库1的master分支文件列表 + +$result = $repo->getTreeByGraphqlTest($repoIds[0], $paths[1], $branches[0], $types[0]); +r(count($result)) && p() && e('0'); // 获取gitlab类型版本库1的master分支public路径下文件夹列表数量 +r($repo->getTreeByGraphqlTest($repoIds[0], $paths[1], $branches[0], $types[1])) && p('0:name') && e('index.html'); // 获取gitlab类型版本库1的master分支public路径下文件列表 + +r($repo->getTreeByGraphqlTest($repoIds[0], $paths[0], $branches[1], $types[0])) && p('0:name') && e('public'); // 获取gitlab类型版本库1的branch1分支文件夹列表 +r($repo->getTreeByGraphqlTest($repoIds[0], $paths[0], $branches[1], $types[1])) && p('1:name') && e('README.md'); // 获取gitlab类型版本库1的branch1分支文件列表 \ No newline at end of file diff --git a/module/repo/test/repo.class.php b/module/repo/test/repo.class.php index 9472d41c82..1e50232a94 100644 --- a/module/repo/test/repo.class.php +++ b/module/repo/test/repo.class.php @@ -709,4 +709,25 @@ class repoTest $result = $this->objectModel->filterProject($products, $projects); return $result; } + + public function getGitlabFilesByPathTest(int $repoID, string $path = '', string $branch = '') + { + $repo = $this->objectModel->getByID($repoID); + $result = $this->objectModel->getGitlabFilesByPath($repo, $path, $branch); + + if(dao::isError()) return dao::getError(); + + return $result; + } + + public function getTreeByGraphqlTest(int $repoID, string $path = '', string $branch = '', string $type = 'blobs') + { + $repo = $this->objectModel->getByID($repoID); + $result = $this->objectModel->getTreeByGraphql($repo, $path, $branch, $type); + + if(dao::isError()) return dao::getError(); + + return $result; + } + }