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

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