SymlinkTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\OssClient;
  4. use OSS\Result\SymlinkResult;
  5. use OSS\Core\OssException;
  6. use OSS\Http\ResponseCore;
  7. require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
  8. class SymlinkTest extends TestOssClientBase
  9. {
  10. public function testPutSymlink()
  11. {
  12. $bucket = getenv('OSS_BUCKET');
  13. $symlink = 'test-link';
  14. $special_object = 'exist_object^$#!~';
  15. $object = 'exist_object';
  16. $this->ossClient ->putObject($bucket, $object, 'test_content');
  17. $this->ossClient->putSymlink($bucket, $symlink, $object);
  18. $result = $this->ossClient->getObject($bucket, $symlink);
  19. $this->assertEquals('test_content', $result);
  20. $this->ossClient ->putObject($bucket, $special_object, 'test_content');
  21. $this->ossClient->putSymlink($bucket, $symlink, $special_object);
  22. $result = $this->ossClient->getObject($bucket, $symlink);
  23. $this->assertEquals('test_content', $result);
  24. }
  25. public function testGetSymlink()
  26. {
  27. $bucket = getenv('OSS_BUCKET');
  28. $symlink = 'test-link';
  29. $object = 'exist_object^$#!~';
  30. $result = $this->ossClient->getSymlink($bucket, $symlink);
  31. $this->assertEquals($result[OssClient::OSS_SYMLINK_TARGET], $object);
  32. $this->assertEquals('200', $result[OssClient::OSS_INFO][OssClient::OSS_HTTP_CODE]);
  33. $this->assertTrue(isset($result[OssClient::OSS_ETAG]));
  34. $this->assertTrue(isset($result[OssClient::OSS_REQUEST_ID]));
  35. }
  36. public function testPutNullSymlink()
  37. {
  38. $bucket = getenv('OSS_BUCKET');
  39. $symlink = 'null-link';
  40. $object_not_exist = 'not_exist_object+$#!b不';
  41. $this->ossClient->putSymlink($bucket, $symlink, $object_not_exist);
  42. try{
  43. $this->ossClient->getObject($bucket, $symlink);
  44. $this->assertTrue(false);
  45. }catch (OssException $e){
  46. $this->assertEquals('The symlink target object does not exist', $e->getErrorMessage());
  47. }
  48. }
  49. public function testGetNullSymlink()
  50. {
  51. $bucket = getenv('OSS_BUCKET');
  52. $symlink = 'null-link-new';
  53. try{
  54. $result = $this->ossClient->getSymlink($bucket, $symlink);
  55. $this->assertTrue(false);
  56. }catch (OssException $e){
  57. $this->assertEquals('The specified key does not exist.', $e->getErrorMessage());
  58. }
  59. }
  60. }