* Add unit test for instance.

This commit is contained in:
sunguangming
2023-12-27 14:36:39 +08:00
parent 5bc22eb2da
commit a9cf0e82ff
4 changed files with 99 additions and 4 deletions
+7 -4
View File
@@ -342,13 +342,14 @@ class instanceModel extends model
}
/**
* 获取访问应用实例的URL。
* Get URL for visiting instance service.
*
* @param object $instance
* @access public
* @return string
*/
public function url($instance)
public function url(object $instance): string
{
$url = "//" . $instance->domain;
$port = getenv('APP_HTTPS_PORT');
@@ -365,7 +366,7 @@ class instanceModel extends model
* @access public
* @return string
*/
public function randThirdDomain($length = 4, $triedTimes = 0)
public function randThirdDomain(int $length = 4, int $triedTimes = 0): string
{
if($triedTimes > 16) $length++;
@@ -376,25 +377,27 @@ class instanceModel extends model
}
/**
* 返回完整域名。
* Return full domain.
*
* @param string $thirdDomain
* @access public
* @return string
*/
public function fullDomain($thirdDomain)
public function fullDomain(string $thirdDomain): string
{
return $thirdDomain . '.' . $this->cne->sysDomain();
}
/**
* 检查域名是否存在。
* Check if the domain exists.
*
* @param string $thirdDomain
* @access public
* @return bool true: exists, false: not exist.
*/
public function domainExists($thirdDomain)
public function domainExists(string $thirdDomain): bool
{
$domain = $this->fullDomain($thirdDomain);
return boolval($this->dao->select('id')->from(TABLE_INSTANCE)->where('domain')->eq($domain)->andWhere('deleted')->eq(0)->fetch());
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
su('admin');
zdTable('instance')->gen(5);
$configData = zdTable('config');
$configData->owner->range('system');
$configData->module->range('common');
$configData->section->range('domain');
$configData->key->range('expiredDomain,customDomain');
$configData->value->range('`{"test":"dops.corp.cc"}`,dops.corp.cc');
$configData->gen(2);
/**
title=instanceModel->domainExists();
timeout=0
cid=1
- 查看该域名前缀是否存在 @0
- 查看该域名前缀是否存在 @1
- 查看该域名前缀是否存在 @1
- 查看该域名前缀是否存在 @1
*/
global $tester;
$tester->loadModel('instance');
r($tester->instance->domainExists('test')) && p('') && e('0'); // 查看该域名前缀是否存在
r($tester->instance->domainExists('rila')) && p('') && e('1'); // 查看该域名前缀是否存在
r($tester->instance->domainExists('7czx')) && p('') && e('1'); // 查看该域名前缀是否存在
r($tester->instance->domainExists('ane3')) && p('') && e('1'); // 查看该域名前缀是否存在
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
su('admin');
$configData = zdTable('config');
$configData->owner->range('system');
$configData->module->range('common');
$configData->section->range('domain');
$configData->key->range('expiredDomain,customDomain');
$configData->value->range('`{"test":"dops.corp.cc"}`,dops.corp.cc');
$configData->gen(2);
/**
title=instanceModel->fullDomain();
timeout=0
cid=1
- 查看完整域名 @test.dops.corp.cc
- 查看完整域名 @rila.dops.corp.cc
- 查看完整域名 @7czx.dops.corp.cc
- 查看完整域名 @ane3.dops.corp.cc
*/
global $tester;
$tester->loadModel('instance');
r($tester->instance->fullDomain('test')) && p('') && e('test.dops.corp.cc'); // 查看完整域名
r($tester->instance->fullDomain('rila')) && p('') && e('rila.dops.corp.cc'); // 查看完整域名
r($tester->instance->fullDomain('7czx')) && p('') && e('7czx.dops.corp.cc'); // 查看完整域名
r($tester->instance->fullDomain('ane3')) && p('') && e('ane3.dops.corp.cc'); // 查看完整域名
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
su('admin');
/**
title=instanceModel->getByID();
timeout=0
cid=1
- 查看获取到的域名前缀的长度 @2
- 查看获取到的域名前缀的长度 @3
- 查看获取到的域名前缀的长度 @4
- 查看获取到的域名前缀的长度 @5
*/
global $tester;
$tester->loadModel('instance');
r(strlen($tester->instance->randThirdDomain(2))) && p('') && e('2'); // 查看获取到的域名前缀的长度
r(strlen($tester->instance->randThirdDomain(3))) && p('') && e('3'); // 查看获取到的域名前缀的长度
r(strlen($tester->instance->randThirdDomain(4))) && p('') && e('4'); // 查看获取到的域名前缀的长度
r(strlen($tester->instance->randThirdDomain(5))) && p('') && e('5'); // 查看获取到的域名前缀的长度