From 2f8cb567bd01e44d7e3ac23d9a53bb4100e7d2d9 Mon Sep 17 00:00:00 2001 From: liugang Date: Sat, 20 Sep 2025 12:39:17 +0800 Subject: [PATCH] * [misc] Enhance unit tests for gitlabModel::apiGetSingleTag() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../gitlab/test/lib/gitlab.unittest.class.php | 9 ++-- module/gitlab/test/model/apigetsingletag.php | 47 +++++++++++-------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/module/gitlab/test/lib/gitlab.unittest.class.php b/module/gitlab/test/lib/gitlab.unittest.class.php index 7806dcc460..ea0805642f 100755 --- a/module/gitlab/test/lib/gitlab.unittest.class.php +++ b/module/gitlab/test/lib/gitlab.unittest.class.php @@ -212,17 +212,20 @@ class gitlabTest } /** - * Api get signle tag. + * Test apiGetSingleTag method. * * @param int $gitlabID * @param int $projectID * @param string $tag * @access public - * @return object + * @return mixed */ public function apiGetSingleTagTest($gitlabID, $projectID, $tag) { - return $this->gitlab->apiGetSingleTag($gitlabID, $projectID, $tag); + $result = $this->gitlab->apiGetSingleTag($gitlabID, $projectID, $tag); + if(dao::isError()) return dao::getError(); + + return $result; } /** diff --git a/module/gitlab/test/model/apigetsingletag.php b/module/gitlab/test/model/apigetsingletag.php index ee93d01a8d..6940813594 100755 --- a/module/gitlab/test/model/apigetsingletag.php +++ b/module/gitlab/test/model/apigetsingletag.php @@ -1,32 +1,41 @@ #!/usr/bin/env php apiGetSingleTag(); +title=测试 gitlabModel::apiGetSingleTag(); timeout=0 -cid=1 +cid=0 -- 查询正确的tag信息属性name @tag3 -- 使用不存在的gitlabID查询tag信息 @0 -- 使用不存在的projectID查询tag信息属性message @404 Project Not Found -- 使用不存在的tag名称查询tag信息属性message @404 Tag Not Found +- 执行gitlabTest模块的apiGetSingleTagTest方法,参数是1, 2, 'tag3' 属性name @tag3 +- 执行gitlabTest模块的apiGetSingleTagTest方法,参数是0, 2, 'tag3' @0 +- 执行gitlabTest模块的apiGetSingleTagTest方法,参数是1, 0, 'tag3' 属性message @404 Project Not Found +- 执行gitlabTest模块的apiGetSingleTagTest方法,参数是1, 2, 'nonexistent' 属性message @404 Tag Not Found +- 执行gitlabTest模块的apiGetSingleTagTest方法,参数是1, 2, '' 属性message @404 Tag Not Found +- 执行gitlabTest模块的apiGetSingleTagTest方法,参数是-1, -1, 'tag' @0 +- 执行gitlabTest模块的apiGetSingleTagTest方法,参数是1, 2, 'tag@special' 属性message @404 Tag Not Found */ -zenData('pipeline')->gen(5); +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/lib/gitlab.unittest.class.php'; -$gitlab = new gitlabTest(); +$table = zenData('pipeline'); +$table->id->range('1-10'); +$table->name->range('gitlab{10}'); +$table->url->range('http://localhost/gitlab'); +$table->token->range('token{10}'); +$table->type->range('gitlab'); +$table->gen(5); -$tag1 = $gitlab->apiGetSingleTagTest(1, 2, 'tag3'); -$tag2 = $gitlab->apiGetSingleTagTest(0, 2, 'tag3'); -$tag3 = $gitlab->apiGetSingleTagTest(1, 0, 'tag3'); -$tag4 = $gitlab->apiGetSingleTagTest(1, 2, '0'); +su('admin'); -r($tag1) && p('name') && e('tag3'); // 查询正确的tag信息 -r($tag2) && p() && e('0'); // 使用不存在的gitlabID查询tag信息 -r($tag3) && p('message') && e('404 Project Not Found'); // 使用不存在的projectID查询tag信息 -r($tag4) && p('message') && e('404 Tag Not Found'); // 使用不存在的tag名称查询tag信息 \ No newline at end of file +$gitlabTest = new gitlabTest(); + +r($gitlabTest->apiGetSingleTagTest(1, 2, 'tag3')) && p('name') && e('tag3'); +r($gitlabTest->apiGetSingleTagTest(0, 2, 'tag3')) && p() && e('0'); +r($gitlabTest->apiGetSingleTagTest(1, 0, 'tag3')) && p('message') && e('404 Project Not Found'); +r($gitlabTest->apiGetSingleTagTest(1, 2, 'nonexistent')) && p('message') && e('404 Tag Not Found'); +r($gitlabTest->apiGetSingleTagTest(1, 2, '')) && p('message') && e('404 Tag Not Found'); +r($gitlabTest->apiGetSingleTagTest(-1, -1, 'tag')) && p() && e('0'); +r($gitlabTest->apiGetSingleTagTest(1, 2, 'tag@special')) && p('message') && e('404 Tag Not Found'); \ No newline at end of file