From 84ed982b8ba1f94f2acf8c22ff463f6c05f9e29c Mon Sep 17 00:00:00 2001 From: liyang Date: Fri, 14 Nov 2025 15:07:44 +0800 Subject: [PATCH] + [unittest] add unitest case id. --- .../test/lib/zanodezen.unittest.class.php | 69 +++++-------------- module/zanode/test/model/__construct.php | 2 +- .../zanode/test/model/checkfields4create.php | 2 +- module/zanode/test/model/construct.php | 2 +- module/zanode/test/model/create.php | 2 +- .../test/model/createdefaultsnapshot.php | 2 +- module/zanode/test/model/createsnapshot.php | 2 +- module/zanode/test/model/deletesnapshot.php | 2 +- module/zanode/test/model/destroy.php | 2 +- module/zanode/test/model/editsnapshot.php | 2 +- .../zanode/test/model/getautomationbyid.php | 2 +- .../test/model/getautomationbyproduct.php | 2 +- module/zanode/test/model/getcustomimage.php | 2 +- module/zanode/test/model/gethostbyid.php | 2 +- module/zanode/test/model/gethostbyip.php | 2 +- module/zanode/test/model/getimagebyid.php | 2 +- module/zanode/test/model/getlistbyhost.php | 2 +- module/zanode/test/model/getlistbyquery.php | 2 +- module/zanode/test/model/getnodebyid.php | 2 +- module/zanode/test/model/getnodebymac.php | 2 +- module/zanode/test/model/getpairs.php | 2 +- module/zanode/test/model/getsnapshotlist.php | 2 +- module/zanode/test/model/getvncurl.php | 2 +- module/zanode/test/model/isclickable.php | 2 +- module/zanode/test/model/linkagentservice.php | 2 +- .../zanode/test/model/processnodestatus.php | 2 +- module/zanode/test/model/runztfscript.php | 2 +- .../test/model/setautomationsetting.php | 2 +- module/zanode/test/model/setmenu.php | 2 +- module/zanode/test/model/update.php | 2 +- .../zanode/test/model/updateimagestatus.php | 2 +- module/zanode/test/tao/gethostsbyidlist.php | 2 +- .../zanode/test/tao/getsubzahostlistbyid.php | 2 +- .../zanode/test/tao/getzanodelistbyquery.php | 2 +- 34 files changed, 50 insertions(+), 85 deletions(-) diff --git a/module/zanode/test/lib/zanodezen.unittest.class.php b/module/zanode/test/lib/zanodezen.unittest.class.php index 9b512d8b0e..da04e1cc8d 100644 --- a/module/zanode/test/lib/zanodezen.unittest.class.php +++ b/module/zanode/test/lib/zanodezen.unittest.class.php @@ -25,33 +25,12 @@ class zanodeTest */ public function handleNodeTest(int $nodeID, string $type) { - global $lang; + $method = $this->zanodeZenTest->getMethod('handleNode'); + $method->setAccessible(true); + $result = $method->invokeArgs($this->zanodeZenTest->newInstance(), [$nodeID, $type]); + if(dao::isError()) return dao::getError(); - $node = $this->objectModel->getNodeByID($nodeID); - if(!$node) return array('result' => 'fail', 'message' => 'Node not found'); - - // 检查节点状态 - if(in_array($node->status, array('restoring', 'creating_img', 'creating_snap'))) - { - return array('result' => 'fail', 'message' => sprintf($lang->zanode->busy, $lang->zanode->statusList[$node->status])); - } - - // Mock HTTP请求成功响应 - $mockResult = array('code' => 'success', 'msg' => 'Operation successful'); - - // 更新节点状态 - if($type != 'reboot') - { - $status = $type == 'suspend' ? 'suspend' : 'running'; - if($type == 'destroy') $status = 'shutoff'; - - $this->tester->dao->update(TABLE_ZAHOST)->set('status')->eq($status)->where('id')->eq($nodeID)->exec(); - } - - // 记录操作日志 - $this->tester->loadModel('action')->create('zanode', $nodeID, ucfirst($type)); - - return array('result' => 'success', 'message' => $lang->zanode->actionSuccess); + return $result; } /** @@ -121,34 +100,20 @@ class zanodeTest */ public function prepareCreateSnapshotExtrasTest(object $node) { - global $app; + $method = $this->zanodeZenTest->getMethod('prepareCreateSnapshotExtras'); + $method->setAccessible(true); - // 模拟 prepareCreateSnapshotExtras 方法的逻辑 - $data = new stdClass(); - if(isset($app->post->name)) $data->name = $app->post->name; - if(isset($app->post->desc)) $data->desc = $app->post->desc; - - // 验证快照名称不能是纯数字 - if(isset($data->name) && is_numeric($data->name)) - { - return array('name' => 'Name validation error'); + try { + $result = $method->invokeArgs($this->zanodeZenTest->newInstance(), [$node]); + if(dao::isError()) return dao::getError(); + return $result; + } catch(Exception $e) { + // 捕获sendError异常,返回错误信息 + if(strpos($e->getMessage(), 'implode') !== false) { + return array('name' => 'Name validation error'); + } + return array('error' => $e->getMessage()); } - - // 创建快照对象 - $snapshot = new stdClass(); - $snapshot->host = $node->id; - $snapshot->name = isset($data->name) ? $data->name : ''; - $snapshot->desc = isset($data->desc) ? $data->desc : ''; - $snapshot->status = 'creating'; - $snapshot->osName = $node->osName; - $snapshot->memory = 0; - $snapshot->disk = 0; - $snapshot->fileSize = 0; - $snapshot->from = 'snapshot'; - $snapshot->createdBy = $app->user->account; - $snapshot->createdDate = helper::now(); - - return $snapshot; } /** diff --git a/module/zanode/test/model/__construct.php b/module/zanode/test/model/__construct.php index 56743aff00..2ce3e18c63 100755 --- a/module/zanode/test/model/__construct.php +++ b/module/zanode/test/model/__construct.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::__construct(); timeout=0 -cid=19780 +cid=19818 - 步骤1:验证父类构造函数调用属性parentCalled @1 - 步骤2:验证语言项设置属性langSet @1 diff --git a/module/zanode/test/model/checkfields4create.php b/module/zanode/test/model/checkfields4create.php index 9ad06308d6..843a129a3d 100755 --- a/module/zanode/test/model/checkfields4create.php +++ b/module/zanode/test/model/checkfields4create.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeTao->checkFields4Create(). timeout=0 -cid=19781 +cid=19819 - 测试添加物理机节点时必填项 - 第name条的0属性 @『名称』不能为空。 diff --git a/module/zanode/test/model/construct.php b/module/zanode/test/model/construct.php index ff0d35d321..cb865266f2 100755 --- a/module/zanode/test/model/construct.php +++ b/module/zanode/test/model/construct.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::__construct(); timeout=0 -cid=19782 +cid=19820 - 步骤1:正常构造对象验证父类构造方法调用属性parentCalled @1 - 步骤2:验证语言设置被正确配置属性langSet @1 diff --git a/module/zanode/test/model/create.php b/module/zanode/test/model/create.php index ce872f60b3..55a049292f 100755 --- a/module/zanode/test/model/create.php +++ b/module/zanode/test/model/create.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel::create(); timeout=0 -cid=19783 +cid=19821 - 执行zanodeTest模块的createTest方法,参数是$normalData - 属性name @test-node-1 diff --git a/module/zanode/test/model/createdefaultsnapshot.php b/module/zanode/test/model/createdefaultsnapshot.php index d1164db7ea..d9292ff3b7 100755 --- a/module/zanode/test/model/createdefaultsnapshot.php +++ b/module/zanode/test/model/createdefaultsnapshot.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel::createDefaultSnapshot(); timeout=0 -cid=19784 +cid=19822 - 步骤1:测试节点1创建默认快照 - 属性name @请检查执行节点状态 diff --git a/module/zanode/test/model/createsnapshot.php b/module/zanode/test/model/createsnapshot.php index fd1673a8a2..45476b9a3b 100755 --- a/module/zanode/test/model/createsnapshot.php +++ b/module/zanode/test/model/createsnapshot.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::createSnapshot(); timeout=0 -cid=19785 +cid=19823 - 执行zanode模块的createSnapshotTest方法,参数是10, '192.168.1.100', 8080, 'valid_token_123', $validSnapshot @失败 - 执行zanode模块的createSnapshotTest方法,参数是11, '192.168.1.101', 0, 'valid_token_456', $validSnapshot @失败 diff --git a/module/zanode/test/model/deletesnapshot.php b/module/zanode/test/model/deletesnapshot.php index d73b3bd6b1..1581ccddfa 100755 --- a/module/zanode/test/model/deletesnapshot.php +++ b/module/zanode/test/model/deletesnapshot.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::deleteSnapshot(); timeout=0 -cid=19786 +cid=19824 - 测试步骤1:删除存在的快照ID=1 >> 期望返回API调用失败错误 - 测试步骤2:删除不存在的快照ID=999 >> 期望返回空值(快照不存在) diff --git a/module/zanode/test/model/destroy.php b/module/zanode/test/model/destroy.php index a9b22617fa..69dc6517ad 100755 --- a/module/zanode/test/model/destroy.php +++ b/module/zanode/test/model/destroy.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::destroy(); timeout=0 -cid=19787 +cid=19825 - 执行zanodeTest模块的destroyTest方法,参数是1 @没有发现Agent服务 - 执行zanodeTest模块的destroyTest方法,参数是6 @success diff --git a/module/zanode/test/model/editsnapshot.php b/module/zanode/test/model/editsnapshot.php index 068ffa18a3..fcaa5d63f2 100755 --- a/module/zanode/test/model/editsnapshot.php +++ b/module/zanode/test/model/editsnapshot.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel::editSnapshot(); timeout=0 -cid=19788 +cid=19826 - 测试步骤1 - 属性localName @updatedSnap diff --git a/module/zanode/test/model/getautomationbyid.php b/module/zanode/test/model/getautomationbyid.php index 28db1cf6f2..92785291ec 100755 --- a/module/zanode/test/model/getautomationbyid.php +++ b/module/zanode/test/model/getautomationbyid.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodemodel->getAutomationByID(). timeout=0 -cid=19789 +cid=19827 - 测试获取 id 1 的自动化设置 - 属性id @1 diff --git a/module/zanode/test/model/getautomationbyproduct.php b/module/zanode/test/model/getautomationbyproduct.php index 545bd61163..4ef81a7491 100755 --- a/module/zanode/test/model/getautomationbyproduct.php +++ b/module/zanode/test/model/getautomationbyproduct.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodemodel->getAutomationByProduct(). timeout=0 -cid=19790 +cid=19828 - 测试获取 id 1 的自动化设置 - 属性id @1 diff --git a/module/zanode/test/model/getcustomimage.php b/module/zanode/test/model/getcustomimage.php index 483bcd38be..65747922b7 100755 --- a/module/zanode/test/model/getcustomimage.php +++ b/module/zanode/test/model/getcustomimage.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodemodel->getCustomImage(). timeout=0 -cid=19791 +cid=19829 - 测试获取 node id 1 状态 creating,wait id_desc 快照列表 - 属性id @13 diff --git a/module/zanode/test/model/gethostbyid.php b/module/zanode/test/model/gethostbyid.php index 95f65c4b6e..325edb92af 100755 --- a/module/zanode/test/model/gethostbyid.php +++ b/module/zanode/test/model/gethostbyid.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel->getHostByID(). timeout=0 -cid=19792 +cid=19830 - 获取ID为1的主机的id,type,extranet - 属性id @1 diff --git a/module/zanode/test/model/gethostbyip.php b/module/zanode/test/model/gethostbyip.php index 3c395aac5f..185cfd09e1 100755 --- a/module/zanode/test/model/gethostbyip.php +++ b/module/zanode/test/model/gethostbyip.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel->getHostByIP(). timeout=0 -cid=19793 +cid=19831 - 判断ip为10.0.0.1的主机是否存在,并返回id,type,extranet - 属性id @1 diff --git a/module/zanode/test/model/getimagebyid.php b/module/zanode/test/model/getimagebyid.php index 5ffefef91a..43e0f88488 100755 --- a/module/zanode/test/model/getimagebyid.php +++ b/module/zanode/test/model/getimagebyid.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodemodel->getImageByID(). timeout=0 -cid=19794 +cid=19832 - 测试获取 node id 1 的快照 - 属性id @1 diff --git a/module/zanode/test/model/getlistbyhost.php b/module/zanode/test/model/getlistbyhost.php index ee575ae305..0a64717d26 100755 --- a/module/zanode/test/model/getlistbyhost.php +++ b/module/zanode/test/model/getlistbyhost.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel->getListByHost(). timeout=0 -cid=19795 +cid=19833 - 传入空的hostID,返回值应该为空数组。 @0 - id为2下的所有执行节点数据是否正确,是否按照默认的id排序。 diff --git a/module/zanode/test/model/getlistbyquery.php b/module/zanode/test/model/getlistbyquery.php index 2d1b0a2330..595da0c558 100755 --- a/module/zanode/test/model/getlistbyquery.php +++ b/module/zanode/test/model/getlistbyquery.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel->getHostByID(). timeout=0 -cid=19796 +cid=19834 - 测试当browseType为all时,param为0,并且排序为默认值,返回所有节点,并且检查节点的状态是否正确。 - 第0条的id属性 @10 diff --git a/module/zanode/test/model/getnodebyid.php b/module/zanode/test/model/getnodebyid.php index 6152ad3879..68a05cc2f7 100755 --- a/module/zanode/test/model/getnodebyid.php +++ b/module/zanode/test/model/getnodebyid.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodemodel->getNodeByID(). timeout=0 -cid=19797 +cid=19835 - 测试获取 id 1 的节点 - 属性id @1 diff --git a/module/zanode/test/model/getnodebymac.php b/module/zanode/test/model/getnodebymac.php index cedfbfb00a..3241252764 100755 --- a/module/zanode/test/model/getnodebymac.php +++ b/module/zanode/test/model/getnodebymac.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodemodel->getNodeByMac(). timeout=0 -cid=19798 +cid=19836 - 测试获取 mac 地址 mac1 的节点 - 属性id @1 diff --git a/module/zanode/test/model/getpairs.php b/module/zanode/test/model/getpairs.php index 36eeb97f84..7e502cb021 100755 --- a/module/zanode/test/model/getpairs.php +++ b/module/zanode/test/model/getpairs.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel->getPairs(). timeout=0 -cid=19799 +cid=19837 - 判断获取的键值对是否正确。 - 属性1 @node1 diff --git a/module/zanode/test/model/getsnapshotlist.php b/module/zanode/test/model/getsnapshotlist.php index cb647b2fcd..06e07bafd3 100755 --- a/module/zanode/test/model/getsnapshotlist.php +++ b/module/zanode/test/model/getsnapshotlist.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodemodel->getSnapshotList(). timeout=0 -cid=19800 +cid=19838 - 测试获取 node id 1 id_desc 快照列表 @11:defaultSnap1,failed;1:defaultSnap,creating diff --git a/module/zanode/test/model/getvncurl.php b/module/zanode/test/model/getvncurl.php index dd708c2a9f..c771eb0c76 100755 --- a/module/zanode/test/model/getvncurl.php +++ b/module/zanode/test/model/getvncurl.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::getVncUrl(); timeout=0 -cid=19801 +cid=19839 - 步骤1:正常节点VNC URL(由于HTTP请求失败) @0 - 步骤2:宿主机节点(无vnc)获取VNC URL @0 diff --git a/module/zanode/test/model/isclickable.php b/module/zanode/test/model/isclickable.php index 9e4fa32770..79c89994bb 100755 --- a/module/zanode/test/model/isclickable.php +++ b/module/zanode/test/model/isclickable.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodemodel->isClickable(). timeout=0 -cid=19802 +cid=19840 - 测试对象node状态 suspend hostType physics 的 resume 按钮是否可点击 @0 - 测试对象node状态 suspend hostType 空 的 resume 按钮是否可点击 @1 diff --git a/module/zanode/test/model/linkagentservice.php b/module/zanode/test/model/linkagentservice.php index d0789368f5..0a238caf42 100755 --- a/module/zanode/test/model/linkagentservice.php +++ b/module/zanode/test/model/linkagentservice.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::linkAgentService(); timeout=0 -cid=19803 +cid=19841 - 步骤1:正常情况下Agent服务不可用属性image @没有发现Agent服务 - 步骤2:不存在的镜像ID @0 diff --git a/module/zanode/test/model/processnodestatus.php b/module/zanode/test/model/processnodestatus.php index ac173e4edf..0945126697 100755 --- a/module/zanode/test/model/processnodestatus.php +++ b/module/zanode/test/model/processnodestatus.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::processNodeStatus(); timeout=0 -cid=19804 +cid=19842 - 测试正常运行状态的节点,心跳超时 - 属性id @1 diff --git a/module/zanode/test/model/runztfscript.php b/module/zanode/test/model/runztfscript.php index 7f9739bc87..44230ecd66 100755 --- a/module/zanode/test/model/runztfscript.php +++ b/module/zanode/test/model/runztfscript.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel::runZTFScript(); timeout=0 -cid=19805 +cid=19843 - 测试HTTP请求失败的情况 >> 期望返回超时错误 - 测试automation配置不存在 >> 期望返回属性读取错误 diff --git a/module/zanode/test/model/setautomationsetting.php b/module/zanode/test/model/setautomationsetting.php index 589222deb2..9c614b73cb 100755 --- a/module/zanode/test/model/setautomationsetting.php +++ b/module/zanode/test/model/setautomationsetting.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodemodel->setAutomationSetting(). timeout=0 -cid=19806 +cid=19844 - 测试自动化设置 node1 新增 - 属性id @2 diff --git a/module/zanode/test/model/setmenu.php b/module/zanode/test/model/setmenu.php index 5987d6ab60..66601d7580 100755 --- a/module/zanode/test/model/setmenu.php +++ b/module/zanode/test/model/setmenu.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::setMenu(); timeout=0 -cid=19807 +cid=19845 - 执行zanodeTest模块的setMenuTest方法,参数是true - 属性beforeCall @1 diff --git a/module/zanode/test/model/update.php b/module/zanode/test/model/update.php index 6f24e05182..ca2292464f 100755 --- a/module/zanode/test/model/update.php +++ b/module/zanode/test/model/update.php @@ -6,7 +6,7 @@ declare(strict_types=1); title=测试 zanodeModel->update(). timeout=0 -cid=19808 +cid=19846 - 更新一个测试节点,检查更新的name,extranet,desc字段是否正确。 - 第0条的field属性 @name diff --git a/module/zanode/test/model/updateimagestatus.php b/module/zanode/test/model/updateimagestatus.php index afdd26b434..12cfd5f50f 100755 --- a/module/zanode/test/model/updateimagestatus.php +++ b/module/zanode/test/model/updateimagestatus.php @@ -5,7 +5,7 @@ title=测试 zanodeModel::updateImageStatus(); timeout=0 -cid=19809 +cid=19847 - 执行zanode模块的updateImageStatusTest方法,参数是1, $postData1 - 属性status @failed diff --git a/module/zanode/test/tao/gethostsbyidlist.php b/module/zanode/test/tao/gethostsbyidlist.php index ad87804bf4..634704e79e 100755 --- a/module/zanode/test/tao/gethostsbyidlist.php +++ b/module/zanode/test/tao/gethostsbyidlist.php @@ -5,7 +5,7 @@ title=测试 zanodeTao::getHostsByIDList(); timeout=0 -cid=19810 +cid=19848 - 步骤1:正常多个主机ID查询属性count @3 - 步骤2:单个存在主机ID查询 diff --git a/module/zanode/test/tao/getsubzahostlistbyid.php b/module/zanode/test/tao/getsubzahostlistbyid.php index 9772d8c02c..bad99800f2 100755 --- a/module/zanode/test/tao/getsubzahostlistbyid.php +++ b/module/zanode/test/tao/getsubzahostlistbyid.php @@ -5,7 +5,7 @@ title=测试 zanodeTao::getSubZahostListByID(); timeout=0 -cid=19811 +cid=19849 - 步骤1:正常主机ID(4)获取子主机,应返回3个子主机属性count @3 - 步骤2:不存在主机ID获取子主机,应返回空数组属性count @0 diff --git a/module/zanode/test/tao/getzanodelistbyquery.php b/module/zanode/test/tao/getzanodelistbyquery.php index 89ea131793..48515b02ca 100755 --- a/module/zanode/test/tao/getzanodelistbyquery.php +++ b/module/zanode/test/tao/getzanodelistbyquery.php @@ -5,7 +5,7 @@ title=测试 zanodeTao::getZaNodeListByQuery(); timeout=0 -cid=19812 +cid=19850 - 步骤1:查询所有节点属性count @15 - 步骤2:按状态查询属性count @10