You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1071 lines
35 KiB

4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
6 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
  1. package cos
  2. // Basic imports
  3. import (
  4. "context"
  5. "fmt"
  6. "io/ioutil"
  7. "math/rand"
  8. "net/http"
  9. "net/url"
  10. "os"
  11. "strings"
  12. "testing"
  13. "time"
  14. //"github.com/google/uuid"
  15. "github.com/stretchr/testify/assert"
  16. "github.com/stretchr/testify/suite"
  17. "github.com/tencentyun/cos-go-sdk-v5"
  18. )
  19. // Define the suite, and absorb the built-in basic suite
  20. // functionality from testify - including a T() method which
  21. // returns the current testing context
  22. type CosTestSuite struct {
  23. suite.Suite
  24. VariableThatShouldStartAtFive int
  25. // CI client
  26. Client *cos.Client
  27. // Copy source client
  28. CClient *cos.Client
  29. Region string
  30. Bucket string
  31. Appid string
  32. // test_object
  33. TestObject string
  34. // special_file_name
  35. SepFileName string
  36. }
  37. // 请替换成您的账号及存储桶信息
  38. const (
  39. //uin
  40. kUin = "100010805041"
  41. kAppid = 1259654469
  42. // 常规测试需要的存储桶
  43. kBucket = "cosgosdktest-1259654469"
  44. kRegion = "ap-guangzhou"
  45. // 跨区域复制需要的目标存储桶,地域不能与kBucket存储桶相同, 目的存储桶需要开启多版本
  46. kRepBucket = "cosgosdkreptest"
  47. kRepRegion = "ap-chengdu"
  48. // Batch测试需要的源存储桶和目标存储桶,目前只在成都、重庆地域公测
  49. kBatchBucket = "cosgosdktest-1259654469"
  50. kTargetBatchBucket = "cosgosdktest-1259654469" //复用了存储桶
  51. kBatchRegion = "ap-guangzhou"
  52. )
  53. func (s *CosTestSuite) SetupSuite() {
  54. fmt.Println("Set up test")
  55. // init
  56. s.TestObject = "test.txt"
  57. s.SepFileName = "中文" + "→↓←→↖↗↙↘! \"#$%&'()*+,-./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
  58. // CI client for test interface
  59. // URL like this http://test-1253846586.cos.ap-guangzhou.myqcloud.com
  60. u := "https://" + kBucket + ".cos." + kRegion + ".myqcloud.com"
  61. u2 := "https://" + kUin + ".cos-control." + kBatchRegion + ".myqcloud.com"
  62. // Get the region
  63. bucketurl, _ := url.Parse(u)
  64. batchurl, _ := url.Parse(u2)
  65. p := strings.Split(bucketurl.Host, ".")
  66. assert.Equal(s.T(), 5, len(p), "Bucket host is not right")
  67. s.Region = p[2]
  68. // Bucket name
  69. pi := strings.LastIndex(p[0], "-")
  70. s.Bucket = p[0][:pi]
  71. s.Appid = p[0][pi+1:]
  72. ib := &cos.BaseURL{BucketURL: bucketurl, BatchURL: batchurl}
  73. s.Client = cos.NewClient(ib, &http.Client{
  74. Transport: &cos.AuthorizationTransport{
  75. SecretID: os.Getenv("COS_SECRETID"),
  76. SecretKey: os.Getenv("COS_SECRETKEY"),
  77. },
  78. })
  79. opt := &cos.BucketPutOptions{
  80. XCosACL: "public-read",
  81. }
  82. r, err := s.Client.Bucket.Put(context.Background(), opt)
  83. if err != nil && r != nil && r.StatusCode == 409 {
  84. fmt.Println("BucketAlreadyOwnedByYou")
  85. } else if err != nil {
  86. assert.Nil(s.T(), err, "PutBucket Failed")
  87. }
  88. }
  89. // Begin of api test
  90. // Service API
  91. func (s *CosTestSuite) TestGetService() {
  92. _, _, err := s.Client.Service.Get(context.Background())
  93. assert.Nil(s.T(), err, "GetService Failed")
  94. }
  95. func (s *CosTestSuite) TestGetRegionService() {
  96. u, _ := url.Parse("http://cos.ap-guangzhou.myqcloud.com")
  97. b := &cos.BaseURL{ServiceURL: u}
  98. client := cos.NewClient(b, &http.Client{
  99. Transport: &cos.AuthorizationTransport{
  100. SecretID: os.Getenv("COS_SECRETID"),
  101. SecretKey: os.Getenv("COS_SECRETKEY"),
  102. },
  103. })
  104. _, _, err := client.Service.Get(context.Background())
  105. assert.Nil(s.T(), err, "GetService Failed")
  106. }
  107. // Bucket API
  108. func (s *CosTestSuite) TestPutHeadDeleteBucket() {
  109. // Notic sometimes the bucket host can not analyis, may has i/o timeout problem
  110. u := "http://" + "testgosdkbucket-create-head-del-" + s.Appid + ".cos." + kRegion + ".myqcloud.com"
  111. iu, _ := url.Parse(u)
  112. ib := &cos.BaseURL{BucketURL: iu}
  113. client := cos.NewClient(ib, &http.Client{
  114. Transport: &cos.AuthorizationTransport{
  115. SecretID: os.Getenv("COS_SECRETID"),
  116. SecretKey: os.Getenv("COS_SECRETKEY"),
  117. },
  118. })
  119. r, err := client.Bucket.Put(context.Background(), nil)
  120. if err != nil && r != nil && r.StatusCode == 409 {
  121. fmt.Println("BucketAlreadyOwnedByYou")
  122. } else if err != nil {
  123. assert.Nil(s.T(), err, "PutBucket Failed")
  124. }
  125. if err != nil {
  126. panic(err)
  127. }
  128. time.Sleep(3 * time.Second)
  129. _, err = client.Bucket.Head(context.Background())
  130. assert.Nil(s.T(), err, "HeadBucket Failed")
  131. if err == nil {
  132. _, err = client.Bucket.Delete(context.Background())
  133. assert.Nil(s.T(), err, "DeleteBucket Failed")
  134. }
  135. }
  136. func (s *CosTestSuite) TestPutBucketACLIllegal() {
  137. opt := &cos.BucketPutACLOptions{
  138. Header: &cos.ACLHeaderOptions{
  139. XCosACL: "public-read-writ",
  140. },
  141. }
  142. _, err := s.Client.Bucket.PutACL(context.Background(), opt)
  143. assert.NotNil(s.T(), err, "PutBucketACL illegal Failed")
  144. }
  145. func (s *CosTestSuite) TestPutGetBucketACLNormal() {
  146. // with header
  147. opt := &cos.BucketPutACLOptions{
  148. Header: &cos.ACLHeaderOptions{
  149. XCosACL: "private",
  150. },
  151. }
  152. _, err := s.Client.Bucket.PutACL(context.Background(), opt)
  153. assert.Nil(s.T(), err, "PutBucketACL normal Failed")
  154. v, _, err := s.Client.Bucket.GetACL(context.Background())
  155. assert.Nil(s.T(), err, "GetBucketACL normal Failed")
  156. assert.Equal(s.T(), 1, len(v.AccessControlList), "GetBucketACL normal Failed, must be private")
  157. }
  158. func (s *CosTestSuite) TestGetBucket() {
  159. opt := &cos.BucketGetOptions{
  160. Prefix: "中文",
  161. MaxKeys: 3,
  162. }
  163. _, _, err := s.Client.Bucket.Get(context.Background(), opt)
  164. assert.Nil(s.T(), err, "GetBucket Failed")
  165. }
  166. func (s *CosTestSuite) TestGetObjectVersions() {
  167. opt := &cos.BucketGetObjectVersionsOptions{
  168. Prefix: "中文",
  169. MaxKeys: 3,
  170. }
  171. _, _, err := s.Client.Bucket.GetObjectVersions(context.Background(), opt)
  172. assert.Nil(s.T(), err, "GetObjectVersions Failed")
  173. }
  174. func (s *CosTestSuite) TestGetBucketLocation() {
  175. v, _, err := s.Client.Bucket.GetLocation(context.Background())
  176. assert.Nil(s.T(), err, "GetLocation Failed")
  177. assert.Equal(s.T(), s.Region, v.Location, "GetLocation wrong region")
  178. }
  179. func (s *CosTestSuite) TestPutGetDeleteCORS() {
  180. opt := &cos.BucketPutCORSOptions{
  181. Rules: []cos.BucketCORSRule{
  182. {
  183. AllowedOrigins: []string{"http://www.qq.com"},
  184. AllowedMethods: []string{"PUT", "GET"},
  185. AllowedHeaders: []string{"x-cos-meta-test", "x-cos-xx"},
  186. MaxAgeSeconds: 500,
  187. ExposeHeaders: []string{"x-cos-meta-test1"},
  188. },
  189. },
  190. }
  191. _, err := s.Client.Bucket.PutCORS(context.Background(), opt)
  192. assert.Nil(s.T(), err, "PutBucketCORS Failed")
  193. v, _, err := s.Client.Bucket.GetCORS(context.Background())
  194. assert.Nil(s.T(), err, "GetBucketCORS Failed")
  195. assert.Equal(s.T(), 1, len(v.Rules), "GetBucketCORS wrong number rules")
  196. }
  197. func (s *CosTestSuite) TestVersionAndReplication() {
  198. opt := &cos.BucketPutVersionOptions{
  199. // Enabled or Suspended, the versioning once opened can not close.
  200. Status: "Enabled",
  201. }
  202. _, err := s.Client.Bucket.PutVersioning(context.Background(), opt)
  203. assert.Nil(s.T(), err, "PutVersioning Failed")
  204. time.Sleep(time.Second)
  205. v, _, err := s.Client.Bucket.GetVersioning(context.Background())
  206. assert.Nil(s.T(), err, "GetVersioning Failed")
  207. assert.Equal(s.T(), "Enabled", v.Status, "Get Wrong Version status")
  208. repOpt := &cos.PutBucketReplicationOptions{
  209. // qcs::cam::uin/[UIN]:uin/[Subaccount]
  210. Role: "qcs::cam::uin/" + kUin + ":uin/" + kUin,
  211. Rule: []cos.BucketReplicationRule{
  212. {
  213. ID: "1",
  214. // Enabled or Disabled
  215. Status: "Enabled",
  216. Destination: &cos.ReplicationDestination{
  217. // qcs::cos:[Region]::[Bucketname-Appid]
  218. Bucket: "qcs::cos:" + kRepRegion + "::" + kRepBucket + "-" + s.Appid,
  219. },
  220. },
  221. },
  222. }
  223. _, err = s.Client.Bucket.PutBucketReplication(context.Background(), repOpt)
  224. assert.Nil(s.T(), err, "PutBucketReplication Failed")
  225. time.Sleep(time.Second)
  226. vr, _, err := s.Client.Bucket.GetBucketReplication(context.Background())
  227. assert.Nil(s.T(), err, "GetBucketReplication Failed")
  228. for _, r := range vr.Rule {
  229. assert.Equal(s.T(), "Enabled", r.Status, "Get Wrong Version status")
  230. assert.Equal(s.T(), "qcs::cos:"+kRepRegion+"::"+kRepBucket+"-"+s.Appid, r.Destination.Bucket, "Get Wrong Version status")
  231. }
  232. _, err = s.Client.Bucket.DeleteBucketReplication(context.Background())
  233. assert.Nil(s.T(), err, "DeleteBucketReplication Failed")
  234. }
  235. func (s *CosTestSuite) TestBucketInventory() {
  236. id := "test1"
  237. dBucket := "qcs::cos:" + s.Region + "::" + s.Bucket + "-" + s.Appid
  238. opt := &cos.BucketPutInventoryOptions{
  239. ID: id,
  240. // True or False
  241. IsEnabled: "True",
  242. IncludedObjectVersions: "All",
  243. Filter: &cos.BucketInventoryFilter{
  244. Prefix: "test",
  245. },
  246. OptionalFields: &cos.BucketInventoryOptionalFields{
  247. BucketInventoryFields: []string{
  248. "Size", "LastModifiedDate",
  249. },
  250. },
  251. Schedule: &cos.BucketInventorySchedule{
  252. // Weekly or Daily
  253. Frequency: "Daily",
  254. },
  255. Destination: &cos.BucketInventoryDestination{
  256. Bucket: dBucket,
  257. Format: "CSV",
  258. },
  259. }
  260. _, err := s.Client.Bucket.PutInventory(context.Background(), id, opt)
  261. assert.Nil(s.T(), err, "PutBucketInventory Failed")
  262. v, _, err := s.Client.Bucket.GetInventory(context.Background(), id)
  263. assert.Nil(s.T(), err, "GetBucketInventory Failed")
  264. assert.Equal(s.T(), "test1", v.ID, "Get Wrong inventory id")
  265. assert.Equal(s.T(), "true", v.IsEnabled, "Get Wrong inventory isenabled")
  266. assert.Equal(s.T(), dBucket, v.Destination.Bucket, "Get Wrong inventory isenabled")
  267. _, err = s.Client.Bucket.DeleteInventory(context.Background(), id)
  268. assert.Nil(s.T(), err, "DeleteBucketInventory Failed")
  269. }
  270. func (s *CosTestSuite) TestBucketLogging() {
  271. tBucket := s.Bucket + "-" + s.Appid
  272. opt := &cos.BucketPutLoggingOptions{
  273. LoggingEnabled: &cos.BucketLoggingEnabled{
  274. TargetBucket: tBucket,
  275. },
  276. }
  277. _, err := s.Client.Bucket.PutLogging(context.Background(), opt)
  278. assert.Nil(s.T(), err, "PutLogging Failed")
  279. v, _, err := s.Client.Bucket.GetLogging(context.Background())
  280. assert.Nil(s.T(), err, "GetLogging Failed")
  281. assert.Equal(s.T(), tBucket, v.LoggingEnabled.TargetBucket, "Get Wrong Version status")
  282. }
  283. func (s *CosTestSuite) TestBucketTagging() {
  284. opt := &cos.BucketPutTaggingOptions{
  285. TagSet: []cos.BucketTaggingTag{
  286. {
  287. Key: "testk1",
  288. Value: "testv1",
  289. },
  290. {
  291. Key: "testk2",
  292. Value: "testv2",
  293. },
  294. },
  295. }
  296. _, err := s.Client.Bucket.PutTagging(context.Background(), opt)
  297. assert.Nil(s.T(), err, "Put Tagging Failed")
  298. v, _, err := s.Client.Bucket.GetTagging(context.Background())
  299. assert.Nil(s.T(), err, "Get Tagging Failed")
  300. assert.Equal(s.T(), v.TagSet[0].Key, opt.TagSet[0].Key, "Get Wrong Tag key")
  301. assert.Equal(s.T(), v.TagSet[0].Value, opt.TagSet[0].Value, "Get Wrong Tag value")
  302. assert.Equal(s.T(), v.TagSet[1].Key, opt.TagSet[1].Key, "Get Wrong Tag key")
  303. assert.Equal(s.T(), v.TagSet[1].Value, opt.TagSet[1].Value, "Get Wrong Tag value")
  304. }
  305. func (s *CosTestSuite) TestPutGetDeleteLifeCycle() {
  306. lc := &cos.BucketPutLifecycleOptions{
  307. Rules: []cos.BucketLifecycleRule{
  308. {
  309. ID: "1234",
  310. Filter: &cos.BucketLifecycleFilter{Prefix: "test"},
  311. Status: "Enabled",
  312. Transition: []cos.BucketLifecycleTransition{
  313. {
  314. Days: 10,
  315. StorageClass: "Standard",
  316. },
  317. },
  318. },
  319. },
  320. }
  321. _, err := s.Client.Bucket.PutLifecycle(context.Background(), lc)
  322. assert.Nil(s.T(), err, "PutBucketLifecycle Failed")
  323. _, r, err := s.Client.Bucket.GetLifecycle(context.Background())
  324. // Might cleaned by other case concrrent
  325. if err != nil && 404 != r.StatusCode {
  326. assert.Nil(s.T(), err, "GetBucketLifecycle Failed")
  327. }
  328. _, err = s.Client.Bucket.DeleteLifecycle(context.Background())
  329. assert.Nil(s.T(), err, "DeleteBucketLifecycle Failed")
  330. }
  331. func (s *CosTestSuite) TestPutGetDeleteWebsite() {
  332. opt := &cos.BucketPutWebsiteOptions{
  333. Index: "index.html",
  334. Error: &cos.ErrorDocument{"index_backup.html"},
  335. RoutingRules: &cos.WebsiteRoutingRules{
  336. []cos.WebsiteRoutingRule{
  337. {
  338. ConditionErrorCode: "404",
  339. RedirectProtocol: "https",
  340. RedirectReplaceKey: "404.html",
  341. },
  342. {
  343. ConditionPrefix: "docs/",
  344. RedirectProtocol: "https",
  345. RedirectReplaceKeyPrefix: "documents/",
  346. },
  347. },
  348. },
  349. }
  350. _, err := s.Client.Bucket.PutWebsite(context.Background(), opt)
  351. assert.Nil(s.T(), err, "PutBucketWebsite Failed")
  352. res, rsp, err := s.Client.Bucket.GetWebsite(context.Background())
  353. if err != nil && 404 != rsp.StatusCode {
  354. assert.Nil(s.T(), err, "GetBucketWebsite Failed")
  355. }
  356. assert.Equal(s.T(), opt.Index, res.Index, "GetBucketWebsite Failed")
  357. assert.Equal(s.T(), opt.Error, res.Error, "GetBucketWebsite Failed")
  358. assert.Equal(s.T(), opt.RedirectProtocol, res.RedirectProtocol, "GetBucketWebsite Failed")
  359. _, err = s.Client.Bucket.DeleteWebsite(context.Background())
  360. assert.Nil(s.T(), err, "DeleteBucketWebsite Failed")
  361. }
  362. func (s *CosTestSuite) TestListMultipartUploads() {
  363. // Create new upload
  364. name := "test_multipart" + time.Now().Format(time.RFC3339)
  365. flag := false
  366. v, _, err := s.Client.Object.InitiateMultipartUpload(context.Background(), name, nil)
  367. assert.Nil(s.T(), err, "InitiateMultipartUpload Failed")
  368. id := v.UploadID
  369. // List
  370. r, _, err := s.Client.Bucket.ListMultipartUploads(context.Background(), nil)
  371. assert.Nil(s.T(), err, "ListMultipartUploads Failed")
  372. for _, p := range r.Uploads {
  373. if p.Key == name {
  374. assert.Equal(s.T(), id, p.UploadID, "ListMultipartUploads wrong uploadid")
  375. flag = true
  376. }
  377. }
  378. assert.Equal(s.T(), true, flag, "ListMultipartUploads wrong key")
  379. // Abort
  380. _, err = s.Client.Object.AbortMultipartUpload(context.Background(), name, id)
  381. assert.Nil(s.T(), err, "AbortMultipartUpload Failed")
  382. }
  383. // Object API
  384. func (s *CosTestSuite) TestPutHeadGetDeleteObject_10MB() {
  385. name := "test/objectPut" + time.Now().Format(time.RFC3339)
  386. b := make([]byte, 1024*1024*10)
  387. _, err := rand.Read(b)
  388. content := fmt.Sprintf("%X", b)
  389. f := strings.NewReader(content)
  390. _, err = s.Client.Object.Put(context.Background(), name, f, nil)
  391. assert.Nil(s.T(), err, "PutObject Failed")
  392. _, err = s.Client.Object.Head(context.Background(), name, nil)
  393. assert.Nil(s.T(), err, "HeadObject Failed")
  394. _, err = s.Client.Object.Delete(context.Background(), name)
  395. assert.Nil(s.T(), err, "DeleteObject Failed")
  396. }
  397. func (s *CosTestSuite) TestPutGetDeleteObjectByFile_10MB() {
  398. // Create tmp file
  399. filePath := "tmpfile" + time.Now().Format(time.RFC3339)
  400. newfile, err := os.Create(filePath)
  401. assert.Nil(s.T(), err, "create tmp file Failed")
  402. defer newfile.Close()
  403. name := "test/objectPutByFile" + time.Now().Format(time.RFC3339)
  404. b := make([]byte, 1024*1024*10)
  405. _, err = rand.Read(b)
  406. newfile.Write(b)
  407. _, err = s.Client.Object.PutFromFile(context.Background(), name, filePath, nil)
  408. assert.Nil(s.T(), err, "PutObject Failed")
  409. // Over write tmp file
  410. _, err = s.Client.Object.GetToFile(context.Background(), name, filePath, nil)
  411. assert.Nil(s.T(), err, "HeadObject Failed")
  412. _, err = s.Client.Object.Delete(context.Background(), name)
  413. assert.Nil(s.T(), err, "DeleteObject Failed")
  414. // remove the local tmp file
  415. err = os.Remove(filePath)
  416. assert.Nil(s.T(), err, "remove local file Failed")
  417. }
  418. func (s *CosTestSuite) TestPutGetDeleteObjectByUpload_10MB() {
  419. // Create tmp file
  420. filePath := "tmpfile" + time.Now().Format(time.RFC3339)
  421. newfile, err := os.Create(filePath)
  422. assert.Nil(s.T(), err, "create tmp file Failed")
  423. defer newfile.Close()
  424. name := "test/objectUpload" + time.Now().Format(time.RFC3339)
  425. b := make([]byte, 1024*1024*10)
  426. _, err = rand.Read(b)
  427. newfile.Write(b)
  428. opt := &cos.MultiUploadOptions{
  429. PartSize: 1,
  430. ThreadPoolSize: 3,
  431. }
  432. _, _, err = s.Client.Object.Upload(context.Background(), name, filePath, opt)
  433. assert.Nil(s.T(), err, "PutObject Failed")
  434. // Over write tmp file
  435. _, err = s.Client.Object.GetToFile(context.Background(), name, filePath, nil)
  436. assert.Nil(s.T(), err, "HeadObject Failed")
  437. _, err = s.Client.Object.Delete(context.Background(), name)
  438. assert.Nil(s.T(), err, "DeleteObject Failed")
  439. // remove the local tmp file
  440. err = os.Remove(filePath)
  441. assert.Nil(s.T(), err, "remove local file Failed")
  442. }
  443. func (s *CosTestSuite) TestPutGetDeleteObjectByUploadAndDownload_10MB() {
  444. // Create tmp file
  445. filePath := "tmpfile" + time.Now().Format(time.RFC3339)
  446. newfile, err := os.Create(filePath)
  447. assert.Nil(s.T(), err, "create tmp file Failed")
  448. defer newfile.Close()
  449. name := "test/objectUpload" + time.Now().Format(time.RFC3339)
  450. b := make([]byte, 1024*1024*10)
  451. _, err = rand.Read(b)
  452. newfile.Write(b)
  453. opt := &cos.MultiUploadOptions{
  454. PartSize: 1,
  455. ThreadPoolSize: 3,
  456. }
  457. _, _, err = s.Client.Object.Upload(context.Background(), name, filePath, opt)
  458. assert.Nil(s.T(), err, "PutObject Failed")
  459. // Over write tmp file
  460. _, err = s.Client.Object.Download(context.Background(), name, filePath, nil)
  461. assert.Nil(s.T(), err, "DownloadObject Failed")
  462. _, err = s.Client.Object.Delete(context.Background(), name)
  463. assert.Nil(s.T(), err, "DeleteObject Failed")
  464. // remove the local tmp file
  465. err = os.Remove(filePath)
  466. assert.Nil(s.T(), err, "remove local file Failed")
  467. }
  468. func (s *CosTestSuite) TestPutGetDeleteObjectSpecialName() {
  469. f := strings.NewReader("test")
  470. name := s.SepFileName + time.Now().Format(time.RFC3339)
  471. _, err := s.Client.Object.Put(context.Background(), name, f, nil)
  472. assert.Nil(s.T(), err, "PutObject Failed")
  473. resp, err := s.Client.Object.Get(context.Background(), name, nil)
  474. assert.Nil(s.T(), err, "GetObject Failed")
  475. defer resp.Body.Close()
  476. bs, _ := ioutil.ReadAll(resp.Body)
  477. assert.Equal(s.T(), "test", string(bs), "GetObject failed content wrong")
  478. _, err = s.Client.Object.Delete(context.Background(), name)
  479. assert.Nil(s.T(), err, "DeleteObject Failed")
  480. }
  481. func (s *CosTestSuite) TestPutObjectToNonExistBucket() {
  482. u := "http://gosdknonexistbucket-" + s.Appid + ".cos." + s.Region + ".myqcloud.com"
  483. iu, _ := url.Parse(u)
  484. ib := &cos.BaseURL{BucketURL: iu}
  485. client := cos.NewClient(ib, &http.Client{
  486. Transport: &cos.AuthorizationTransport{
  487. SecretID: os.Getenv("COS_SECRETID"),
  488. SecretKey: os.Getenv("COS_SECRETKEY"),
  489. },
  490. })
  491. name := "test/objectPut.go"
  492. f := strings.NewReader("test")
  493. r, err := client.Object.Put(context.Background(), name, f, nil)
  494. assert.NotNil(s.T(), err, "PutObject ToNonExistBucket Failed")
  495. assert.Equal(s.T(), 404, r.StatusCode, "PutObject ToNonExistBucket, not 404")
  496. }
  497. func (s *CosTestSuite) TestPutGetObjectACL() {
  498. name := "test/objectACL.go" + time.Now().Format(time.RFC3339)
  499. f := strings.NewReader("test")
  500. _, err := s.Client.Object.Put(context.Background(), name, f, nil)
  501. assert.Nil(s.T(), err, "PutObject Failed")
  502. // Put acl
  503. opt := &cos.ObjectPutACLOptions{
  504. Header: &cos.ACLHeaderOptions{
  505. XCosACL: "public-read",
  506. },
  507. }
  508. _, err = s.Client.Object.PutACL(context.Background(), name, opt)
  509. assert.Nil(s.T(), err, "PutObjectACL Failed")
  510. v, _, err := s.Client.Object.GetACL(context.Background(), name)
  511. assert.Nil(s.T(), err, "GetObjectACL Failed")
  512. assert.Equal(s.T(), 2, len(v.AccessControlList), "GetLifecycle wrong number rules")
  513. _, err = s.Client.Object.Delete(context.Background(), name)
  514. assert.Nil(s.T(), err, "DeleteObject Failed")
  515. }
  516. func (s *CosTestSuite) TestPutObjectRestore() {
  517. name := "archivetest"
  518. putOpt := &cos.ObjectPutOptions{
  519. ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
  520. XCosStorageClass: "ARCHIVE",
  521. },
  522. }
  523. f := strings.NewReader("test")
  524. _, err := s.Client.Object.Put(context.Background(), name, f, putOpt)
  525. assert.Nil(s.T(), err, "PutObject Archive faild")
  526. opt := &cos.ObjectRestoreOptions{
  527. Days: 2,
  528. Tier: &cos.CASJobParameters{
  529. // Standard, Exepdited and Bulk
  530. Tier: "Expedited",
  531. },
  532. }
  533. resp, _ := s.Client.Object.PostRestore(context.Background(), name, opt)
  534. retCode := resp.StatusCode
  535. if retCode != 200 && retCode != 202 && retCode != 409 {
  536. right := false
  537. fmt.Println("PutObjectRestore get code is:", retCode)
  538. assert.Equal(s.T(), true, right, "PutObjectRestore Failed")
  539. }
  540. }
  541. func (s *CosTestSuite) TestCopyObject() {
  542. u := "http://" + kRepBucket + "-" + s.Appid + ".cos." + kRepRegion + ".myqcloud.com"
  543. iu, _ := url.Parse(u)
  544. ib := &cos.BaseURL{BucketURL: iu}
  545. c := cos.NewClient(ib, &http.Client{
  546. Transport: &cos.AuthorizationTransport{
  547. SecretID: os.Getenv("COS_SECRETID"),
  548. SecretKey: os.Getenv("COS_SECRETKEY"),
  549. },
  550. })
  551. opt := &cos.BucketPutOptions{
  552. XCosACL: "public-read",
  553. }
  554. // Notice in intranet the bucket host sometimes has i/o timeout problem
  555. r, err := c.Bucket.Put(context.Background(), opt)
  556. if err != nil && r != nil && r.StatusCode == 409 {
  557. fmt.Println("BucketAlreadyOwnedByYou")
  558. } else if err != nil {
  559. assert.Nil(s.T(), err, "PutBucket Failed")
  560. }
  561. source := "test/objectMove1" + time.Now().Format(time.RFC3339)
  562. expected := "test"
  563. f := strings.NewReader(expected)
  564. r, err = c.Object.Put(context.Background(), source, f, nil)
  565. assert.Nil(s.T(), err, "PutObject Failed")
  566. var version_id string
  567. if r.Header["X-Cos-Version-Id"] != nil {
  568. version_id = r.Header.Get("X-Cos-Version-Id")
  569. }
  570. time.Sleep(3 * time.Second)
  571. // Copy file
  572. soruceURL := fmt.Sprintf("%s/%s", iu.Host, source)
  573. dest := "test/objectMove1" + time.Now().Format(time.RFC3339)
  574. //opt := &cos.ObjectCopyOptions{}
  575. if version_id == "" {
  576. _, _, err = s.Client.Object.Copy(context.Background(), dest, soruceURL, nil)
  577. } else {
  578. _, _, err = s.Client.Object.Copy(context.Background(), dest, soruceURL, nil, version_id)
  579. }
  580. assert.Nil(s.T(), err, "PutObjectCopy Failed")
  581. // Check content
  582. resp, err := s.Client.Object.Get(context.Background(), dest, nil)
  583. assert.Nil(s.T(), err, "GetObject Failed")
  584. bs, _ := ioutil.ReadAll(resp.Body)
  585. resp.Body.Close()
  586. result := string(bs)
  587. assert.Equal(s.T(), expected, result, "PutObjectCopy Failed, wrong content")
  588. }
  589. func (s *CosTestSuite) TestCreateAbortMultipartUpload() {
  590. name := "test_multipart" + time.Now().Format(time.RFC3339)
  591. v, _, err := s.Client.Object.InitiateMultipartUpload(context.Background(), name, nil)
  592. assert.Nil(s.T(), err, "InitiateMultipartUpload Failed")
  593. _, err = s.Client.Object.AbortMultipartUpload(context.Background(), name, v.UploadID)
  594. assert.Nil(s.T(), err, "AbortMultipartUpload Failed")
  595. }
  596. func (s *CosTestSuite) TestCreateCompleteMultipartUpload() {
  597. name := "test/test_complete_upload" + time.Now().Format(time.RFC3339)
  598. v, _, err := s.Client.Object.InitiateMultipartUpload(context.Background(), name, nil)
  599. uploadID := v.UploadID
  600. blockSize := 1024 * 1024 * 3
  601. opt := &cos.CompleteMultipartUploadOptions{}
  602. for i := 1; i < 3; i++ {
  603. b := make([]byte, blockSize)
  604. _, err := rand.Read(b)
  605. content := fmt.Sprintf("%X", b)
  606. f := strings.NewReader(content)
  607. resp, err := s.Client.Object.UploadPart(
  608. context.Background(), name, uploadID, i, f, nil,
  609. )
  610. assert.Nil(s.T(), err, "UploadPart Failed")
  611. etag := resp.Header.Get("Etag")
  612. opt.Parts = append(opt.Parts, cos.Object{
  613. PartNumber: i, ETag: etag},
  614. )
  615. }
  616. _, _, err = s.Client.Object.CompleteMultipartUpload(
  617. context.Background(), name, uploadID, opt,
  618. )
  619. assert.Nil(s.T(), err, "CompleteMultipartUpload Failed")
  620. }
  621. func (s *CosTestSuite) TestSSE_C() {
  622. name := "test/TestSSE_C"
  623. content := "test sse-c " + time.Now().Format(time.RFC3339)
  624. f := strings.NewReader(content)
  625. putOpt := &cos.ObjectPutOptions{
  626. ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
  627. ContentType: "text/html",
  628. //XCosServerSideEncryption: "AES256",
  629. XCosSSECustomerAglo: "AES256",
  630. XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=",
  631. XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==",
  632. },
  633. ACLHeaderOptions: &cos.ACLHeaderOptions{
  634. XCosACL: "public-read",
  635. //XCosACL: "private",
  636. },
  637. }
  638. _, err := s.Client.Object.Put(context.Background(), name, f, putOpt)
  639. assert.Nil(s.T(), err, "PutObject with SSE failed")
  640. headOpt := &cos.ObjectHeadOptions{
  641. XCosSSECustomerAglo: "AES256",
  642. XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=",
  643. XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==",
  644. }
  645. _, err = s.Client.Object.Head(context.Background(), name, headOpt)
  646. assert.Nil(s.T(), err, "HeadObject with SSE failed")
  647. getOpt := &cos.ObjectGetOptions{
  648. XCosSSECustomerAglo: "AES256",
  649. XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=",
  650. XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==",
  651. }
  652. var resp *cos.Response
  653. resp, err = s.Client.Object.Get(context.Background(), name, getOpt)
  654. assert.Nil(s.T(), err, "GetObject with SSE failed")
  655. bodyBytes, _ := ioutil.ReadAll(resp.Body)
  656. bodyContent := string(bodyBytes)
  657. assert.Equal(s.T(), content, bodyContent, "GetObject with SSE failed, want: %+v, res: %+v", content, bodyContent)
  658. copyOpt := &cos.ObjectCopyOptions{
  659. &cos.ObjectCopyHeaderOptions{
  660. XCosCopySourceSSECustomerAglo: "AES256",
  661. XCosCopySourceSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=",
  662. XCosCopySourceSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==",
  663. },
  664. &cos.ACLHeaderOptions{},
  665. }
  666. copySource := s.Bucket + "-" + s.Appid + ".cos." + s.Region + ".myqcloud.com/" + name
  667. _, _, err = s.Client.Object.Copy(context.Background(), "test/TestSSE_C_Copy", copySource, copyOpt)
  668. assert.Nil(s.T(), err, "CopyObject with SSE failed")
  669. partIni := &cos.MultiUploadOptions{
  670. OptIni: &cos.InitiateMultipartUploadOptions{
  671. &cos.ACLHeaderOptions{},
  672. &cos.ObjectPutHeaderOptions{
  673. XCosSSECustomerAglo: "AES256",
  674. XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=",
  675. XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==",
  676. },
  677. },
  678. PartSize: 1,
  679. }
  680. filePath := "tmpfile" + time.Now().Format(time.RFC3339)
  681. newFile, err := os.Create(filePath)
  682. assert.Nil(s.T(), err, "create tmp file Failed")
  683. defer newFile.Close()
  684. b := make([]byte, 1024*10)
  685. _, err = rand.Read(b)
  686. newFile.Write(b)
  687. _, _, err = s.Client.Object.MultiUpload(context.Background(), "test/TestSSE_C_MultiUpload", filePath, partIni)
  688. assert.Nil(s.T(), err, "MultiUpload with SSE failed")
  689. err = os.Remove(filePath)
  690. assert.Nil(s.T(), err, "remove local file Failed")
  691. }
  692. func (s *CosTestSuite) TestMultiUpload() {
  693. filePath := "tmpfile" + time.Now().Format(time.RFC3339)
  694. newFile, err := os.Create(filePath)
  695. assert.Nil(s.T(), err, "create tmp file Failed")
  696. defer newFile.Close()
  697. b := make([]byte, 1024*1024*10)
  698. _, err = rand.Read(b)
  699. newFile.Write(b)
  700. partIni := &cos.MultiUploadOptions{}
  701. _, _, err = s.Client.Object.MultiUpload(context.Background(), "test/Test_MultiUpload", filePath, partIni)
  702. err = os.Remove(filePath)
  703. assert.Nil(s.T(), err, "remove tmp file failed")
  704. }
  705. /*
  706. func (s *CosTestSuite) TestBatch() {
  707. client := cos.NewClient(s.Client.BaseURL, &http.Client{
  708. Transport: &cos.AuthorizationTransport{
  709. SecretID: os.Getenv("COS_SECRETID"),
  710. SecretKey: os.Getenv("COS_SECRETKEY"),
  711. },
  712. })
  713. source_name := "test/1.txt"
  714. sf := strings.NewReader("batch test content")
  715. _, err := client.Object.Put(context.Background(), source_name, sf, nil)
  716. assert.Nil(s.T(), err, "object put Failed")
  717. manifest_name := "test/manifest.csv"
  718. f := strings.NewReader(kBatchBucket + "," + source_name)
  719. resp, err := client.Object.Put(context.Background(), manifest_name, f, nil)
  720. assert.Nil(s.T(), err, "object put Failed")
  721. etag := resp.Header.Get("ETag")
  722. uuid_str := uuid.New().String()
  723. opt := &cos.BatchCreateJobOptions{
  724. ClientRequestToken: uuid_str,
  725. ConfirmationRequired: "true",
  726. Description: "test batch",
  727. Manifest: &cos.BatchJobManifest{
  728. Location: &cos.BatchJobManifestLocation{
  729. ETag: etag,
  730. ObjectArn: "qcs::cos:" + kBatchRegion + ":uid/" + s.Appid + ":" + kBatchBucket + "/" + manifest_name,
  731. },
  732. Spec: &cos.BatchJobManifestSpec{
  733. Fields: []string{"Bucket", "Key"},
  734. Format: "COSBatchOperations_CSV_V1",
  735. },
  736. },
  737. Operation: &cos.BatchJobOperation{
  738. PutObjectCopy: &cos.BatchJobOperationCopy{
  739. TargetResource: "qcs::cos:" + kBatchRegion + ":uid/" + s.Appid + ":" + kTargetBatchBucket,
  740. },
  741. },
  742. Priority: 1,
  743. Report: &cos.BatchJobReport{
  744. Bucket: "qcs::cos:" + kBatchRegion + ":uid/" + s.Appid + ":" + kBatchBucket,
  745. Enabled: "true",
  746. Format: "Report_CSV_V1",
  747. Prefix: "job-result",
  748. ReportScope: "AllTasks",
  749. },
  750. RoleArn: "qcs::cam::uin/" + kUin + ":roleName/COSBatch_QcsRole",
  751. }
  752. headers := &cos.BatchRequestHeaders{
  753. XCosAppid: kAppid,
  754. }
  755. res1, _, err := client.Batch.CreateJob(context.Background(), opt, headers)
  756. assert.Nil(s.T(), err, "create job Failed")
  757. jobid := res1.JobId
  758. res2, _, err := client.Batch.DescribeJob(context.Background(), jobid, headers)
  759. assert.Nil(s.T(), err, "describe job Failed")
  760. assert.Equal(s.T(), res2.Job.ConfirmationRequired, "true", "ConfirmationRequired not right")
  761. assert.Equal(s.T(), res2.Job.Description, "test batch", "Description not right")
  762. assert.Equal(s.T(), res2.Job.JobId, jobid, "jobid not right")
  763. assert.Equal(s.T(), res2.Job.Priority, 1, "priority not right")
  764. assert.Equal(s.T(), res2.Job.RoleArn, "qcs::cam::uin/"+kUin+":roleName/COSBatch_QcsRole", "priority not right")
  765. _, _, err = client.Batch.ListJobs(context.Background(), nil, headers)
  766. assert.Nil(s.T(), err, "list jobs failed")
  767. up_opt := &cos.BatchUpdatePriorityOptions{
  768. JobId: jobid,
  769. Priority: 3,
  770. }
  771. res3, _, err := client.Batch.UpdateJobPriority(context.Background(), up_opt, headers)
  772. assert.Nil(s.T(), err, "list jobs failed")
  773. assert.Equal(s.T(), res3.JobId, jobid, "jobid failed")
  774. assert.Equal(s.T(), res3.Priority, 3, "priority not right")
  775. // 等待状态变成Suspended
  776. for i := 0; i < 50; i = i + 1 {
  777. res, _, err := client.Batch.DescribeJob(context.Background(), jobid, headers)
  778. assert.Nil(s.T(), err, "describe job Failed")
  779. assert.Equal(s.T(), res2.Job.ConfirmationRequired, "true", "ConfirmationRequired not right")
  780. assert.Equal(s.T(), res2.Job.Description, "test batch", "Description not right")
  781. assert.Equal(s.T(), res2.Job.JobId, jobid, "jobid not right")
  782. assert.Equal(s.T(), res2.Job.Priority, 1, "priority not right")
  783. assert.Equal(s.T(), res2.Job.RoleArn, "qcs::cam::uin/"+kUin+":roleName/COSBatch_QcsRole", "priority not right")
  784. if res.Job.Status == "Suspended" {
  785. break
  786. }
  787. if i == 9 {
  788. assert.Error(s.T(), errors.New("Job status is not Suspended or timeout"))
  789. }
  790. time.Sleep(time.Second * 2)
  791. }
  792. us_opt := &cos.BatchUpdateStatusOptions{
  793. JobId: jobid,
  794. RequestedJobStatus: "Ready", // 允许状态转换见 https://cloud.tencent.com/document/product/436/38604
  795. StatusUpdateReason: "to test",
  796. }
  797. res4, _, err := client.Batch.UpdateJobStatus(context.Background(), us_opt, headers)
  798. assert.Nil(s.T(), err, "list jobs failed")
  799. assert.Equal(s.T(), res4.JobId, jobid, "jobid failed")
  800. assert.Equal(s.T(), res4.Status, "Ready", "status failed")
  801. assert.Equal(s.T(), res4.StatusUpdateReason, "to test", "StatusUpdateReason failed")
  802. }
  803. */
  804. func (s *CosTestSuite) TestEncryption() {
  805. opt := &cos.BucketPutEncryptionOptions{
  806. Rule: &cos.BucketEncryptionConfiguration{
  807. SSEAlgorithm: "AES256",
  808. },
  809. }
  810. _, err := s.Client.Bucket.PutEncryption(context.Background(), opt)
  811. assert.Nil(s.T(), err, "PutEncryption Failed")
  812. time.Sleep(time.Second * 2)
  813. res, _, err := s.Client.Bucket.GetEncryption(context.Background())
  814. assert.Nil(s.T(), err, "GetEncryption Failed")
  815. assert.Equal(s.T(), opt.Rule.SSEAlgorithm, res.Rule.SSEAlgorithm, "GetEncryption Failed")
  816. _, err = s.Client.Bucket.DeleteEncryption(context.Background())
  817. assert.Nil(s.T(), err, "DeleteEncryption Failed")
  818. }
  819. func (s *CosTestSuite) TestReferer() {
  820. opt := &cos.BucketPutRefererOptions{
  821. Status: "Enabled",
  822. RefererType: "White-List",
  823. DomainList: []string{
  824. "*.qq.com",
  825. "*.qcloud.com",
  826. },
  827. EmptyReferConfiguration: "Allow",
  828. }
  829. _, err := s.Client.Bucket.PutReferer(context.Background(), opt)
  830. assert.Nil(s.T(), err, "PutReferer Failed")
  831. res, _, err := s.Client.Bucket.GetReferer(context.Background())
  832. assert.Nil(s.T(), err, "GetReferer Failed")
  833. assert.Equal(s.T(), opt.Status, res.Status, "GetReferer Failed")
  834. assert.Equal(s.T(), opt.RefererType, res.RefererType, "GetReferer Failed")
  835. assert.Equal(s.T(), opt.DomainList, res.DomainList, "GetReferer Failed")
  836. assert.Equal(s.T(), opt.EmptyReferConfiguration, res.EmptyReferConfiguration, "GetReferer Failed")
  837. }
  838. func (s *CosTestSuite) TestAccelerate() {
  839. opt := &cos.BucketPutAccelerateOptions{
  840. Status: "Enabled",
  841. Type: "COS",
  842. }
  843. _, err := s.Client.Bucket.PutAccelerate(context.Background(), opt)
  844. assert.Nil(s.T(), err, "PutAccelerate Failed")
  845. time.Sleep(time.Second)
  846. res, _, err := s.Client.Bucket.GetAccelerate(context.Background())
  847. assert.Nil(s.T(), err, "GetAccelerate Failed")
  848. assert.Equal(s.T(), opt.Status, res.Status, "GetAccelerate Failed")
  849. assert.Equal(s.T(), opt.Type, res.Type, "GetAccelerate Failed")
  850. opt.Status = "Suspended"
  851. _, err = s.Client.Bucket.PutAccelerate(context.Background(), opt)
  852. assert.Nil(s.T(), err, "PutAccelerate Failed")
  853. time.Sleep(time.Second)
  854. res, _, err = s.Client.Bucket.GetAccelerate(context.Background())
  855. assert.Nil(s.T(), err, "GetAccelerate Failed")
  856. assert.Equal(s.T(), opt.Status, res.Status, "GetAccelerate Failed")
  857. assert.Equal(s.T(), opt.Type, res.Type, "GetAccelerate Failed")
  858. }
  859. func (s *CosTestSuite) TestMultiCopy() {
  860. u := "http://" + kRepBucket + "-" + s.Appid + ".cos." + kRepRegion + ".myqcloud.com"
  861. iu, _ := url.Parse(u)
  862. ib := &cos.BaseURL{BucketURL: iu}
  863. c := cos.NewClient(ib, &http.Client{
  864. Transport: &cos.AuthorizationTransport{
  865. SecretID: os.Getenv("COS_SECRETID"),
  866. SecretKey: os.Getenv("COS_SECRETKEY"),
  867. },
  868. })
  869. opt := &cos.BucketPutOptions{
  870. XCosACL: "public-read",
  871. }
  872. // Notice in intranet the bucket host sometimes has i/o timeout problem
  873. r, err := c.Bucket.Put(context.Background(), opt)
  874. if err != nil && r != nil && r.StatusCode == 409 {
  875. fmt.Println("BucketAlreadyOwnedByYou")
  876. } else if err != nil {
  877. assert.Nil(s.T(), err, "PutBucket Failed")
  878. }
  879. source := "test/objectMove1" + time.Now().Format(time.RFC3339)
  880. expected := "test"
  881. f := strings.NewReader(expected)
  882. r, err = c.Object.Put(context.Background(), source, f, nil)
  883. assert.Nil(s.T(), err, "PutObject Failed")
  884. time.Sleep(3 * time.Second)
  885. // Copy file
  886. soruceURL := fmt.Sprintf("%s/%s", iu.Host, source)
  887. dest := "test/objectMove1" + time.Now().Format(time.RFC3339)
  888. _, _, err = s.Client.Object.MultiCopy(context.Background(), dest, soruceURL, nil)
  889. assert.Nil(s.T(), err, "MultiCopy Failed")
  890. // Check content
  891. resp, err := s.Client.Object.Get(context.Background(), dest, nil)
  892. assert.Nil(s.T(), err, "GetObject Failed")
  893. bs, _ := ioutil.ReadAll(resp.Body)
  894. resp.Body.Close()
  895. result := string(bs)
  896. assert.Equal(s.T(), expected, result, "MultiCopy Failed, wrong content")
  897. }
  898. // End of api test
  899. // All methods that begin with "Test" are run as tests within a
  900. // suite.
  901. // In order for 'go test' to run this suite, we need to create
  902. // a normal test function and pass our suite to suite.Run
  903. func TestCosTestSuite(t *testing.T) {
  904. suite.Run(t, new(CosTestSuite))
  905. }
  906. func (s *CosTestSuite) TearDownSuite() {
  907. // Clean the file in bucket
  908. // r, _, err := s.Client.Bucket.ListMultipartUploads(context.Background(), nil)
  909. // assert.Nil(s.T(), err, "ListMultipartUploads Failed")
  910. // for _, p := range r.Uploads {
  911. // // Abort
  912. // _, err = s.Client.Object.AbortMultipartUpload(context.Background(), p.Key, p.UploadID)
  913. // assert.Nil(s.T(), err, "AbortMultipartUpload Failed")
  914. // }
  915. // // Delete objects
  916. // opt := &cos.BucketGetOptions{
  917. // MaxKeys: 500,
  918. // }
  919. // v, _, err := s.Client.Bucket.Get(context.Background(), opt)
  920. // assert.Nil(s.T(), err, "GetBucket Failed")
  921. // for _, c := range v.Contents {
  922. // _, err := s.Client.Object.Delete(context.Background(), c.Key)
  923. // assert.Nil(s.T(), err, "DeleteObject Failed")
  924. // }
  925. // When clean up these infos, can not solve the concurrent test problem
  926. fmt.Println("tear down~")
  927. }