* [misc] Enhance unit tests for instanceModel::filterMemOptions() method

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-25 09:16:15 +08:00
co-authored by Claude
parent e5605dc8a3
commit a21dd810f5
2 changed files with 43 additions and 13 deletions
@@ -680,4 +680,23 @@ class instanceTest
return $result;
}
/**
* Test filterMemOptions method.
*
* @param int $memorySize
* @access public
* @return array
*/
public function filterMemOptionsTest(int $memorySize)
{
$resources = new stdClass();
$resources->min = new stdClass();
$resources->min->memory = $memorySize * 1024;
$result = $this->objectModel->filterMemOptions($resources);
if(dao::isError()) return dao::getError();
return $result;
}
}
+24 -13
View File
@@ -1,26 +1,37 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
/**
title=instanceModel->domainExists();
title=测试 instanceModel::filterMemOptions();
timeout=0
cid=1
cid=0
- 查看过滤后的内存选项是否正确 @6
- 查看过滤后的内存选项是否正确 @2
- 步骤1:1GB内存,期望返回6个选项 @6
- 步骤2:512MB内存,期望返回7个选项 @7
- 步骤3:128MB内存,期望返回所有9个选项 @9
- 步骤4:32GB内存,期望返回1个选项 @1
- 步骤5:0值输入,期望返回所有选项 @9
- 步骤6:检查1GB选项的键值属性1048576 @1GB
- 步骤7:检查2GB选项的显示文本属性2097152 @2GB
*/
global $tester;
$tester->loadModel('instance');
// 1. 导入依赖
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/instance.unittest.class.php';
$resources = new stdclass();
$resources->min = new stdclass();
// 2. 用户登录
su('admin');
$resources->min->memory = 1048576 * 1024;
r(count($tester->instance->filterMemOptions($resources))) && p('') && e('6'); // 查看过滤后的内存选项是否正确
// 3. 创建测试实例
$instanceTest = new instanceTest();
$resources->min->memory = 16777216 * 1024;
r(count($tester->instance->filterMemOptions($resources))) && p('') && e('2'); // 查看过滤后的内存选项是否正确
// 4. 测试步骤
r(count($instanceTest->filterMemOptionsTest(1024 * 1024))) && p() && e('6'); // 步骤1:1GB内存,期望返回6个选项
r(count($instanceTest->filterMemOptionsTest(512 * 1024))) && p() && e('7'); // 步骤2:512MB内存,期望返回7个选项
r(count($instanceTest->filterMemOptionsTest(128 * 1024))) && p() && e('9'); // 步骤3:128MB内存,期望返回所有9个选项
r(count($instanceTest->filterMemOptionsTest(32768 * 1024))) && p() && e('1'); // 步骤4:32GB内存,期望返回1个选项
r(count($instanceTest->filterMemOptionsTest(0))) && p() && e('9'); // 步骤5:0值输入,期望返回所有选项
r($instanceTest->filterMemOptionsTest(1024 * 1024)) && p('1048576') && e('1GB'); // 步骤6:检查1GB选项的键值
r($instanceTest->filterMemOptionsTest(2048 * 1024)) && p('2097152') && e('2GB'); // 步骤7:检查2GB选项的显示文本