From adedf46f959f335ea9ade5fba323d4b87511e769 Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 5 Nov 2025 19:44:26 +0800 Subject: [PATCH] + [misc] Add unit tests for instanceModel::stop() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/instance/test/model/stop.php | 93 +++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 module/instance/test/model/stop.php diff --git a/module/instance/test/model/stop.php b/module/instance/test/model/stop.php new file mode 100755 index 0000000000..cab6aea721 --- /dev/null +++ b/module/instance/test/model/stop.php @@ -0,0 +1,93 @@ +#!/usr/bin/env php +id->range('1-5'); +$instanceTable->name->range('test-app{5}'); +$instanceTable->k8name->range('test-k8-{5}'); +$instanceTable->chart->range('zentao,gitlab,jenkins,sonar,mysql'); +$instanceTable->status->range('running{2},abnormal{1},stopped{1},starting{1}'); +$instanceTable->channel->range('stable{5}'); +$instanceTable->space->range('1-5'); +$instanceTable->deleted->range('0{5}'); +$instanceTable->gen(5); + +$spaceTable = zenData('space'); +$spaceTable->id->range('1-5'); +$spaceTable->k8space->range('default,test-space,dev-space,prod-space,staging-space'); +$spaceTable->name->range('默认空间,测试空间,开发空间,生产空间,演示空间'); +$spaceTable->deleted->range('0{5}'); +$spaceTable->gen(5); + +// 3. 用户登录 +su('admin'); + +// 4. 创建测试实例 +$instanceTest = new instanceTest(); + +// 5. 测试步骤(至少5个) +// 构造测试实例对象 +$runningInstance = new stdclass(); +$runningInstance->id = 1; +$runningInstance->k8name = 'test-k8-1'; +$runningInstance->chart = 'zentao'; +$runningInstance->channel = 'stable'; +$runningInstance->spaceData = new stdclass(); +$runningInstance->spaceData->k8space = 'default'; + +$badRequestInstance = new stdclass(); +$badRequestInstance->id = 2; +$badRequestInstance->k8name = 'test-k8-2'; +$badRequestInstance->chart = 'gitlab'; +$badRequestInstance->channel = 'stable'; +$badRequestInstance->spaceData = new stdclass(); +$badRequestInstance->spaceData->k8space = 'test-space'; + +$serverErrorInstance = new stdclass(); +$serverErrorInstance->id = 3; +$serverErrorInstance->k8name = 'test-k8-3'; +$serverErrorInstance->chart = 'jenkins'; +$serverErrorInstance->channel = 'stable'; +$serverErrorInstance->spaceData = new stdclass(); +$serverErrorInstance->spaceData->k8space = 'dev-space'; + +$notFoundInstance = new stdclass(); +$notFoundInstance->id = 4; +$notFoundInstance->k8name = 'test-k8-4'; +$notFoundInstance->chart = 'sonar'; +$notFoundInstance->channel = 'stable'; +$notFoundInstance->spaceData = new stdclass(); +$notFoundInstance->spaceData->k8space = 'prod-space'; + +$stoppedInstance = new stdclass(); +$stoppedInstance->id = 5; +$stoppedInstance->k8name = 'test-k8-5'; +$stoppedInstance->chart = 'mysql'; +$stoppedInstance->channel = 'stable'; +$stoppedInstance->spaceData = new stdclass(); +$stoppedInstance->spaceData->k8space = 'staging-space'; + +r($instanceTest->stopTest($runningInstance)) && p('code') && e('200'); // 步骤1:正常停止运行中的实例 +r($instanceTest->stopTest($badRequestInstance)) && p('code') && e('400'); // 步骤2:停止异常状态的实例 +r($instanceTest->stopTest($serverErrorInstance)) && p('code') && e('500'); // 步骤3:停止服务器错误的实例 +r($instanceTest->stopTest($notFoundInstance)) && p('code') && e('404'); // 步骤4:停止不存在的实例 +r($runningInstance->k8name) && p() && e('test-k8-1'); // 步骤5:验证实例k8name属性 \ No newline at end of file