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.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_PresignedObjectDownloadByPath(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.ObjectDownloadByPath(PresignedObjectDownloadByPath{
  45. UserID: 1,
  46. PackageID: 3,
  47. Path: "example.java",
  48. // Offset: 1,
  49. // Length: types.Ref(int64(100)),
  50. }, 100)
  51. So(err, ShouldEqual, nil)
  52. t.Logf("url: %s", url)
  53. })
  54. }
  55. func Test_PresignedObjectDownload(t *testing.T) {
  56. cli := NewClient(&Config{
  57. URL: "http://localhost:7890",
  58. AccessKey: "123456",
  59. SecretKey: "123456",
  60. })
  61. Convey("下载文件", t, func() {
  62. pre := cli.Presigned()
  63. url, err := pre.ObjectDownload(PresignedObjectDownload{
  64. UserID: 1,
  65. ObjectID: 1039,
  66. // Offset: 1,
  67. // Length: types.Ref(int64(100)),
  68. }, 100)
  69. So(err, ShouldEqual, nil)
  70. t.Logf("url: %s", url)
  71. })
  72. }
  73. func Test_PresignedObjectUpload(t *testing.T) {
  74. cli := NewClient(&Config{
  75. URL: "http://localhost:7890",
  76. })
  77. Convey("上传文件", t, func() {
  78. pre := cli.Presigned()
  79. url, err := pre.ObjectUpload(PresignedObjectUpload{
  80. UserID: 1,
  81. PackageID: 3,
  82. Path: "example.java",
  83. }, 100)
  84. So(err, ShouldEqual, nil)
  85. t.Logf("url: %s", url)
  86. })
  87. }
  88. func Test_PresignedNewMultipartUpload(t *testing.T) {
  89. cli := NewClient(&Config{
  90. URL: "http://localhost:7890",
  91. })
  92. Convey("启动分片上传", t, func() {
  93. pre := cli.Presigned()
  94. url, err := pre.ObjectNewMultipartUpload(PresignedObjectNewMultipartUpload{
  95. UserID: 1,
  96. PackageID: 3,
  97. Path: "example.java",
  98. }, 600)
  99. So(err, ShouldEqual, nil)
  100. t.Logf("url: %s", url)
  101. })
  102. }
  103. func Test_PresignedObjectUploadPart(t *testing.T) {
  104. cli := NewClient(&Config{
  105. URL: "http://localhost:7890",
  106. AccessKey: "123456",
  107. SecretKey: "123456",
  108. })
  109. Convey("上传分片", t, func() {
  110. pre := cli.Presigned()
  111. url, err := pre.ObjectUploadPart(PresignedObjectUploadPart{
  112. UserID: 1,
  113. ObjectID: 7,
  114. Index: 3,
  115. }, 600)
  116. So(err, ShouldEqual, nil)
  117. t.Logf("url: %s", url)
  118. })
  119. }
  120. func Test_PresignedCompleteMultipartUpload(t *testing.T) {
  121. cli := NewClient(&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.ObjectCompleteMultipartUpload(PresignedObjectCompleteMultipartUpload{
  129. UserID: 1,
  130. ObjectID: 7,
  131. Indexes: []int{1, 2, 3},
  132. }, 600)
  133. So(err, ShouldEqual, nil)
  134. t.Logf("url: %s", url)
  135. })
  136. }