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.8 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. cfg := api.ConfigJSON{
  10. EndPoint: "https://localhost:7890",
  11. RootCA: ``,
  12. ClientCert: ``,
  13. ClientKey: ``,
  14. }
  15. c, err := cfg.Build()
  16. if err != nil {
  17. panic(err)
  18. }
  19. cli := NewClient(c)
  20. Convey("下载文件", t, func() {
  21. pre := cli.Presigned()
  22. url, err := pre.ObjectDownloadByPath(PresignedObjectDownloadByPath{
  23. PackageID: 3,
  24. Path: "example.java",
  25. Offset: 1,
  26. Length: types.Ref(int64(100)),
  27. }, 100)
  28. So(err, ShouldEqual, nil)
  29. t.Logf("url: %s", url)
  30. })
  31. Convey("上传文件", t, func() {
  32. pre := cli.Presigned()
  33. url, err := pre.ObjectUpload(PresignedObjectUpload{
  34. PackageID: 3,
  35. Path: "example.java",
  36. }, 100)
  37. So(err, ShouldEqual, nil)
  38. t.Logf("url: %s", url)
  39. })
  40. }
  41. func Test_PresignedObjectListByPath(t *testing.T) {
  42. cli := NewClient(api.Config{
  43. EndPoint: "http://localhost:7890",
  44. })
  45. Convey("下载文件", t, func() {
  46. pre := cli.Presigned()
  47. url, err := pre.ObjectListByPath(PresignedObjectListByPath{
  48. ObjectListByPath: ObjectListByPath{
  49. PackageID: 12,
  50. Path: "a/",
  51. IsPrefix: true,
  52. NoRecursive: true,
  53. MaxKeys: 10,
  54. ContinuationToken: "123456",
  55. },
  56. }, 100)
  57. So(err, ShouldEqual, nil)
  58. t.Logf("url: %s", url)
  59. })
  60. }
  61. func Test_PresignedObjectDownloadByPath(t *testing.T) {
  62. cli := NewClient(api.Config{
  63. EndPoint: "http://localhost:7890",
  64. })
  65. Convey("下载文件", t, func() {
  66. pre := cli.Presigned()
  67. url, err := pre.ObjectDownloadByPath(PresignedObjectDownloadByPath{
  68. PackageID: 3,
  69. Path: "example.java",
  70. // Offset: 1,
  71. // Length: types.Ref(int64(100)),
  72. }, 100)
  73. So(err, ShouldEqual, nil)
  74. t.Logf("url: %s", url)
  75. })
  76. }
  77. func Test_PresignedObjectDownload(t *testing.T) {
  78. cli := NewClient(api.Config{
  79. EndPoint: "http://localhost:7890",
  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. EndPoint: "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. EndPoint: "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. EndPoint: "http://localhost:7890",
  123. })
  124. Convey("上传分片", t, func() {
  125. pre := cli.Presigned()
  126. url, err := pre.ObjectUploadPart(PresignedObjectUploadPart{
  127. ObjectID: 7,
  128. Index: 3,
  129. }, 600)
  130. So(err, ShouldEqual, nil)
  131. t.Logf("url: %s", url)
  132. })
  133. }
  134. func Test_PresignedCompleteMultipartUpload(t *testing.T) {
  135. cli := NewClient(api.Config{
  136. EndPoint: "http://localhost:7890",
  137. })
  138. Convey("合并分片", t, func() {
  139. pre := cli.Presigned()
  140. url, err := pre.ObjectCompleteMultipartUpload(PresignedObjectCompleteMultipartUpload{
  141. ObjectID: 7,
  142. Indexes: []int{1, 2, 3},
  143. }, 600)
  144. So(err, ShouldEqual, nil)
  145. t.Logf("url: %s", url)
  146. })
  147. }

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