bfs_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/main/upload/model"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoNewBfs(t *testing.T) {
  11. convey.Convey("NewBfs", t, func(ctx convey.C) {
  12. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  13. ctx.Convey("d.Bfs should not be nil", func(ctx convey.C) {
  14. ctx.So(d.Bfs, convey.ShouldNotBeNil)
  15. })
  16. })
  17. })
  18. }
  19. //func TestDaowaterMark(t *testing.T) {
  20. // convey.Convey("waterMark", t, func(ctx convey.C) {
  21. // bts, err := ioutil.ReadFile("/Users/sunsuke/Desktop/hahaha.png")
  22. // fmt.Println(err)
  23. // //for _, byt := range bts {
  24. // //fmt.Print(byt, ",")
  25. // //}
  26. //
  27. // var (
  28. // c = context.Background()
  29. // // png file
  30. // data = bts
  31. // contentType = http.DetectContentType(data)
  32. // wmKey = ""
  33. // wmText = "test"
  34. // paddingX = int(0)
  35. // paddingY = int(0)
  36. // wmScale = float64(0)
  37. // )
  38. // fmt.Println(contentType)
  39. // ctx.Convey("When everything goes positive", func(ctx convey.C) {
  40. // res, err := d.Bfs.waterMark(c, data, contentType, wmKey, wmText, paddingX, paddingY, wmScale)
  41. // ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  42. // ctx.So(err, convey.ShouldBeNil)
  43. // ctx.So(res, convey.ShouldNotBeNil)
  44. // })
  45. // })
  46. // })
  47. //}
  48. func TestDaoUpload(t *testing.T) {
  49. convey.Convey("Upload", t, func(ctx convey.C) {
  50. var (
  51. c = context.Background()
  52. data = []byte("ut test")
  53. up = &model.UploadParam{
  54. Bucket: "test",
  55. Auth: d.Bfs.Authorize("221bce6492eba70f", "6eb80603e85842542f9736eb13b7e3", http.MethodPut, "test", "", time.Now().Unix()),
  56. ContentType: http.DetectContentType(data),
  57. }
  58. )
  59. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  60. location, etag, err := d.Bfs.Upload(c, up, data)
  61. ctx.Convey("Then err should be nil.location,etag should not be nil.", func(ctx convey.C) {
  62. ctx.So(err, convey.ShouldBeNil)
  63. ctx.So(etag, convey.ShouldNotBeNil)
  64. ctx.So(location, convey.ShouldNotBeNil)
  65. })
  66. })
  67. })
  68. }
  69. func TestDaoSpecificUpload(t *testing.T) {
  70. convey.Convey("SpecificUpload", t, func(ctx convey.C) {
  71. var (
  72. c = context.Background()
  73. data = []byte("ut specific upload")
  74. contentType = http.DetectContentType(data)
  75. auth = d.Bfs.Authorize("221bce6492eba70f", "6eb80603e85842542f9736eb13b7e3", http.MethodPut, "test", "", time.Now().Unix())
  76. bucket = "test"
  77. fileName = ""
  78. )
  79. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  80. location, etag, err := d.Bfs.SpecificUpload(c, contentType, auth, bucket, fileName, data)
  81. ctx.Convey("Then err should be nil.location,etag should not be nil.", func(ctx convey.C) {
  82. ctx.So(err, convey.ShouldBeNil)
  83. ctx.So(etag, convey.ShouldNotBeNil)
  84. ctx.So(location, convey.ShouldNotBeNil)
  85. })
  86. })
  87. })
  88. }
  89. func TestDaoAuthorize(t *testing.T) {
  90. convey.Convey("Authorize", t, func(ctx convey.C) {
  91. var (
  92. key = "221bce6492eba70f"
  93. secret = "6eb80603e85842542f9736eb13b7e3"
  94. method = http.MethodPut
  95. bucket = "test"
  96. fileName = ""
  97. expire = time.Now().Unix()
  98. )
  99. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  100. authorization := d.Bfs.Authorize(key, secret, method, bucket, fileName, expire)
  101. ctx.Convey("Then authorization should not be nil.", func(ctx convey.C) {
  102. ctx.So(authorization, convey.ShouldNotBeNil)
  103. })
  104. })
  105. })
  106. }
  107. func TestDaoClose(t *testing.T) {
  108. convey.Convey("close", t, func(ctx convey.C) {
  109. d.Close()
  110. })
  111. }
  112. func TestDaoPing(t *testing.T) {
  113. convey.Convey("ping", t, func(ctx convey.C) {
  114. d.Ping(context.Background())
  115. })
  116. }