+ [misc] Add unit tests for zahostZen::getServiceStatus() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-19 11:06:09 +08:00
co-authored by Claude
parent 6c2ddbf639
commit 613d82bfbd
2 changed files with 84 additions and 0 deletions
@@ -0,0 +1,44 @@
<?php
declare(strict_types = 1);
class zahostTest
{
public $zahostZenTest;
public $tester;
public function __construct()
{
global $tester;
$this->tester = $tester;
$this->objectModel = $tester->loadModel('zahost');
$tester->app->setModuleName('zahost');
$this->zahostZenTest = initReference('zahost');
}
/**
* Test getServiceStatus method.
*
* @param object $host
* @access public
* @return mixed
*/
public function getServiceStatusTest($host = null)
{
if($host === null)
{
$host = new stdClass();
$host->status = 'online';
$host->extranet = '192.168.1.1';
$host->zap = '8086';
$host->tokenSN = 'test-token';
}
$method = $this->zahostZenTest->getMethod('getServiceStatus');
$method->setAccessible(true);
$result = $method->invokeArgs($this->zahostZenTest->newInstance(), [$host]);
if(dao::isError()) return dao::getError();
return $result;
}
}
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env php
<?php
/**
title=测试 zahostZen::getServiceStatus();
timeout=0
cid=0
- 执行zahostTest模块的getServiceStatusTest方法 属性kvm @not_install
- 执行zahostTest模块的getServiceStatusTest方法 属性nginx @not_install
- 执行zahostTest模块的getServiceStatusTest方法 属性novnc @not_install
- 执行zahostTest模块的getServiceStatusTest方法 属性websockify @not_install
- 执行zahostTest模块的getServiceStatusTest方法 属性kvm @not_install
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/zahostzen.unittest.class.php';
$host = zenData('host');
$host->id->range('1-10');
$host->name->range('host{1-10}');
$host->extranet->range('192.168.1.{1-10}');
$host->zap->range('8086');
$host->tokenSN->range('token{1-10}');
$host->status->range('wait,offline,online{5},ready{2}');
$host->type->range('zahost');
$host->deleted->range('0');
$host->gen(10);
su('admin');
$zahostTest = new zahostTest();
r($zahostTest->getServiceStatusTest((object)['status' => 'wait', 'extranet' => '192.168.1.1', 'zap' => '8086', 'tokenSN' => 'token1'])) && p('kvm') && e('not_install');
r($zahostTest->getServiceStatusTest((object)['status' => 'offline', 'extranet' => '192.168.1.2', 'zap' => '8086', 'tokenSN' => 'token2'])) && p('nginx') && e('not_install');
r($zahostTest->getServiceStatusTest((object)['status' => 'online', 'extranet' => 'invalid-host', 'zap' => '8086', 'tokenSN' => 'token3'])) && p('novnc') && e('not_install');
r($zahostTest->getServiceStatusTest((object)['status' => 'ready', 'extranet' => '192.168.1.4', 'zap' => '8086', 'tokenSN' => 'invalid-token'])) && p('websockify') && e('not_install');
r($zahostTest->getServiceStatusTest((object)['status' => 'online', 'extranet' => '192.168.1.5', 'zap' => '8086', 'tokenSN' => 'token5'])) && p('kvm') && e('not_install');