+ [misc] Add unit tests for instanceModel::freshStatus() method

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:06:16 +08:00
co-authored by Claude
parent e9af847f6d
commit e997602d5a
3 changed files with 271 additions and 0 deletions
@@ -301,4 +301,19 @@ class instanceTest
return $result;
}
/**
* Test freshStatus method.
*
* @param object $instance
* @access public
* @return object
*/
public function freshStatusTest(object $instance): object
{
$result = $this->objectModel->freshStatus($instance);
if(dao::isError()) return dao::getError();
return $result;
}
}
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env php
<?php
/**
title=测试 instanceModel::freshStatus();
timeout=0
cid=0
- 步骤1:正常状态刷新,设置runDuration为0属性runDuration @0
- 步骤2:CNE查询失败,runDuration保持为0属性runDuration @0
- 步骤3:状态变化验证属性status @creating
- 步骤4:版本信息验证属性version @1.0.0
- 步骤5:实例ID验证属性id @5
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/instance.unittest.class.php';
// 2. zendata数据准备(根据需要配置)
$table = zenData('instance');
$table->id->range('1-5');
$table->name->range('Test Instance{1-5}');
$table->status->range('running,stopped,creating,running,stopped');
$table->version->range('1.0.0,1.1.0,2.0.0,1.0.0,2.0.0');
$table->k8name->range('test-k8name{1-5}');
$table->chart->range('zentao,gitlab,jenkins,zentao,gitlab');
$table->domain->range('test1.example.com,test2.example.com,test3.example.com,test4.example.com,test5.example.com');
$table->space->range('1-3:R');
$table->deleted->range('0');
$table->gen(5);
// 3. 用户登录(选择合适角色)
su('admin');
// 4. 创建测试实例(变量名与模块名一致)
$instanceTest = new instanceTest();
// 5. 🔴 强制要求:必须包含至少5个测试步骤
// 创建测试实例对象,包含必要的属性
$instance1 = (object)array('id' => 1, 'status' => 'running', 'version' => '1.0.0', 'k8name' => 'test-k8name1', 'chart' => 'zentao', 'spaceData' => (object)array('k8space' => 'test-space'));
$instance2 = (object)array('id' => 2, 'status' => 'stopped', 'version' => '1.1.0', 'k8name' => 'invalid-k8name', 'chart' => 'gitlab', 'spaceData' => (object)array('k8space' => 'test-space'));
$instance3 = (object)array('id' => 3, 'status' => 'creating', 'version' => '2.0.0', 'k8name' => 'test-k8name3', 'chart' => 'jenkins', 'spaceData' => (object)array('k8space' => 'test-space'));
$instance4 = (object)array('id' => 4, 'status' => 'running', 'version' => '1.0.0', 'k8name' => 'test-k8name4', 'chart' => 'zentao', 'spaceData' => (object)array('k8space' => 'test-space'));
$instance5 = (object)array('id' => 5, 'status' => 'stopped', 'version' => '2.0.0', 'k8name' => 'test-k8name5', 'chart' => 'gitlab', 'spaceData' => (object)array('k8space' => 'test-space'));
r($instanceTest->freshStatusTest($instance1)) && p('runDuration') && e('0'); // 步骤1:正常状态刷新,设置runDuration为0
r($instanceTest->freshStatusTest($instance2)) && p('runDuration') && e('0'); // 步骤2:CNE查询失败,runDuration保持为0
r($instanceTest->freshStatusTest($instance3)) && p('status') && e('creating'); // 步骤3:状态变化验证
r($instanceTest->freshStatusTest($instance4)) && p('version') && e('1.0.0'); // 步骤4:版本信息验证
r($instanceTest->freshStatusTest($instance5)) && p('id') && e('5'); // 步骤5:实例ID验证
@@ -0,0 +1,203 @@
---
title: instance表freshStatus方法测试数据
desc: 用于测试freshStatus方法的实例数据
author: Claude
version: 1.0
fields:
- field: id
note: 实例ID
range: 1-10
prefix: ""
postfix: ""
loop: 0
format: ""
- field: space
note: 空间ID
range: 1-3:R
prefix: ""
postfix: ""
loop: 0
format: ""
- field: solution
note: 解决方案ID
range: 0
prefix: ""
postfix: ""
loop: 0
format: ""
- field: name
note: 实例名称
range: Test Instance{1-10}
prefix: ""
postfix: ""
loop: 0
format: ""
- field: appID
note: 应用ID
range: 1-5:R
prefix: ""
postfix: ""
loop: 0
format: ""
- field: appName
note: 应用名称
range: ZenTao,GitLab,Jenkins,SonarQube,Nexus
prefix: ""
postfix: ""
loop: 0
format: ""
- field: appVersion
note: 应用版本
range: 18.12,15.11.3,2.401.3,9.9.0,3.41.1
prefix: ""
postfix: ""
loop: 0
format: ""
- field: chart
note: Chart名称
range: zentao,gitlab,jenkins,sonarqube,nexus3
prefix: ""
postfix: ""
loop: 0
format: ""
- field: logo
note: 应用logo
range: '/static/zentao.png,/static/gitlab.png,/static/jenkins.png,/static/sonar.png,/static/nexus.png'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: version
note: 实例版本
range: 1.0.0,1.1.0,2.0.0,1.2.0,2.1.0
prefix: ""
postfix: ""
loop: 0
format: ""
- field: desc
note: 实例描述
range: Test description for instance{1-10}
prefix: ""
postfix: ""
loop: 0
format: ""
- field: introduction
note: 实例介绍
range: Test introduction for instance{1-10}
prefix: ""
postfix: ""
loop: 0
format: ""
- field: source
note: 来源
range: cloud,system,user
prefix: ""
postfix: ""
loop: 0
format: ""
- field: channel
note: 渠道
range: stable,testing,dev
prefix: ""
postfix: ""
loop: 0
format: ""
- field: k8name
note: K8s名称
range: test-k8name{1-10}
prefix: ""
postfix: ""
loop: 0
format: ""
- field: status
note: 实例状态
range: running{3},stopped{3},creating{2},abnormal{1},initializing{1}
prefix: ""
postfix: ""
loop: 0
format: ""
- field: pinned
note: 是否置顶
range: '0{8},1{2}'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: domain
note: 域名
range: test{1-10}.example.com
prefix: ""
postfix: ""
loop: 0
format: ""
- field: smtpSnippetName
note: SMTP片段名称
range: '""'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: ldapSnippetName
note: LDAP片段名称
range: '""'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: dbSettings
note: 数据库设置
range: '{}'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: autoBackup
note: 自动备份
range: '0{7},1{3}'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: backupKeepDays
note: 备份保留天数
range: 7,15,30
prefix: ""
postfix: ""
loop: 0
format: ""
- field: createdBy
note: 创建者
range: admin,user1,user2
prefix: ""
postfix: ""
loop: 0
format: ""
- field: createdAt
note: 创建时间
range: (3d)-(1d)
prefix: ""
postfix: ""
loop: 0
format: "YYYY-MM-DD hh:mm:ss"
- field: editedBy
note: 编辑者
range: '""'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: editedDate
note: 编辑时间
range: '""'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: deleted
note: 是否删除
range: 0
prefix: ""
postfix: ""
loop: 0
format: ""