From 3da26a490e0f08c85edc9259513486f52fa3ab67 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Thu, 28 Dec 2023 09:19:38 +0800 Subject: [PATCH] * Add the test file for updateImageStatus. --- module/zanode/control.php | 3 ++- module/zanode/model.php | 6 ++--- .../zanode/test/model/updateimagestatus.php | 27 +++++++++++++++++++ module/zanode/test/zanode.class.php | 15 +++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 module/zanode/test/model/updateimagestatus.php diff --git a/module/zanode/control.php b/module/zanode/control.php index f288c0b254..f5b1a6d5f9 100644 --- a/module/zanode/control.php +++ b/module/zanode/control.php @@ -490,7 +490,8 @@ class zanode extends control { if($_POST) { - $this->zanode->updateImageStatus($imageID); + $data = form::data()->get(); + $this->zanode->updateImageStatus($imageID, $data); if(dao::isError()) return $this->sendError(dao::getError()); return $this->sendSuccess(array('load' => true)); diff --git a/module/zanode/model.php b/module/zanode/model.php index dd3135c001..9646b50ff2 100644 --- a/module/zanode/model.php +++ b/module/zanode/model.php @@ -345,13 +345,13 @@ class zanodemodel extends model * 更新导出镜像的状态。 * Update Image status. * - * @param int $imageID + * @param int $imageID + * @param object $data * @access public * @return void */ - public function updateImageStatus(int $imageID): void + public function updateImageStatus(int $imageID, object $data): void { - $data = form::data()->get(); $this->dao->update(TABLE_IMAGE)->data($data)->where('id')->eq($imageID)->autoCheck()->exec(); } diff --git a/module/zanode/test/model/updateimagestatus.php b/module/zanode/test/model/updateimagestatus.php new file mode 100644 index 0000000000..2d108f0dad --- /dev/null +++ b/module/zanode/test/model/updateimagestatus.php @@ -0,0 +1,27 @@ +#!/usr/bin/env php +updateImageStatus(). +cid=1 + +- 测试修改镜像的状态和路径 + - 属性status @failed + - 属性path @/home/devops/zagent/download/ubuntu20.04.qcow2 + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/zanode.class.php'; + +zdTable('image')->gen(1); +zdTable('user')->gen(5); +su('admin'); + +$postData = new stdclass(); +$postData->status = 'failed'; +$postData->path = '/home/devops/zagent/download/ubuntu20.04.qcow2'; + +$zanode = new zanodeTest(); +r($zanode->updateImageStatusTest(1, $postData)) && p('status,path') && e('failed,/home/devops/zagent/download/ubuntu20.04.qcow2'); //测试修改镜像的状态和路径 diff --git a/module/zanode/test/zanode.class.php b/module/zanode/test/zanode.class.php index 550b38476b..967aac3c98 100644 --- a/module/zanode/test/zanode.class.php +++ b/module/zanode/test/zanode.class.php @@ -226,4 +226,19 @@ class zanodeTest $node = $this->getNodeByID($nodeID); return $this->getVncUrl($node); } + + /** + * 测试更新导出镜像的状态。 + * Test update Image status. + * + * @param int $imageID + * @param object $data + * @access public + * @return void + */ + public function updateImageStatusTest(int $imageID, object $data): object + { + $this->updateImageStatus($imageID, $data); + return $this->objectModel->dao->select('status,path')->from(TABLE_IMAGE)->where('id')->eq($imageID)->fetch(); + } }