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 4.0 kB

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