Skip to content

Commit e7df02c

Browse files
authored
update regiontest (#120)
1 parent 6110aef commit e7df02c

File tree

3 files changed

+64
-9
lines changed

3 files changed

+64
-9
lines changed

src/Qcloud/Cos/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct($cosConfig) {
3434
$this->rawCosConfig = $cosConfig;
3535
$this->cosConfig['schema'] = isset($cosConfig['schema']) ? $cosConfig['schema'] : 'http';
3636
$this->cosConfig['endpoint'] = isset($cosConfig['endpoint']) ? $cosConfig['endpoint'] : null;
37-
$this->cosConfig['region'] = isset($regionmap[$cosConfig['region']]) ? region_map($cosConfig['region']) : $cosConfig['region'];
37+
$this->cosConfig['region'] = region_map($cosConfig['region']);
3838
$this->cosConfig['appId'] = isset($cosConfig['credentials']['appId']) ? $cosConfig['credentials']['appId'] : null;
3939
$this->cosConfig['secretId'] = isset($cosConfig['credentials']['secretId']) ? $cosConfig['credentials']['secretId'] : "";
4040
$this->cosConfig['secretKey'] = isset($cosConfig['credentials']['secretKey']) ? $cosConfig['credentials']['secretKey'] : "";

src/Qcloud/Cos/Common.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Qcloud\Cos;
44

5-
$regionmap = array('cn-east'=>'ap-shanghai',
5+
function region_map($region) {
6+
$regionmap = array('cn-east'=>'ap-shanghai',
67
'cn-south'=>'ap-guangzhou',
78
'cn-north'=>'ap-beijing-1',
89
'cn-south-2'=>'ap-guangzhou-2',
@@ -13,11 +14,9 @@
1314
'sh'=>'ap-shanghai',
1415
'gz'=>'ap-guangzhou',
1516
'cd'=>'ap-chengdu',
16-
'sgp'=>'ap-singapore',);
17-
18-
function region_map($region) {
19-
if (array_key_exists($region, regionmap)) {
20-
return regionmap[$region];
17+
'sgp'=>'ap-singapore');
18+
if (array_key_exists($region, $regionmap)) {
19+
return $regionmap[$region];
2120
}
2221
return $region;
2322
}

src/Qcloud/Cos/Tests/Test.php

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ protected function tearDown() {
3232
/**********************************
3333
* TestBucket
3434
**********************************/
35-
36-
/*
35+
36+
/*
3737
* put bucket,bucket已经存在
3838
* BucketAlreadyOwnedByYou
3939
* 409
@@ -47,6 +47,62 @@ public function testCreateExistingBucket()
4747
}
4848
}
4949

50+
/*
51+
* put bucket, 创建所有region的bucket
52+
* 409
53+
*/
54+
public function testValidRegionBucket()
55+
{
56+
$regionlist = array('cn-east','ap-shanghai',
57+
'cn-south','ap-guangzhou',
58+
'cn-north','ap-beijing-1',
59+
'cn-south-2','ap-guangzhou-2',
60+
'cn-southwest','ap-chengdu',
61+
'sg','ap-singapore',
62+
'tj','ap-beijing-1',
63+
'bj','ap-beijing',
64+
'sh','ap-shanghai',
65+
'gz','ap-guangzhou',
66+
'cd','ap-chengdu',
67+
'sgp','ap-singapore');
68+
foreach ($regionlist as$region) {
69+
try {
70+
71+
$this->cosClient = new Client(array('region' => $region,
72+
'credentials' => array(
73+
'appId' => getenv('COS_APPID'),
74+
'secretId' => getenv('COS_KEY'),
75+
'secretKey' => getenv('COS_SECRET'))));
76+
$this->cosClient->createBucket(['Bucket' => $this->bucket]);
77+
} catch (ServiceResponseException $e) {
78+
$this->assertEquals([$e->getStatusCode()], [409]);
79+
}
80+
}
81+
}
82+
83+
/*
84+
* put bucket, 不合法的region名
85+
* 409
86+
*/
87+
public function testInvalidRegionBucket()
88+
{
89+
$regionlist = array('cn-east-2','ap-shanghai-3');
90+
foreach ($regionlist as$region) {
91+
try {
92+
$this->cosClient = new Client(array('region' => $region,
93+
'credentials' => array(
94+
'appId' => getenv('COS_APPID'),
95+
'secretId' => getenv('COS_KEY'),
96+
'secretKey' => getenv('COS_SECRET'))));
97+
$this->cosClient->createBucket(['Bucket' => $this->bucket]);
98+
} catch (ServiceResponseException $e) {
99+
$this->assertFalse(TRUE);
100+
} catch (\GuzzleHttp\Exception\ConnectException $e) {
101+
$this->assertTrue(TRUE);
102+
}
103+
}
104+
}
105+
50106
/*
51107
* put bucket,bucket名称非法
52108
* InvalidBucketName

0 commit comments

Comments
 (0)