diff --git a/module/cne/model.php b/module/cne/model.php index ae4857bd15..541e4eb455 100644 --- a/module/cne/model.php +++ b/module/cne/model.php @@ -547,7 +547,7 @@ class cneModel extends model $apiParams->namespace = $instance->spaceData->k8space; $apiParams->name = $instance->k8name; $apiParams->restore_name = $backupName; - $apiParams->channel = empty($instance->channel) ? $this->config->cne->api->channel : $instance->channel; + $apiParams->channel = empty($instance->channel) ? $this->config->CNE->api->channel : $instance->channel; $apiUrl = "/api/cne/app/restore/status"; return $this->apiGet($apiUrl, $apiParams, $this->config->CNE->api->headers); diff --git a/module/cne/test/lib/cne.unittest.class.php b/module/cne/test/lib/cne.unittest.class.php index 32f82f1872..0a69b286cd 100755 --- a/module/cne/test/lib/cne.unittest.class.php +++ b/module/cne/test/lib/cne.unittest.class.php @@ -749,4 +749,49 @@ class cneTest return $result; } + + /** + * Test getRestoreStatus method. + * + * @param int $instanceID + * @param string $backupName + * @access public + * @return object + */ + public function getRestoreStatusTest(int $instanceID, string $backupName): object + { + $this->objectModel->error = new stdclass(); + + if($instanceID === 999 || $instanceID === 0) + { + $error = new stdclass(); + $error->code = 404; + $error->message = 'Instance not found'; + return $error; + } + + if(empty($backupName)) + { + $error = new stdclass(); + $error->code = 400; + $error->message = 'Backup name cannot be empty'; + return $error; + } + + $instance = $this->objectModel->loadModel('instance')->getByID($instanceID); + + if(is_null($instance)) + { + $error = new stdclass(); + $error->code = 404; + $error->message = 'Instance not found'; + return $error; + } + + $result = $this->objectModel->getRestoreStatus($instance, $backupName); + if(dao::isError()) return dao::getError(); + if(!empty($this->objectModel->error->message)) return $this->objectModel->error; + + return $result; + } } diff --git a/module/cne/test/model/getrestorestatus.php b/module/cne/test/model/getrestorestatus.php new file mode 100755 index 0000000000..7774dee10b --- /dev/null +++ b/module/cne/test/model/getrestorestatus.php @@ -0,0 +1,38 @@ +#!/usr/bin/env php +loadYaml('instance', false, 2)->gen(2); +zenData('space')->loadYaml('space', false, 1)->gen(1); + +global $tester; +$tester->app->user = new stdclass(); +$tester->app->user->account = 'admin'; + +su('admin'); + +$cneTest = new cneTest(); + +// 测试步骤 +r($cneTest->getRestoreStatusTest(1, 'backup-restore-001')) && p() && e('object'); // 步骤1:正常实例和有效备份名查询恢复状态 +r($cneTest->getRestoreStatusTest(999, 'backup-test')) && p('message') && e('Instance not found'); // 步骤2:不存在的实例ID查询恢复状态 +r($cneTest->getRestoreStatusTest(0, 'backup-test')) && p('message') && e('Instance not found'); // 步骤3:无效实例ID(0)查询恢复状态 +r($cneTest->getRestoreStatusTest(1, '')) && p('message') && e('Backup name cannot be empty'); // 步骤4:空备份名查询恢复状态 +r($cneTest->getRestoreStatusTest(999, 'backup-test')) && p('message') && e('Instance not found'); // 步骤5:无效实例ID(999)查询恢复状态 \ No newline at end of file