From 6f9336c19ad3ad49ede6a8d856c398df7da5d103 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Wed, 27 Dec 2023 13:53:59 +0800 Subject: [PATCH] + Add unit test case for solution->getByID. --- module/solution/model.php | 2 +- module/solution/test/model/getbyid.php | 42 ++++++++++++++++ module/solution/test/solution.class.php | 26 ++++++++++ module/solution/test/yaml/instance.yaml | 66 +++++++++++++++++++++++++ module/solution/test/yaml/solution.yaml | 43 ++++++++++++++++ module/solution/test/yaml/space.yaml | 20 ++++++++ 6 files changed, 198 insertions(+), 1 deletion(-) create mode 100755 module/solution/test/model/getbyid.php create mode 100644 module/solution/test/solution.class.php create mode 100644 module/solution/test/yaml/instance.yaml create mode 100644 module/solution/test/yaml/solution.yaml create mode 100644 module/solution/test/yaml/space.yaml diff --git a/module/solution/model.php b/module/solution/model.php index 383ff61964..39c79c1d2a 100644 --- a/module/solution/model.php +++ b/module/solution/model.php @@ -21,7 +21,7 @@ class solutionModel extends model */ public function getByID(int $solutionID): ?object { - $solution = $this->dao->select('*')->from(TABLE_SOLUTION)->where('id')->eq($solutionID)->fetch(); + $solution = $this->dao->select('*')->from(TABLE_SOLUTION)->where('id')->eq($solutionID)->fetch(); if(!$solution) return null; $solution->instances = array(); diff --git a/module/solution/test/model/getbyid.php b/module/solution/test/model/getbyid.php new file mode 100755 index 0000000000..ff56675fe8 --- /dev/null +++ b/module/solution/test/model/getbyid.php @@ -0,0 +1,42 @@ +#!/usr/bin/env php +getByID(); +timeout=0 +cid=1 + +- 解决方案ID为空 @0 +- 解决方案ID存在 + - 属性name @禅道 DevOps 解决方案1 + - 属性status @notEnoughResource +- 解决方案ID存在,检查实例数量 @3 +- 解决方案ID存在 + - 属性name @禅道 DevOps 解决方案2 + - 属性status @notEnoughResource +- 解决方案ID存在,检查实例数量 @1 +- 解决方案ID不存在 @0 + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/solution.class.php'; + +zdTable('space')->config('space')->gen(2); +zdTable('solution')->config('solution')->gen(2); +zdTable('instance')->config('instance')->gen(4); + +$solutionModel = new solutionTest(); + +r($solutionModel->getByIdTest(0)) && p() && e('0'); // 解决方案ID为空 + +$solution = $solutionModel->getByIdTest(1); +r($solution) && p('name,status') && e('禅道 DevOps 解决方案1,notEnoughResource'); // 解决方案ID存在 +r(count($solution->instances)) && p() && e('3'); // 解决方案ID存在,检查实例数量 + +$solution = $solutionModel->getByIdTest(2); +r($solution) && p('name,status') && e('禅道 DevOps 解决方案2,notEnoughResource'); // 解决方案ID存在 +r(count($solution->instances)) && p() && e('1'); // 解决方案ID存在,检查实例数量 + +r($solutionModel->getByIdTest(5)) && p() && e('0'); // 解决方案ID不存在 \ No newline at end of file diff --git a/module/solution/test/solution.class.php b/module/solution/test/solution.class.php new file mode 100644 index 0000000000..c064a7cd51 --- /dev/null +++ b/module/solution/test/solution.class.php @@ -0,0 +1,26 @@ + + * @package solution + * @link https://www.zentao.net + */ +class solutionTest +{ + public function __construct() + { + su('admin'); + + global $tester; + $this->objectModel = $tester->loadModel('solution'); + } + + public function getByIdTest(int $solutionID): object|null + { + return $this->objectModel->getByID($solutionID); + } +} diff --git a/module/solution/test/yaml/instance.yaml b/module/solution/test/yaml/instance.yaml new file mode 100644 index 0000000000..6df6ba9328 --- /dev/null +++ b/module/solution/test/yaml/instance.yaml @@ -0,0 +1,66 @@ +--- +title: instance +author: Yanyi Cao +version: "1.0" +fields: + - field: id + range: 1-4 + - field: space + range: '1{2},2{2}' + - field: solution + range: '1{3},2' + - field: name + range: '`Jenkins`,`GitLab`,`GitLab`,`Jenkins`' + - field: appID + range: '`59`,`58`,`58`,`59`' + - field: appName + range: '`Jenkins`,`GitLab`,`GitLab`,`Jenkins`' + - field: appVersion + range: '`2.401.3`,`15.3.4`,`15.3.4`,`2.401.3`' + - field: chart + range: '`jenkins`,`gitlab`,`gitlab`,`jenkins`' + - field: logo + range: '`//img.qucheng.com/app/j/jenkins-icon.svg`,`//img.qucheng.com/app/g/gitlab-icon.svg`,`//img.qucheng.com/app/g/gitlab-icon.svg`,`//img.qucheng.com/app/j/jenkins-icon.svg`' + - field: version + range: '`2023.10.901`' + - field: desc + range: '`Jenkins是国际上流行的免费开源软件项目,是基于Java开发持续集成工具,用于监控持续重复的工作,旨在提供一个开放的易用的软件平台,使软件的持续集成自动化,大大节约人力和时效。`,`GitLab是由GitLab + Inc.开发,使用MIT许可证的基于网络的Git仓库管理工具,且具有wiki和issue跟踪功能。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。`,`GitLab是由GitLab + Inc.开发,使用MIT许可证的基于网络的Git仓库管理工具,且具有wiki和issue跟踪功能。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。`,`Jenkins是国际上流行的免费开源软件项目,是基于Java开发持续集成工具,用于监控持续重复的工作,旨在提供一个开放的易用的软件平台,使软件的持续集成自动化,大大节约人力和时效。`' + - field: introduction + range: '`基于Java开发的一款持续集成工具`,`GitLab 一款基于Git的一体化软件开发平台。`,`GitLab 一款基于Git的一体化软件开发平台。`,`基于Java开发的一款持续集成工具`' + - field: source + range: '`cloud`' + - field: channel + range: '`stable`' + - field: k8name + range: '`jenkins-20231019112830`,`gitlab-20231019131424`,`gitlab-20231025104407`,`jenkins-20231025104735`' + - field: status + range: '`running`,`starting`,,' + - field: pinned + range: "0" + - field: domain + range: '`jvud.devops.corp.cc`,`gmip.devops.corp.cc`,`9krd.devops.corp.cc`,`adkm.devops.corp.cc`' + - field: smtpSnippetName + range: "" + - field: ldapSnippetName + range: "" + - field: ldapSettings + range: "" + - field: dbSettings + range: '`{"ingress":{"enabled":true,"host":"jvud.devops.corp.cc"},"global":{"ingress":{"enabled":true,"host":"jvud.devops.corp.cc"}},"ci":{"enabled":true},"mysql":{"enabled":false,"auth":{"user":"user_52","password":"vmqA3pzlswbB","host":"qucheng-mysql.quickon-system.svc","port":3306,"database":"db_52","dbservice":{"name":"qucheng-mysql","namespace":"quickon-system"}}}}`,`{"ingress":{"enabled":true,"host":"gmip.devops.corp.cc"},"global":{"ingress":{"enabled":true,"host":"gmip.devops.corp.cc"}},"ci":{"enabled":true},"mysql":{"enabled":false,"auth":{"user":"user_53","password":"cjPmBztaTYvy","host":"qucheng-mysql.quickon-system.svc","port":3306,"database":"db_53","dbservice":{"name":"qucheng-mysql","namespace":"quickon-system"}}}}`,`{"ingress":{"enabled":true,"host":"9krd.devops.corp.cc"},"global":{"ingress":{"enabled":true,"host":"9krd.devops.corp.cc"}},"ci":{"enabled":true},"mysql":{"enabled":false,"auth":{"user":"user_54","password":"GTFyIESAUjsP","host":"qucheng-mysql.quickon-system.svc","port":3306,"database":"db_54","dbservice":{"name":"qucheng-mysql","namespace":"quickon-system"}}}}`,`{"ingress":{"enabled":true,"host":"adkm.devops.corp.cc"},"global":{"ingress":{"enabled":true,"host":"adkm.devops.corp.cc"}},"ci":{"enabled":true},"mysql":{"enabled":false,"auth":{"user":"user_55","password":"wvKn8a7JyxcZ","host":"qucheng-mysql.quickon-system.svc","port":3306,"database":"db_55","dbservice":{"name":"qucheng-mysql","namespace":"quickon-system"}}}}`' + - field: autoBackup + range: "0" + - field: backupKeepDays + range: '`1`' + - field: autoRestore + range: "0" + - field: env + range: "" + - field: createdBy + range: '`wwccss`' + - field: createdAt + range: '`2023-10-19 11:28:30`,`2023-10-19 13:14:24`,`2023-10-25 10:44:07`,`2023-10-25 10:47:35`' + - field: deleted + range: "0" +... diff --git a/module/solution/test/yaml/solution.yaml b/module/solution/test/yaml/solution.yaml new file mode 100644 index 0000000000..6d397c4d0c --- /dev/null +++ b/module/solution/test/yaml/solution.yaml @@ -0,0 +1,43 @@ +--- +title: solution +author: Yanyi Cao +version: "1.0" +fields: + - field: id + range: 1-2 + - field: name + prefix: '禅道 DevOps 解决方案' + range: 1-2 + - field: appID + range: '`2`' + - field: appName + range: '`devops`' + - field: appVersion + range: '`1.1.0`' + - field: version + range: '`2023.10.901`' + - field: chart + range: '`devops`' + - field: cover + range: '`https://img.qucheng.com/app/d/devops-bg.png`' + - field: desc + range: '`禅道 DevOps 解决方案是一套软件全生命周期管理、跟踪、集成、发布解决方案。包含禅道项目管理工具、代码仓库、集成工具等。用户可以跟踪软件项目进度,管理代码的集成与发布。`' + - field: introduction + range: '`覆盖从立项到发布,端到端的软件开发全流程跟踪。全面集成 Jenkins、Gitlab 等工具。`' + - field: source + range: '`cloud`' + - field: channel + range: '`stable`' + - field: components + range: '`{"git":{"id":58,"name":"gitlab","alias":"GitLab","chart":"gitlab","app_version":"15.3.4","version":"2023.10.901","logo":"https:\/\/img.qucheng.com\/app\/g\/gitlab-icon.svg","status":"installed"},"ci":{"id":59,"name":"jenkins","alias":"Jenkins","chart":"jenkins","app_version":"2.401.3","version":"2023.10.901","logo":"https:\/\/img.qucheng.com\/app\/j\/jenkins-icon.svg","status":"installing"}}`' + - field: status + range: '`notEnoughResource`' + - field: deleted + range: "0" + - field: createdBy + range: '`wwccss`' + - field: createdAt + range: '`2023-10-16 09:25:07`' + - field: updatedDate + range: '`2023-12-08 16:10:08`' +... diff --git a/module/solution/test/yaml/space.yaml b/module/solution/test/yaml/space.yaml new file mode 100644 index 0000000000..534a8c4700 --- /dev/null +++ b/module/solution/test/yaml/space.yaml @@ -0,0 +1,20 @@ +--- +title: space +author: Yanyi Cao +version: "1.0" +fields: + - field: id + range: 1-2 + - field: name + range: '`默认空间`' + - field: k8space + range: '`quickon-app`' + - field: owner + range: '`wwccss`,' + - field: default + range: '`1`' + - field: createdAt + range: '`2023-08-29 11:20:29`,`2023-10-16 09:25:11`' + - field: deleted + range: "0" +...