+ [misc] Add unit tests for systemModel::getBackupList() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -39,4 +39,19 @@ class systemTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getBackupList method.
|
||||
*
|
||||
* @param object $instance
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBackupListTest($instance)
|
||||
{
|
||||
$result = $this->objectModel->getBackupList($instance);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 systemModel::getBackupList();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:正常实例获取备份列表属性result @fail
|
||||
- 步骤2:获取备份列表消息字段属性message @CNE服务器出错
|
||||
- 步骤3:获取备份列表数据字段属性data @~~
|
||||
- 步骤4:无效实例获取备份列表属性result @fail
|
||||
- 步骤5:空实例获取备份列表属性result @fail
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/system.unittest.class.php';
|
||||
|
||||
// 2. zendata数据准备(根据需要配置)
|
||||
$spaceTable = zenData('space');
|
||||
$spaceTable->loadYaml('space_getbackuplist', false, 2)->gen(5);
|
||||
|
||||
$instanceTable = zenData('instance');
|
||||
$instanceTable->loadYaml('instance_getbackuplist', false, 2)->gen(10);
|
||||
|
||||
// 3. 用户登录(选择合适角色)
|
||||
su('admin');
|
||||
|
||||
// 4. 创建测试实例(变量名与模块名一致)
|
||||
$systemTest = new systemTest();
|
||||
|
||||
// 5. 创建测试实例对象
|
||||
$spaceData = new stdClass();
|
||||
$spaceData->k8space = 'test-namespace';
|
||||
|
||||
$validInstance = new stdClass();
|
||||
$validInstance->id = 1;
|
||||
$validInstance->name = 'test-instance';
|
||||
$validInstance->space = 1;
|
||||
$validInstance->status = 'running';
|
||||
$validInstance->deleted = '0';
|
||||
$validInstance->k8name = 'zentao-1';
|
||||
$validInstance->spaceData = $spaceData;
|
||||
$validInstance->channel = '';
|
||||
|
||||
$invalidSpaceData = new stdClass();
|
||||
$invalidSpaceData->k8space = 'invalid-namespace';
|
||||
|
||||
$invalidInstance = new stdClass();
|
||||
$invalidInstance->id = 999;
|
||||
$invalidInstance->name = 'invalid-instance';
|
||||
$invalidInstance->space = 999;
|
||||
$invalidInstance->status = 'failed';
|
||||
$invalidInstance->deleted = '1';
|
||||
$invalidInstance->k8name = 'invalid-k8name';
|
||||
$invalidInstance->spaceData = $invalidSpaceData;
|
||||
$invalidInstance->channel = '';
|
||||
|
||||
$emptyInstance = new stdClass();
|
||||
$emptyInstance->spaceData = new stdClass();
|
||||
$emptyInstance->spaceData->k8space = '';
|
||||
$emptyInstance->k8name = '';
|
||||
$emptyInstance->channel = '';
|
||||
|
||||
// 6. 🔴 强制要求:必须包含至少5个测试步骤
|
||||
r($systemTest->getBackupListTest($validInstance)) && p('result') && e('fail'); // 步骤1:正常实例获取备份列表
|
||||
r($systemTest->getBackupListTest($validInstance)) && p('message') && e('CNE服务器出错'); // 步骤2:获取备份列表消息字段
|
||||
r($systemTest->getBackupListTest($validInstance)) && p('data') && e('~~'); // 步骤3:获取备份列表数据字段
|
||||
r($systemTest->getBackupListTest($invalidInstance)) && p('result') && e('fail'); // 步骤4:无效实例获取备份列表
|
||||
r($systemTest->getBackupListTest($emptyInstance)) && p('result') && e('fail'); // 步骤5:空实例获取备份列表
|
||||
@@ -0,0 +1,58 @@
|
||||
---
|
||||
title: Instance data for getBackupList test
|
||||
desc: Test data for testing systemModel::getBackupList() method
|
||||
author: Claude
|
||||
version: 1.0
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: Instance ID
|
||||
range: 1-10
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
format: ""
|
||||
|
||||
- field: space
|
||||
note: Space ID
|
||||
range: 1-3
|
||||
format: ""
|
||||
|
||||
- field: name
|
||||
note: Instance name
|
||||
range: test-instance{3}, prod-instance{3}, dev-instance{2}, backup-instance{2}
|
||||
format: ""
|
||||
|
||||
- field: appName
|
||||
note: Application name
|
||||
range: zentao{5}, jenkins{3}, gitlab{2}
|
||||
format: ""
|
||||
|
||||
- field: k8name
|
||||
note: Kubernetes name
|
||||
range: zentao-1{3}, jenkins-1{2}, gitlab-1{2}, zentao-2{3}
|
||||
format: ""
|
||||
|
||||
- field: chart
|
||||
note: Helm chart name
|
||||
range: zentao{5}, jenkins{3}, gitlab{2}
|
||||
format: ""
|
||||
|
||||
- field: status
|
||||
note: Instance status
|
||||
range: running{7}, stopped{2}, failed{1}
|
||||
format: ""
|
||||
|
||||
- field: deleted
|
||||
note: Delete status
|
||||
range: 0{9}, 1{1}
|
||||
format: ""
|
||||
|
||||
- field: createdBy
|
||||
note: Creator
|
||||
range: admin{5}, user{3}, tester{2}
|
||||
format: ""
|
||||
|
||||
- field: createdAt
|
||||
note: Creation time
|
||||
range: (now)-(1w)
|
||||
format: YYYY-MM-DD hh:mm:ss
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
title: Space data for getBackupList test
|
||||
desc: Test data for space table used in systemModel::getBackupList() method
|
||||
author: Claude
|
||||
version: 1.0
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: Space ID
|
||||
range: 1-5
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
format: ""
|
||||
|
||||
- field: name
|
||||
note: Space name
|
||||
range: test-space{2}, prod-space{2}, dev-space{1}
|
||||
format: ""
|
||||
|
||||
- field: k8space
|
||||
note: Kubernetes namespace
|
||||
range: test-ns{2}, prod-ns{2}, dev-ns{1}
|
||||
format: ""
|
||||
|
||||
- field: owner
|
||||
note: Space owner
|
||||
range: admin{2}, user{2}, tester{1}
|
||||
format: ""
|
||||
|
||||
- field: status
|
||||
note: Space status
|
||||
range: active{4}, inactive{1}
|
||||
format: ""
|
||||
|
||||
- field: deleted
|
||||
note: Delete status
|
||||
range: 0{4}, 1{1}
|
||||
format: ""
|
||||
|
||||
- field: createdBy
|
||||
note: Creator
|
||||
range: admin{3}, user{2}
|
||||
format: ""
|
||||
|
||||
- field: createdAt
|
||||
note: Creation time
|
||||
range: (now)-(2w)
|
||||
format: YYYY-MM-DD hh:mm:ss
|
||||
Reference in New Issue
Block a user