* [misc] Enhance unit tests for repoModel::getRepoListByUrl() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -256,7 +256,10 @@ class repoTest
|
||||
|
||||
public function getRepoListByUrlTest($url = '')
|
||||
{
|
||||
$objects = $this->objectModel->getRepoListByUrl($url = '');
|
||||
// 确保参数是字符串类型,处理null值
|
||||
$url = (string)$url;
|
||||
|
||||
$objects = $this->objectModel->getRepoListByUrl($url);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
@@ -1344,4 +1347,21 @@ class repoTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getRelationByCommit method.
|
||||
*
|
||||
* @param int $repoID
|
||||
* @param string $commit
|
||||
* @param string $type
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getRelationByCommitTest(int $repoID, string $commit, string $type = ''): array
|
||||
{
|
||||
$result = $this->objectModel->getRelationByCommit($repoID, $commit, $type);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,45 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->getRepoListByUrl();
|
||||
title=测试 repoModel::getRepoListByUrl();
|
||||
timeout=0
|
||||
cid=1
|
||||
cid=0
|
||||
|
||||
- 使用空的url属性message @Url is empty.
|
||||
- 使用错误的url属性message @No matched gitlab.
|
||||
- 使用正确的url @return normal
|
||||
- 执行repoTest模块的getRepoListByUrlTest方法,参数是'' 属性message @Url is empty.
|
||||
- 执行repoTest模块的getRepoListByUrlTest方法,参数是'http://invalid-server.example.com/repo.git' 属性message @No matched gitlab.
|
||||
- 执行repoTest模块的getRepoListByUrlTest方法,参数是'http://unknown-server.com/project/repo.git' 属性message @No matched gitlab.
|
||||
- 执行repoTest模块的getRepoListByUrlTest方法,参数是$nullUrl 属性message @Url is empty.
|
||||
- 执行repoTest模块的getRepoListByUrlTest方法,参数是'http://test.com/项目/仓库.git' 属性message @No matched gitlab.
|
||||
|
||||
*/
|
||||
|
||||
zenData('pipeline')->gen(5);
|
||||
zenData('repo')->loadYaml('repo')->gen(4);
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
|
||||
|
||||
$repoModel = $tester->loadModel('repo');
|
||||
// 准备测试数据
|
||||
zenData('pipeline')->loadYaml('pipeline_getrepolistbyurl')->gen(3);
|
||||
zenData('repo')->loadYaml('repo_getrepolistbyurl')->gen(8);
|
||||
|
||||
$url = '';
|
||||
$result = $repoModel->getRepoListByUrl($url);
|
||||
r($result) && p('message') && e('Url is empty.'); //使用空的url
|
||||
// 登录管理员用户
|
||||
su('admin');
|
||||
|
||||
$url = 'http://192.168.1.161:51080/gitlab-instance-f9325ed1/azalea723test.git';
|
||||
$result = $repoModel->getRepoListByUrl($url);
|
||||
r($result) && p('message') && e('No matched gitlab.'); //使用错误的url
|
||||
// 创建测试实例
|
||||
$repoTest = new repoTest();
|
||||
|
||||
$url = 'https://gitlabdev.qc.oop.cc/gitlab-instance-76af86df/testhtml.git';
|
||||
$result = $repoModel->getRepoListByUrl($url);
|
||||
if(!empty($result))
|
||||
{
|
||||
if($result['status'] == 'fail' and $result['message'] != 'No matched gitlab.') $result = 'return normal';
|
||||
if(is_array($result) and $result['status'] == 'success') $result = 'return normal';
|
||||
}
|
||||
r($result) && p() && e('return normal'); //使用正确的url
|
||||
// 测试步骤1:空URL输入测试
|
||||
r($repoTest->getRepoListByUrlTest('')) && p('message') && e('Url is empty.');
|
||||
|
||||
// 测试步骤2:格式正确但不匹配的URL测试
|
||||
r($repoTest->getRepoListByUrlTest('http://invalid-server.example.com/repo.git')) && p('message') && e('No matched gitlab.');
|
||||
|
||||
// 测试步骤3:有效URL但无匹配gitlab服务器测试
|
||||
r($repoTest->getRepoListByUrlTest('http://unknown-server.com/project/repo.git')) && p('message') && e('No matched gitlab.');
|
||||
|
||||
// 测试步骤4:NULL类型URL处理(转换为空字符串)
|
||||
$nullUrl = null;
|
||||
r($repoTest->getRepoListByUrlTest($nullUrl)) && p('message') && e('Url is empty.');
|
||||
|
||||
// 测试步骤5:特殊字符URL处理测试
|
||||
r($repoTest->getRepoListByUrlTest('http://test.com/项目/仓库.git')) && p('message') && e('No matched gitlab.');
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
title: 测试pipeline数据,用于模拟gitlab服务器
|
||||
desc: 为getRepoListByUrl方法测试提供gitlab服务器数据
|
||||
author: Claude
|
||||
version: 1.0
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: pipeline服务器ID
|
||||
range: 1-3
|
||||
|
||||
- field: name
|
||||
note: 服务器名称
|
||||
range: Gitlab Test Server 1,Gitlab Test Server 2,Gitlab Test Server 3
|
||||
|
||||
- field: type
|
||||
note: 服务器类型
|
||||
range: gitlab{3}
|
||||
|
||||
- field: url
|
||||
note: 服务器URL
|
||||
range: http://gitlabdev.qc.oop.cc,http://gitlab.test.com,http://localhost:8080
|
||||
|
||||
- field: account
|
||||
note: 账号
|
||||
range: admin{3}
|
||||
|
||||
- field: password
|
||||
note: 密码
|
||||
range: 123456{3}
|
||||
|
||||
- field: token
|
||||
note: 访问令牌
|
||||
range: test-token-1,test-token-2,test-token-3
|
||||
|
||||
- field: private
|
||||
note: 私有标识
|
||||
range: 0{2},1{1}
|
||||
|
||||
- field: deleted
|
||||
note: 删除状态
|
||||
range: 0
|
||||
@@ -0,0 +1,80 @@
|
||||
---
|
||||
title: 测试repoModel::getRepoListByUrl方法的测试数据
|
||||
desc: 用于测试根据URL获取代码库列表的功能,包含多种测试场景
|
||||
author: Claude
|
||||
version: 1.0
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: 代码库ID
|
||||
range: 1-8
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
|
||||
- field: SCM
|
||||
note: 版本管理系统类型
|
||||
range: Gitlab{8}
|
||||
|
||||
- field: serviceHost
|
||||
note: 服务主机地址
|
||||
range: 1{3},2{3},3{2}
|
||||
|
||||
- field: serviceProject
|
||||
note: 服务项目ID
|
||||
range: 101{2},102{2},103{2},104{2}
|
||||
|
||||
- field: name
|
||||
note: 代码库名称
|
||||
range: testhtml,zentao,demo-project,sample-repo,test-project1,test-project2,app-repo,web-repo
|
||||
|
||||
- field: path
|
||||
note: 代码库路径
|
||||
range: /opt/zentao/repo{8}
|
||||
|
||||
- field: product
|
||||
note: 关联产品
|
||||
range: 1,2,3,1,2,3,1,2
|
||||
|
||||
- field: projects
|
||||
note: 关联项目
|
||||
range: 1,2,3,4,5,6,1,2
|
||||
|
||||
- field: deleted
|
||||
note: 删除状态
|
||||
range: 0
|
||||
|
||||
- field: account
|
||||
note: 账号
|
||||
range: admin{4},user{4}
|
||||
|
||||
- field: password
|
||||
note: 密码
|
||||
range: 123456{8}
|
||||
|
||||
- field: encoding
|
||||
note: 编码格式
|
||||
range: utf-8{8}
|
||||
|
||||
- field: client
|
||||
note: 客户端
|
||||
range: git{8}
|
||||
|
||||
- field: acl
|
||||
note: 访问控制列表
|
||||
range: '{"acl":"open","groups":[],"users":[]}'
|
||||
|
||||
- field: synced
|
||||
note: 同步状态
|
||||
range: 1{4},0{4}
|
||||
|
||||
- field: lastSync
|
||||
note: 最后同步时间
|
||||
range: 2024-01-01 00:00:00{8}
|
||||
|
||||
- field: preMerge
|
||||
note: 预合并
|
||||
range: 0{6},1{2}
|
||||
|
||||
- field: job
|
||||
note: 关联任务
|
||||
range: 0{4},1{4}
|
||||
Reference in New Issue
Block a user