From 5dddf28232b6bf55f1bf957b9a26774c0b95c205 Mon Sep 17 00:00:00 2001 From: liyang Date: Tue, 12 Mar 2024 16:30:14 +0800 Subject: [PATCH] + Add unit test in gitfox module. --- module/gitfox/model.php | 16 ------ module/gitfox/test/gitfox.class.php | 51 +++++++++++++++++ module/gitfox/test/model/getbyid.php | 30 ++++++++++ module/gitfox/test/model/getlist.php | 24 ++++++++ module/gitfox/test/model/getpairs.php | 23 ++++++++ module/gitfox/test/yaml/oauth.yaml | 17 ++++++ module/gitfox/test/yaml/relation.yaml | 82 +++++++++++++++++++++++++++ module/gitfox/test/yaml/repo.yaml | 31 ++++++++++ test/data/pipeline.yaml | 16 +++--- 9 files changed, 266 insertions(+), 24 deletions(-) create mode 100755 module/gitfox/test/gitfox.class.php create mode 100755 module/gitfox/test/model/getbyid.php create mode 100755 module/gitfox/test/model/getlist.php create mode 100755 module/gitfox/test/model/getpairs.php create mode 100644 module/gitfox/test/yaml/oauth.yaml create mode 100644 module/gitfox/test/yaml/relation.yaml create mode 100644 module/gitfox/test/yaml/repo.yaml diff --git a/module/gitfox/model.php b/module/gitfox/model.php index 268aad5a94..f19d3a4e0a 100644 --- a/module/gitfox/model.php +++ b/module/gitfox/model.php @@ -73,21 +73,5 @@ class gitfoxModel extends model return $users; } - - /** - * 获取gitfox api 基础url 根据gitfox id。 - * Get gitfox api base url by gitfox id. - * - * @param int $gitfoxID - * @access public - * @return string - */ - public function getApiRoot(int $gitfoxID): string - { - $gitfox = $this->getByID($gitfoxID); - if(!$gitfox || $gitfox->type != 'gitfox') return ''; - - return rtrim($gitfox->url, '/') . '/api/v1%s'; - } } diff --git a/module/gitfox/test/gitfox.class.php b/module/gitfox/test/gitfox.class.php new file mode 100755 index 0000000000..95f0e56b2b --- /dev/null +++ b/module/gitfox/test/gitfox.class.php @@ -0,0 +1,51 @@ +tester = $tester; + $this->gitfox = $this->tester->loadModel('gitfox'); + } + + /** + * Get by id. + * + * @param int $id + * @access public + * @return object + */ + public function getByID($id) + { + $gitfox = $this->gitfox->getByID($id); + if(empty($gitfox)) return 0; + return $gitfox; + } + + /** + * Get gitfox list. + * + * @param string $orderBy + * @access public + * @return object + */ + public function getList($orderBy = 'id_desc') + { + $gitfox = $this->gitfox->getList($orderBy); + if(empty($gitfox)) return 0; + return $gitfox; + } + + /** + * Get gitfox pairs + * + * @return string + */ + public function getPairs() + { + $pairs = $this->gitfox->getPairs(); + return $pairs; + } +} diff --git a/module/gitfox/test/model/getbyid.php b/module/gitfox/test/model/getbyid.php new file mode 100755 index 0000000000..c85ca75642 --- /dev/null +++ b/module/gitfox/test/model/getbyid.php @@ -0,0 +1,30 @@ +#!/usr/bin/env php +gitById(); +timeout=0 +cid=1 + +- 使用存在的ID属性id @1 +- 使用空的ID @0 +- 使用不存在的ID @0 + +*/ + +zdTable('pipeline')->gen(7); + +$gitfox = new gitfoxTest(); + +$gitfoxID = 1; +r($gitfox->getById($gitfoxID)) && p('id') && e('7'); // 使用存在的ID + +$gitfoxID = 0; +r($gitfox->getById($gitfoxID)) && p() && e(0); // 使用空的ID + +$gitfoxID = 111; +r($gitfox->getById($gitfoxID)) && p() && e(0); // 使用不存在的ID diff --git a/module/gitfox/test/model/getlist.php b/module/gitfox/test/model/getlist.php new file mode 100755 index 0000000000..b23a8f292a --- /dev/null +++ b/module/gitfox/test/model/getlist.php @@ -0,0 +1,24 @@ +#!/usr/bin/env php +gitList(); +timeout=0 +cid=1 + +- 获取GitFox列表第1条的id属性 @1 +- 获取GitFox列表数量 @1 + +*/ + +zdTable('pipeline')->gen(7); +$gitfox = new gitfoxTest(); + +$orderBy = 'id_desc'; +$gitfoxList = $gitfox->getList($orderBy); +r($gitfoxList) && p('7:id') && e('1'); // 获取GitFox列表 +r(count($gitfoxList)) && p('') && e('1'); // 获取GitFox列表数量 diff --git a/module/gitfox/test/model/getpairs.php b/module/gitfox/test/model/getpairs.php new file mode 100755 index 0000000000..3488d4cb47 --- /dev/null +++ b/module/gitfox/test/model/getpairs.php @@ -0,0 +1,23 @@ +#!/usr/bin/env php +gitPairs(); +timeout=0 +cid=1 + +- 获取GitFox id为1的名字。属性1 @GitFox服务器 +- 获取GitFox 列表数量。 @1 + +*/ + +zdTable('pipeline')->gen(7); +$gitfox = new gitfoxTest(); + +$gitfoxPairs = $gitfox->getPairs(); +r($gitfoxPairs) && p(7) && e('GitFox服务器'); // 获取GitFox id为1的名字。 +r(count($gitfoxPairs)) && p() && e('1'); // 获取GitFox 列表数量。 diff --git a/module/gitfox/test/yaml/oauth.yaml b/module/gitfox/test/yaml/oauth.yaml new file mode 100644 index 0000000000..5b2acbe354 --- /dev/null +++ b/module/gitfox/test/yaml/oauth.yaml @@ -0,0 +1,17 @@ +title: table zt_oauth +desc: "" +author: automated export +version: "1.0" +fields: + - field: account + fields: + - field: account1 + range: user + - field: account2 + range: 3-100 + - field: openID + range: 1-98,root{2} + - field: providerType + range: gitlab + - field: providerID + range: 1 diff --git a/module/gitfox/test/yaml/relation.yaml b/module/gitfox/test/yaml/relation.yaml new file mode 100644 index 0000000000..031a03018e --- /dev/null +++ b/module/gitfox/test/yaml/relation.yaml @@ -0,0 +1,82 @@ +title: table zt_relation +desc: "issue关系" +author: automated export +version: "1.0" +fields: + - field: id + note: "ID" + range: 1-4 + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: product + note: "所属产品" + range: 1 + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: execution + note: "所属执行" + range: "2,1" + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: AType + note: "object类型" + range: task,bug,story + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: AID + note: "自身ID" + range: "18,5,8,19" + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: AVersion + note: "自身版本" + range: 2 + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: relation + note: "关联关系" + range: gitlab + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: BType + note: "被关联需求类型" + range: issue + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: BID + note: "被关联需求ID" + range: "4,3,2,1" + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: BVersion + note: "被关联版本" + range: 2 + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: extra + note: "" + range: 1 + prefix: "" + postfix: "" + loop: 0 + format: "" diff --git a/module/gitfox/test/yaml/repo.yaml b/module/gitfox/test/yaml/repo.yaml new file mode 100644 index 0000000000..e85a178e96 --- /dev/null +++ b/module/gitfox/test/yaml/repo.yaml @@ -0,0 +1,31 @@ +title: repo. +desc: repo data. +author: Zeng Gang +version: "1.0" +fields: +- field: id + range: 1-5 +- field: product + range: 1 +- field: name + range: testHtml,project1,unittest +- field: path + range: "[http://gitlabdev.qc.oop.cc/gitlab-instance-76af86df/testhtml],[],[/var/www/html/gitlab/test2/zentaopms/www/data/repo/unittest_gitea]" +- field: SCM + range: Gitlab{2},Gitea +- field: client + range: git +- field: serviceHost + range: 1{2},4 +- field: serviceProject + range: "2,1,[gitea/unittest]" +- field: commits + range: 0{2},2 +- field: extra + range: 9 +- field: preMerge + range: 0 +- field: job + range: 0 +- field: deleted + range: 0 diff --git a/test/data/pipeline.yaml b/test/data/pipeline.yaml index 7bbc576438..32581f5132 100644 --- a/test/data/pipeline.yaml +++ b/test/data/pipeline.yaml @@ -3,21 +3,21 @@ author: Zeng gang version: "1.0" fields: - field: id - range: 1-6 + range: 1-7 - field: type - range: gitlab,sonarqube,jenkins,gitea,gogs,nexus + range: gitlab,sonarqube,jenkins,gitea,gogs,nexus,gitfox - field: name - range: GitLab服务器,SonarQube服务器,Jenkins服务器,Gitea服务器,Gogs服务器,Nexus服务器 + range: GitLab服务器,SonarQube服务器,Jenkins服务器,Gitea服务器,Gogs服务器,Nexus服务器,GitFox服务器 - field: url - range: "[https://gitlabdev.qc.oop.cc],[https://sonardev.qc.oop.cc],[https://jenkinsdev.qc.oop.cc],[https://giteadev.qc.oop.cc],[https://gogsdev.qc.oop.cc],[https://nexus3dev.qc.oop.cc]" + range: "[https://gitlabdev.qc.oop.cc],[https://sonardev.qc.oop.cc],[https://jenkinsdev.qc.oop.cc],[https://giteadev.qc.oop.cc],[https://gogsdev.qc.oop.cc],[https://nexus3dev.qc.oop.cc],[http://101.35.53.5:3000/]" - field: account - range: "root,sonar,jenkins,gitea,gogs-admin,admin" + range: "root,sonar,jenkins,gitea,gogs-admin,admin,[]" - field: password - range: "[bGFjdTdCSUgwTEljY21tbnZRQUs=],[a2tHQXpFMXA5cE9vcUpBOWJMSWg=],[MXJZN1JWREEyQlZrak81ME9qTUo=],[UGNVb1dhSFE1aUp6ZTl5RU9WYmk=],[RUgwM3ByWDJWUWVnOGRha1Fnc2g=],[TTV6c0dWemZUVDdMWGNoeFozN3I=]" + range: "[bGFjdTdCSUgwTEljY21tbnZRQUs=],[a2tHQXpFMXA5cE9vcUpBOWJMSWg=],[MXJZN1JWREEyQlZrak81ME9qTUo=],[UGNVb1dhSFE1aUp6ZTl5RU9WYmk=],[RUgwM3ByWDJWUWVnOGRha1Fnc2g=],[TTV6c0dWemZUVDdMWGNoeFozN3I=],[]" - field: token - range: '[glpat-b8Sa1pM9k9ygxMZYPN6w],[squ_00a8b5794f6fa527bfb8f2a6f382264b5d306b17],[11eb8b38c99143c7c6d872291e291abff4],[6149a6013047301b116389d50db5cbf599772082],[6aafc3d332b70312a680fedf26039c67e98cfabe],[d0b31569-1f36-3b0e-a8a0-c556e5627a3e]' + range: '[glpat-b8Sa1pM9k9ygxMZYPN6w],[squ_00a8b5794f6fa527bfb8f2a6f382264b5d306b17],[11eb8b38c99143c7c6d872291e291abff4],[6149a6013047301b116389d50db5cbf599772082],[6aafc3d332b70312a680fedf26039c67e98cfabe],[d0b31569-1f36-3b0e-a8a0-c556e5627a3e],[eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTAyMDk2ODcsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjQsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MTJ9fQ.MMtsV_h1BMe3iV5xHax06w0iasyOEPj4UkXxYDeETqw]' - field: private - range: 08bcc98f75d7d40053dc80722bdc117b,228b25587479f2fc7570428e8bcbabdc,ec8e41481723685d9106c88be5967c41,a56af13f4c4a6a4ed77f24e59794cf39,4fabcbd31314365506ebc56c0c83c1ec + range: 08bcc98f75d7d40053dc80722bdc117b,228b25587479f2fc7570428e8bcbabdc,ec8e41481723685d9106c88be5967c41,a56af13f4c4a6a4ed77f24e59794cf39,4fabcbd31314365506ebc56c0c83c1ec,65efec169bf37 - field: createdBy range: admin - field: createdDate