* [misc] Enhance unit tests for sonarqubeModel::apiGetProjects() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -129,9 +129,19 @@ class sonarqubeTest
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function apiGetProjectsTest($sonarqubeID, $keyword = '')
|
||||
/**
|
||||
* Test apiGetProjects method.
|
||||
*
|
||||
* @param int $sonarqubeID
|
||||
* @param string $keyword
|
||||
* @param string $projectKey
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function apiGetProjectsTest($sonarqubeID, $keyword = '', $projectKey = '')
|
||||
{
|
||||
$result = $this->objectModel->apiGetProjects($sonarqubeID, $keyword);
|
||||
$result = $this->objectModel->apiGetProjects($sonarqubeID, $keyword, $projectKey);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
if(empty($result)) $result = 'return empty';
|
||||
return $result;
|
||||
|
||||
@@ -4,26 +4,55 @@
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::apiGetProjects();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 通过sonarqubeID,获取SonarQube项目列表 @1
|
||||
- 通过sonarqubeID,获取SonarQube项目数量 @1
|
||||
- 通过sonarqubeID,关键字,搜索获取SonarQube项目第0条的name属性 @unittest
|
||||
- 当sonarqubeID为0时,获取SonarQube项目列表 @return empty
|
||||
- 步骤1:正常情况第0条的name属性 @Special Key Test
|
||||
- 步骤2:关键字搜索第0条的key属性 @special.key:test-123
|
||||
- 步骤3:projectKey查询 @return empty
|
||||
- 步骤4:无效ID(0) @return empty
|
||||
- 步骤5:无效ID(999) @return empty
|
||||
- 步骤6:组合参数 @return empty
|
||||
- 步骤7:空关键字第0条的name属性 @Special Key Test
|
||||
|
||||
*/
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/sonarqube.unittest.class.php';
|
||||
su('admin');
|
||||
|
||||
// 准备测试数据
|
||||
zenData('pipeline')->loadYaml('pipeline')->gen(5);
|
||||
|
||||
$sonarqubeID = 2;
|
||||
$keyword = 'unit';
|
||||
// 设置用户登录
|
||||
su('admin');
|
||||
|
||||
// 创建测试实例
|
||||
$sonarqube = new sonarqubeTest();
|
||||
$result = $sonarqube->apiGetProjectsTest($sonarqubeID);
|
||||
r(isset($result[0]->name)) && p() && e('1'); //通过sonarqubeID,获取SonarQube项目列表
|
||||
r(count($result) > 1) && p() && e('1'); //通过sonarqubeID,获取SonarQube项目数量
|
||||
r($sonarqube->apiGetProjectsTest($sonarqubeID, $keyword)) && p('0:name') && e('unittest'); //通过sonarqubeID,关键字,搜索获取SonarQube项目
|
||||
r($sonarqube->apiGetProjectsTest(0)) && p() && e('return empty'); //当sonarqubeID为0时,获取SonarQube项目列表
|
||||
|
||||
// 测试参数定义
|
||||
$validSonarqubeID = 2;
|
||||
$invalidSonarqubeID1 = 0;
|
||||
$invalidSonarqubeID2 = 999;
|
||||
$keyword = 'test';
|
||||
$projectKey = 'unittest-project';
|
||||
$emptyKeyword = '';
|
||||
|
||||
// 测试步骤1:正常sonarqubeID获取项目列表
|
||||
r($sonarqube->apiGetProjectsTest($validSonarqubeID)) && p('0:name') && e('Special Key Test'); // 步骤1:正常情况
|
||||
|
||||
// 测试步骤2:使用关键字搜索项目
|
||||
r($sonarqube->apiGetProjectsTest($validSonarqubeID, $keyword)) && p('0:key') && e('special.key:test-123'); // 步骤2:关键字搜索
|
||||
|
||||
// 测试步骤3:使用projectKey参数获取特定项目
|
||||
r($sonarqube->apiGetProjectsTest($validSonarqubeID, '', $projectKey)) && p() && e('return empty'); // 步骤3:projectKey查询
|
||||
|
||||
// 测试步骤4:无效sonarqubeID(0)测试
|
||||
r($sonarqube->apiGetProjectsTest($invalidSonarqubeID1)) && p() && e('return empty'); // 步骤4:无效ID(0)
|
||||
|
||||
// 测试步骤5:无效sonarqubeID(999)测试
|
||||
r($sonarqube->apiGetProjectsTest($invalidSonarqubeID2)) && p() && e('return empty'); // 步骤5:无效ID(999)
|
||||
|
||||
// 测试步骤6:同时使用keyword和projectKey参数
|
||||
r($sonarqube->apiGetProjectsTest($validSonarqubeID, $keyword, $projectKey)) && p() && e('return empty'); // 步骤6:组合参数
|
||||
|
||||
// 测试步骤7:使用空关键字搜索(相当于获取所有项目)
|
||||
r($sonarqube->apiGetProjectsTest($validSonarqubeID, $emptyKeyword)) && p('0:name') && e('Special Key Test'); // 步骤7:空关键字
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: pipeline data for sonarqube apiGetProjects testing
|
||||
author: Claude
|
||||
version: "1.0"
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
range: 11-20
|
||||
- field: type
|
||||
range: 'sonarqube{8},gitlab{1},jenkins{1}'
|
||||
- field: name
|
||||
range: 'SonarQube服务器1,SonarQube服务器2,SonarQube服务器3,SonarQube服务器4,SonarQube服务器5,SonarQube测试服务器,SonarQube开发服务器,SonarQube生产服务器,GitLab服务器,Jenkins服务器'
|
||||
- field: url
|
||||
range: '[https://sonar1.test.com],[https://sonar2.test.com],[https://sonar3.test.com],[https://sonar4.test.com],[https://sonar5.test.com],[https://sonartest.test.com],[https://sonardev.test.com],[https://sonarprod.test.com],[https://gitlab.test.com],[https://jenkins.test.com]'
|
||||
- field: account
|
||||
range: 'sonar,admin{7},gitlab,jenkins'
|
||||
- field: password
|
||||
range: '[dGVzdFBhc3N3b3Jk],[YWRtaW5QYXNzd29yZA==]{7},[Z2l0bGFiUGFzc3dvcmQ=],[amVua2luc1Bhc3N3b3Jk]'
|
||||
- field: token
|
||||
range: '[squ_test1234567890abcdef1234567890abcdef12345678],[squ_test2234567890abcdef1234567890abcdef12345678],[squ_test3234567890abcdef1234567890abcdef12345678],[squ_test4234567890abcdef1234567890abcdef12345678],[squ_test5234567890abcdef1234567890abcdef12345678],[squ_test6234567890abcdef1234567890abcdef12345678],[squ_test7234567890abcdef1234567890abcdef12345678],[squ_test8234567890abcdef1234567890abcdef12345678],[gitlab_token123456789abcdef],[jenkins_token123456789abcdef]'
|
||||
- field: private
|
||||
range: '08bcc98f75d7d40053dc80722bdc117b{10}'
|
||||
- field: createdBy
|
||||
range: admin
|
||||
- field: createdDate
|
||||
range: '[(D-30)-(D)]'
|
||||
- field: deleted
|
||||
range: '0{9},1{1}'
|
||||
Reference in New Issue
Block a user