OssClientBucketStorageCapacityTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Core\OssException;
  4. require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
  5. class OssClientBucketStorageCapacityTest extends TestOssClientBase
  6. {
  7. public function testBucket()
  8. {
  9. try {
  10. $storageCapacity = $this->ossClient->getBucketStorageCapacity($this->bucket);
  11. $this->assertEquals($storageCapacity, -1);
  12. } catch (OssException $e) {
  13. $this->assertTrue(false);
  14. }
  15. try {
  16. $this->ossClient->putBucketStorageCapacity($this->bucket, 1000);
  17. } catch (OssException $e) {
  18. $this->assertTrue(false);
  19. }
  20. try {
  21. Common::waitMetaSync();
  22. $storageCapacity = $this->ossClient->getBucketStorageCapacity($this->bucket);
  23. $this->assertEquals($storageCapacity, 1000);
  24. } catch (OssException $e) {
  25. $this->assertTrue(false);
  26. }
  27. try {
  28. $this->ossClient->putBucketStorageCapacity($this->bucket, 0);
  29. Common::waitMetaSync();
  30. $storageCapacity = $this->ossClient->getBucketStorageCapacity($this->bucket);
  31. $this->assertEquals($storageCapacity, 0);
  32. $this->ossClient->putObject($this->bucket, 'test-storage-capacity','test-content');
  33. $this->assertTrue(false);
  34. } catch (OssException $e) {
  35. $this->assertEquals('Bucket storage exceed max storage capacity.',$e->getErrorMessage());
  36. }
  37. try {
  38. $this->ossClient->putBucketStorageCapacity($this->bucket, -2);
  39. $this->assertTrue(false);
  40. } catch (OssException $e) {
  41. $this->assertEquals(400, $e->getHTTPStatus());
  42. $this->assertEquals('InvalidArgument', $e->getErrorCode());
  43. }
  44. }
  45. }