* [misc] Enhance unit tests for zahostModel::getNodeGroupHost() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -289,17 +289,16 @@ class zahostTest
|
||||
* 测试获取按主机分组的执行节点列表。
|
||||
* Test get node group by host.
|
||||
*
|
||||
* @param int $hostID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getNodeGroupHostTest(int $hostID): array
|
||||
public function getNodeGroupHostTest(): array
|
||||
{
|
||||
$nodeGroupHost = $this->objectModel->getNodeGroupHost();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return zget($nodeGroupHost, $hostID, array());
|
||||
return $nodeGroupHost;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,29 +3,43 @@
|
||||
|
||||
/**
|
||||
|
||||
title=测试 zahostModel->getList();
|
||||
title=测试 zahostModel::getNodeGroupHost();
|
||||
timeout=0
|
||||
cid=1
|
||||
cid=0
|
||||
|
||||
- 宿主机1 下的执行节点1第4条的name属性 @执行节点1
|
||||
- 宿主机2 下的执行节点2第5条的name属性 @执行节点2
|
||||
- 宿主机3 下没有执行节点 @0
|
||||
- 步骤1:验证返回2个主机分组 @2
|
||||
- 步骤2:验证宿主机1下有1个执行节点 @1
|
||||
- 步骤3:验证宿主机2下有1个执行节点 @1
|
||||
- 步骤4:验证宿主机3下没有执行节点 @0
|
||||
- 步骤5:验证无效父级节点不在结果中 @0
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/zahost.unittest.class.php';
|
||||
su('admin');
|
||||
|
||||
$host = zenData('host');
|
||||
$host->id->range('1-5');
|
||||
$host->type->range('zahost{3},node{2}');
|
||||
$host->name->range('宿主机1,宿主机2,宿主机3,执行节点1,执行节点2');
|
||||
$host->parent->range('0{3},1,2');
|
||||
$host->gen(5);
|
||||
$host->id->range('1-6');
|
||||
$host->type->range('zahost{3},node{3}');
|
||||
$host->name->range('宿主机1,宿主机2,宿主机3,执行节点1,执行节点2,执行节点3');
|
||||
$host->parent->range('0{3},1,2,999');
|
||||
$host->deleted->range('0');
|
||||
$host->gen(6);
|
||||
|
||||
su('admin');
|
||||
|
||||
$hostID = array(1, 2, 3);
|
||||
$zahost = new zahostTest();
|
||||
r($zahost->getNodeGroupHostTest($hostID[0])) && p('4:name') && e('执行节点1'); //宿主机1 下的执行节点1
|
||||
r($zahost->getNodeGroupHostTest($hostID[1])) && p('5:name') && e('执行节点2'); //宿主机2 下的执行节点2
|
||||
r($zahost->getNodeGroupHostTest($hostID[2])) && p('') && e('0'); //宿主机3 下没有执行节点
|
||||
$result = $zahost->getNodeGroupHostTest();
|
||||
|
||||
// 将结果存储在变量中以便复用
|
||||
$resultCount = count($result);
|
||||
$host1HasNodes = isset($result[1]) ? count($result[1]) : 0;
|
||||
$host2HasNodes = isset($result[2]) ? count($result[2]) : 0;
|
||||
$host3HasNodes = isset($result[3]) ? count($result[3]) : 0;
|
||||
$hostInvalidNodes = isset($result[999]) ? count($result[999]) : 0;
|
||||
|
||||
r($resultCount) && p() && e('2'); // 步骤1:验证返回2个主机分组
|
||||
r($host1HasNodes) && p() && e('1'); // 步骤2:验证宿主机1下有1个执行节点
|
||||
r($host2HasNodes) && p() && e('1'); // 步骤3:验证宿主机2下有1个执行节点
|
||||
r($host3HasNodes) && p() && e('0'); // 步骤4:验证宿主机3下没有执行节点
|
||||
r($hostInvalidNodes) && p() && e('0'); // 步骤5:验证无效父级节点不在结果中
|
||||
Reference in New Issue
Block a user