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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. })
  11. Convey("下载文件", t, func() {
  12. pre := cli.Presigned("123456", "123456")
  13. url, err := pre.ObjectDownload(PresignedObjectDownloadByPath{
  14. UserID: 1,
  15. PackageID: 3,
  16. Path: "example.java",
  17. Offset: 1,
  18. Length: types.Ref(int64(100)),
  19. }, 100)
  20. So(err, ShouldEqual, nil)
  21. t.Logf("url: %s", url)
  22. })
  23. Convey("上传文件", t, func() {
  24. pre := cli.Presigned("123456", "123456")
  25. url, err := pre.ObjectUpload(PresignedObjectUpload{
  26. UserID: 1,
  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_PresignedObjectDownload(t *testing.T) {
  35. cli := NewClient(&Config{
  36. URL: "http://localhost:7890",
  37. })
  38. Convey("下载文件", t, func() {
  39. pre := cli.Presigned("123456", "123456")
  40. url, err := pre.ObjectDownload(PresignedObjectDownloadByPath{
  41. UserID: 1,
  42. PackageID: 3,
  43. Path: "example.java",
  44. // Offset: 1,
  45. // Length: types.Ref(int64(100)),
  46. }, 100)
  47. So(err, ShouldEqual, nil)
  48. t.Logf("url: %s", url)
  49. })
  50. }
  51. func Test_PresignedObjectUpload(t *testing.T) {
  52. cli := NewClient(&Config{
  53. URL: "http://localhost:7890",
  54. })
  55. Convey("上传文件", t, func() {
  56. pre := cli.Presigned("123456", "123456")
  57. url, err := pre.ObjectUpload(PresignedObjectUpload{
  58. UserID: 1,
  59. PackageID: 3,
  60. Path: "example.java",
  61. }, 100)
  62. So(err, ShouldEqual, nil)
  63. t.Logf("url: %s", url)
  64. })
  65. }
  66. func Test_PresignedNewMultipartUpload(t *testing.T) {
  67. cli := NewClient(&Config{
  68. URL: "http://localhost:7890",
  69. })
  70. Convey("启动分片上传", t, func() {
  71. pre := cli.Presigned("123456", "123456")
  72. url, err := pre.ObjectNewMultipartUpload(PresignedObjectNewMultipartUpload{
  73. UserID: 1,
  74. PackageID: 3,
  75. Path: "example.java",
  76. }, 600)
  77. So(err, ShouldEqual, nil)
  78. t.Logf("url: %s", url)
  79. })
  80. }
  81. func Test_PresignedObjectUploadPart(t *testing.T) {
  82. cli := NewClient(&Config{
  83. URL: "http://localhost:7890",
  84. })
  85. Convey("上传分片", t, func() {
  86. pre := cli.Presigned("123456", "123456")
  87. url, err := pre.ObjectUploadPart(PresignedObjectUploadPart{
  88. UserID: 1,
  89. ObjectID: 7,
  90. Index: 3,
  91. }, 600)
  92. So(err, ShouldEqual, nil)
  93. t.Logf("url: %s", url)
  94. })
  95. }
  96. func Test_PresignedCompleteMultipartUpload(t *testing.T) {
  97. cli := NewClient(&Config{
  98. URL: "http://localhost:7890",
  99. })
  100. Convey("合并分片", t, func() {
  101. pre := cli.Presigned("123456", "123456")
  102. url, err := pre.ObjectCompleteMultipartUpload(PresignedObjectCompleteMultipartUpload{
  103. UserID: 1,
  104. ObjectID: 7,
  105. Indexes: []int{1, 2, 3},
  106. }, 600)
  107. So(err, ShouldEqual, nil)
  108. t.Logf("url: %s", url)
  109. })
  110. }