diff --git a/module/instance/test/lib/instance.unittest.class.php b/module/instance/test/lib/instance.unittest.class.php index f1a9d7952d..bf74592eb4 100644 --- a/module/instance/test/lib/instance.unittest.class.php +++ b/module/instance/test/lib/instance.unittest.class.php @@ -286,4 +286,19 @@ class instanceTest return $result; } + + /** + * Test batchFresh method. + * + * @param array $instances + * @access public + * @return mixed + */ + public function batchFreshTest(array $instances) + { + $result = $this->objectModel->batchFresh($instances); + if(dao::isError()) return dao::getError(); + + return $result; + } } \ No newline at end of file diff --git a/module/instance/test/model/batchfresh.php b/module/instance/test/model/batchfresh.php new file mode 100755 index 0000000000..978b2142b5 --- /dev/null +++ b/module/instance/test/model/batchfresh.php @@ -0,0 +1,74 @@ +#!/usr/bin/env php +gen(0); +zenData('space')->gen(0); + +// 3. 用户登录 +su('admin'); + +// 4. 创建测试实例 +$instanceTest = new instanceTest(); + +// 5. 创建测试实例对象 +$instance1 = new stdClass(); +$instance1->id = 1; +$instance1->status = 'running'; +$instance1->k8name = 'test-k8name-1'; +$instance1->version = '1.0.0'; +$instance1->chart = 'zentao'; +$instance1->spaceData = new stdClass(); +$instance1->spaceData->k8space = 'test-space-1'; + +$instance2 = new stdClass(); +$instance2->id = 2; +$instance2->status = 'stopped'; +$instance2->k8name = 'test-k8name-2'; +$instance2->version = '1.0.0'; +$instance2->chart = 'gitlab'; +$instance2->spaceData = new stdClass(); +$instance2->spaceData->k8space = 'test-space-1'; + +$instance3 = new stdClass(); +$instance3->id = 3; +$instance3->status = 'creating'; +$instance3->k8name = 'test-k8name-3'; +$instance3->version = '1.1.0'; +$instance3->chart = 'jenkins'; +$instance3->spaceData = new stdClass(); +$instance3->spaceData->k8space = 'test-space-2'; + +$invalidInstance = new stdClass(); +$invalidInstance->id = 999; +$invalidInstance->status = 'unknown'; +$invalidInstance->k8name = 'invalid-k8name'; +$invalidInstance->version = '1.0.0'; +$invalidInstance->chart = 'unknown'; +$invalidInstance->spaceData = new stdClass(); +$invalidInstance->spaceData->k8space = 'invalid-space'; + +// 6. 测试步骤 +r($instanceTest->batchFreshTest(array())) && p() && e('0'); // 步骤1:空实例数组 +r($instanceTest->batchFreshTest(array($instance1))) && p('0:id') && e('1'); // 步骤2:单个实例ID +r($instanceTest->batchFreshTest(array($instance1, $instance2))) && p('1:id') && e('2'); // 步骤3:多个实例第二个ID +r($instanceTest->batchFreshTest(array($instance3))) && p('0:status') && e('creating'); // 步骤4:状态获取 +r($instanceTest->batchFreshTest(array($invalidInstance))) && p('0:id') && e('999'); // 步骤5:异常实例ID \ No newline at end of file diff --git a/module/instance/test/model/yaml/instance_batchfresh.yaml b/module/instance/test/model/yaml/instance_batchfresh.yaml new file mode 100644 index 0000000000..6f919ddd3a --- /dev/null +++ b/module/instance/test/model/yaml/instance_batchfresh.yaml @@ -0,0 +1,46 @@ +--- +title: 批量更新实例状态测试数据 +desc: 用于测试batchFresh方法的实例数据 +author: Claude +version: 1.0 + +fields: +- field: id + note: 实例ID + range: 1-20 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: name + note: 实例名称 + range: test-instance-{1-20} + format: "" +- field: status + note: 实例状态 + range: running{8},stopped{5},creating{3},abnormal{2},destroying{2} +- field: k8name + note: K8S名称 + range: test-k8s-{1-20} +- field: version + note: 应用版本 + range: 1.0.0{5},1.1.0{7},1.2.0{8} +- field: space + note: 空间ID + range: 1-5:R +- field: deleted + note: 删除标记 + range: 0{18},1{2} +- field: domain + note: 域名 + range: test{1-20}.example.com +- field: chart + note: Chart名称 + range: zentao{5},gitlab{3},jenkins{4},sonar{3},nexus{5} +- field: createdBy + note: 创建者 + range: admin{10},user1{5},user2{5} +- field: createdAt + note: 创建时间 + range: 2024-01-01 00:00:00-2024-12-31 23:59:59 + format: YYYY-MM-DD hh:mm:ss \ No newline at end of file diff --git a/module/instance/test/model/yaml/space_batchfresh.yaml b/module/instance/test/model/yaml/space_batchfresh.yaml new file mode 100644 index 0000000000..a21d8bbc1e --- /dev/null +++ b/module/instance/test/model/yaml/space_batchfresh.yaml @@ -0,0 +1,33 @@ +--- +title: 空间数据测试配置 +desc: 用于测试实例关联的空间数据 +author: Claude +version: 1.0 + +fields: +- field: id + note: 空间ID + range: 1-10 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: name + note: 空间名称 + range: test-space-{1-10} +- field: k8space + note: K8S空间名称 + range: test-k8space-{1-10} +- field: deleted + note: 删除标记 + range: 0{9},1{1} +- field: owner + note: 空间所有者 + range: admin{5},user1{3},user2{2} +- field: createdBy + note: 创建者 + range: admin{6},user1{2},user2{2} +- field: createdAt + note: 创建时间 + range: 2024-01-01 00:00:00-2024-12-31 23:59:59 + format: YYYY-MM-DD hh:mm:ss \ No newline at end of file