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

presigned_test.go 3.9 kB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package api
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. "gitlink.org.cn/cloudream/common/pkgs/types"
  6. "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
  7. )
  8. func Test_Presigned(t *testing.T) {
  9. cli := NewClient(&api.Config{
  10. URL: "http://localhost:7890",
  11. AccessKey: "123456",
  12. SecretKey: "123456",
  13. })
  14. Convey("下载文件", t, func() {
  15. pre := cli.Presigned()
  16. url, err := pre.ObjectDownloadByPath(PresignedObjectDownloadByPath{
  17. PackageID: 3,
  18. Path: "example.java",
  19. Offset: 1,
  20. Length: types.Ref(int64(100)),
  21. }, 100)
  22. So(err, ShouldEqual, nil)
  23. t.Logf("url: %s", url)
  24. })
  25. Convey("上传文件", t, func() {
  26. pre := cli.Presigned()
  27. url, err := pre.ObjectUpload(PresignedObjectUpload{
  28. PackageID: 3,
  29. Path: "example.java",
  30. }, 100)
  31. So(err, ShouldEqual, nil)
  32. t.Logf("url: %s", url)
  33. })
  34. }
  35. func Test_PresignedObjectListByPath(t *testing.T) {
  36. cli := NewClient(&api.Config{
  37. URL: "http://localhost:7890",
  38. AccessKey: "123456",
  39. SecretKey: "123456",
  40. })
  41. Convey("下载文件", t, func() {
  42. pre := cli.Presigned()
  43. url, err := pre.ObjectListByPath(PresignedObjectListByPath{
  44. ObjectListByPath: ObjectListByPath{
  45. PackageID: 12,
  46. Path: "a/",
  47. IsPrefix: true,
  48. NoRecursive: true,
  49. MaxKeys: 10,
  50. ContinuationToken: "123456",
  51. },
  52. }, 100)
  53. So(err, ShouldEqual, nil)
  54. t.Logf("url: %s", url)
  55. })
  56. }
  57. func Test_PresignedObjectDownloadByPath(t *testing.T) {
  58. cli := NewClient(&api.Config{
  59. URL: "http://localhost:7890",
  60. AccessKey: "123456",
  61. SecretKey: "123456",
  62. })
  63. Convey("下载文件", t, func() {
  64. pre := cli.Presigned()
  65. url, err := pre.ObjectDownloadByPath(PresignedObjectDownloadByPath{
  66. PackageID: 3,
  67. Path: "example.java",
  68. // Offset: 1,
  69. // Length: types.Ref(int64(100)),
  70. }, 100)
  71. So(err, ShouldEqual, nil)
  72. t.Logf("url: %s", url)
  73. })
  74. }
  75. func Test_PresignedObjectDownload(t *testing.T) {
  76. cli := NewClient(&api.Config{
  77. URL: "http://localhost:7890",
  78. AccessKey: "123456",
  79. SecretKey: "123456",
  80. })
  81. Convey("下载文件", t, func() {
  82. pre := cli.Presigned()
  83. url, err := pre.ObjectDownload(PresignedObjectDownload{
  84. ObjectID: 1039,
  85. // Offset: 1,
  86. // Length: types.Ref(int64(100)),
  87. }, 100)
  88. So(err, ShouldEqual, nil)
  89. t.Logf("url: %s", url)
  90. })
  91. }
  92. func Test_PresignedObjectUpload(t *testing.T) {
  93. cli := NewClient(&api.Config{
  94. URL: "http://localhost:7890",
  95. })
  96. Convey("上传文件", t, func() {
  97. pre := cli.Presigned()
  98. url, err := pre.ObjectUpload(PresignedObjectUpload{
  99. PackageID: 3,
  100. Path: "example.java",
  101. }, 100)
  102. So(err, ShouldEqual, nil)
  103. t.Logf("url: %s", url)
  104. })
  105. }
  106. func Test_PresignedNewMultipartUpload(t *testing.T) {
  107. cli := NewClient(&api.Config{
  108. URL: "http://localhost:7890",
  109. })
  110. Convey("启动分片上传", t, func() {
  111. pre := cli.Presigned()
  112. url, err := pre.ObjectNewMultipartUpload(PresignedObjectNewMultipartUpload{
  113. PackageID: 3,
  114. Path: "example.java",
  115. }, 600)
  116. So(err, ShouldEqual, nil)
  117. t.Logf("url: %s", url)
  118. })
  119. }
  120. func Test_PresignedObjectUploadPart(t *testing.T) {
  121. cli := NewClient(&api.Config{
  122. URL: "http://localhost:7890",
  123. AccessKey: "123456",
  124. SecretKey: "123456",
  125. })
  126. Convey("上传分片", t, func() {
  127. pre := cli.Presigned()
  128. url, err := pre.ObjectUploadPart(PresignedObjectUploadPart{
  129. ObjectID: 7,
  130. Index: 3,
  131. }, 600)
  132. So(err, ShouldEqual, nil)
  133. t.Logf("url: %s", url)
  134. })
  135. }
  136. func Test_PresignedCompleteMultipartUpload(t *testing.T) {
  137. cli := NewClient(&api.Config{
  138. URL: "http://localhost:7890",
  139. AccessKey: "123456",
  140. SecretKey: "123456",
  141. })
  142. Convey("合并分片", t, func() {
  143. pre := cli.Presigned()
  144. url, err := pre.ObjectCompleteMultipartUpload(PresignedObjectCompleteMultipartUpload{
  145. ObjectID: 7,
  146. Indexes: []int{1, 2, 3},
  147. }, 600)
  148. So(err, ShouldEqual, nil)
  149. t.Logf("url: %s", url)
  150. })
  151. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。