From e50ff3f699c514e7adeb8f9ad2ae987913589673 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Thu, 11 Jan 2024 17:28:16 +0800 Subject: [PATCH] + Add unit test case for gitlab->getFileLastCommit. --- module/gitlab/test/gitlab.class.php | 17 +++++++ .../gitlab/test/model/getfilelastcommit.php | 46 +++++++++++-------- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/module/gitlab/test/gitlab.class.php b/module/gitlab/test/gitlab.class.php index 4e1224d42c..05e27e4047 100644 --- a/module/gitlab/test/gitlab.class.php +++ b/module/gitlab/test/gitlab.class.php @@ -411,4 +411,21 @@ class gitlabTest if(isset($result->errors)) return array_column($result->errors, 'message'); return $result->data->project->repository->tree; } + + /** + * Test getFileLastCommit method. + * + * @param string $path + * @param string $branch + * @access public + * @return object|null|array + */ + public function getFileLastCommitTest(string $path, string $branch): object|array|null + { + $repo = $this->gitlab->loadModel('repo')->getByID(1); + $result = $this->gitlab->getFileLastCommit($repo, $path, $branch); + if(!$result) return $result; + if(isset($result->errors)) return array_column($result->errors, 'message'); + return $result; + } } diff --git a/module/gitlab/test/model/getfilelastcommit.php b/module/gitlab/test/model/getfilelastcommit.php index b477d1c057..2d49b05547 100644 --- a/module/gitlab/test/model/getfilelastcommit.php +++ b/module/gitlab/test/model/getfilelastcommit.php @@ -10,29 +10,39 @@ title=测试 gitlabModel::getFileLastCommit(); timeout=0 cid=1 -- 获取版本库1 unitfile文件最后一次提交信息 - - 属性message @unitfile - - 属性authorName @Administrator -- 获取版本库1 public文件夹最后一次提交信息 - - 属性message @2023-12-21 - - 属性authorName @Administrator -- 获取版本库1 public文件夹最后一次提交信息 - - 属性message @getFileLastCommit单测 - - 属性authorName @Administrator +- 空的路径和分支 @0 +- 错误的分支 @0 +- 正确的分支属性sha @1b9405639ddef9585b3743b0637b4f79775409b7 +- 错误的路径 @0 +- 正确的路径属性sha @2e0dd521b4a29930d5670a2c142a4400d7cffc1a +- 带/的路径属性sha @0fd3978da3be5969ef39ff2517cc69cb3a23811c +- 带/的路径属性sha @0fd3978da3be5969ef39ff2517cc69cb3a23811c */ zdTable('pipeline')->gen(5); -zdTable('repo')->config('repo')->gen(5); +zdTable('repo')->config('repo')->gen(1); $gitlab = new gitlabTest(); -$repoID = 1; -$path = 'unitfile'; -$path2 = 'public'; -$path3 = 'getfilelastcommit'; -$branch = 'branch1'; +$path = ''; +$branch = ''; +r($gitlab->getFileLastCommitTest($path, $branch)) && p() && e('0'); // 空的路径和分支 -r($gitlab->getFileLastCommitTest($repoID, $path)) && p('message,authorName') && e('unitfile,Administrator'); //获取版本库1 unitfile文件最后一次提交信息 -r($gitlab->getFileLastCommitTest($repoID, $path2)) && p('message,authorName') && e('2023-12-21,Administrator'); //获取版本库1 public文件夹最后一次提交信息 -r($gitlab->getFileLastCommitTest($repoID, $path3, $branch)) && p('message,authorName') && e('getFileLastCommit单测,Administrator'); //获取版本库1 public文件夹最后一次提交信息 +$branch = 'test_error'; +r($gitlab->getFileLastCommitTest($path, $branch)) && p() && e('0'); // 错误的分支 + +$branch = 'master'; +r($gitlab->getFileLastCommitTest($path, $branch)) && p('sha') && e('1b9405639ddef9585b3743b0637b4f79775409b7'); // 正确的分支 + +$path = 'test_error'; +r($gitlab->getFileLastCommitTest($path, $branch)) && p() && e('0'); // 错误的路径 + +$path = 'README.md'; +r($gitlab->getFileLastCommitTest($path, $branch)) && p('sha') && e('2e0dd521b4a29930d5670a2c142a4400d7cffc1a'); // 正确的路径 + +$path = '/public'; +r($gitlab->getFileLastCommitTest($path, $branch)) && p('sha') && e('0fd3978da3be5969ef39ff2517cc69cb3a23811c'); // 带/的路径 + +$path = '/public/'; +r($gitlab->getFileLastCommitTest($path, $branch)) && p('sha') && e('0fd3978da3be5969ef39ff2517cc69cb3a23811c'); // 带/的路径