From 9e077c491604f9a66f41f8fbdccfe9ef1d6099da Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 8 Sep 2025 15:31:58 +0800 Subject: [PATCH] + [misc] Add unit tests for instanceModel::k8nameExists() 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 --- .../test/lib/instance.unittest.class.php | 15 ++++++++ module/instance/test/model/k8nameexists.php | 35 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 module/instance/test/model/k8nameexists.php diff --git a/module/instance/test/lib/instance.unittest.class.php b/module/instance/test/lib/instance.unittest.class.php index 56fd20d93a..eebb98e407 100644 --- a/module/instance/test/lib/instance.unittest.class.php +++ b/module/instance/test/lib/instance.unittest.class.php @@ -88,4 +88,19 @@ class instanceTest return $result; } + + /** + * Test k8nameExists method. + * + * @param string $k8name + * @access public + * @return mixed + */ + public function k8nameExistsTest(string $k8name) + { + $result = $this->objectModel->k8nameExists($k8name); + if(dao::isError()) return dao::getError(); + + return $result; + } } \ No newline at end of file diff --git a/module/instance/test/model/k8nameexists.php b/module/instance/test/model/k8nameexists.php new file mode 100755 index 0000000000..9abb449061 --- /dev/null +++ b/module/instance/test/model/k8nameexists.php @@ -0,0 +1,35 @@ +#!/usr/bin/env php +id->range('1-5'); +$table->k8name->range('test-k8name-1,test-k8name-2,test-k8name-3,test-k8name-4,test-k8name-5'); +$table->deleted->range('0{4},1'); +$table->gen(5); + +su('admin'); + +$instanceTest = new instanceTest(); + +r($instanceTest->k8nameExistsTest('test-k8name-1')) && p() && e('1'); +r($instanceTest->k8nameExistsTest('nonexistent-k8name')) && p() && e('0'); +r($instanceTest->k8nameExistsTest('')) && p() && e('0'); +r($instanceTest->k8nameExistsTest('test-k8name-5')) && p() && e('0'); +r($instanceTest->k8nameExistsTest('test-k8name-special')) && p() && e('0'); \ No newline at end of file