bfs_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/interface/main/upload/conf"
  7. xtime "go-common/library/time"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestNewBfs(t *testing.T) {
  11. Convey("new bfs instance", t, func() {
  12. b := NewBfs(&conf.Config{
  13. Bfs: &conf.Bfs{
  14. BfsURL: "uat-bfs.bilibili.co",
  15. WaterMarkURL: "http://i0.hdslb.com/imageserver/watermark/gen",
  16. TimeOut: xtime.Duration(time.Second * 5),
  17. WmTimeOut: xtime.Duration(time.Second * 5),
  18. },
  19. })
  20. So(b, ShouldNotBeNil)
  21. })
  22. }
  23. func TestGenImage(t *testing.T) {
  24. Convey("create watermark image", t, func() {
  25. image, height, width, hasher, err := b.GenImage(context.TODO(), "comic", "hello world", 2, true)
  26. So(err, ShouldBeNil)
  27. So(image, ShouldNotBeEmpty)
  28. So(height, ShouldNotEqual, 0)
  29. So(width, ShouldNotEqual, 0)
  30. So(hasher, ShouldNotEqual, "")
  31. })
  32. }
  33. func TestWatermark(t *testing.T) {
  34. Convey("do watermark action", t, func() {
  35. image, err := b.Watermark(context.TODO(), testData, "image/png", "comic", "hello", 0, 0, 0)
  36. So(err, ShouldBeNil)
  37. So(image, ShouldNotBeEmpty)
  38. })
  39. }
  40. func TestUpload(t *testing.T) {
  41. Convey("upload", t, func() {
  42. var (
  43. dir = "dir1/"
  44. filename = "1111.jpg"
  45. )
  46. location, _, err := b.Upload(context.Background(), "1b24a3d8560d2213", "415aaa6ff53659dabf8a2de394025a", "image/jpg", "static", dir, filename, testData)
  47. So(err, ShouldBeNil)
  48. So(location, ShouldNotBeEmpty)
  49. })
  50. Convey("upload", t, func() {
  51. var (
  52. dir = "dir1/"
  53. filename = ""
  54. )
  55. location, _, err := b.Upload(context.Background(), "1b24a3d8560d2213", "415aaa6ff53659dabf8a2de394025a", "image/jpg", "static", dir, filename, testData)
  56. So(err, ShouldBeNil)
  57. So(location, ShouldNotBeEmpty)
  58. })
  59. Convey("upload", t, func() {
  60. var (
  61. dir = ""
  62. filename = "1111.jpg"
  63. )
  64. location, _, err := b.Upload(context.Background(), "1b24a3d8560d2213", "415aaa6ff53659dabf8a2de394025a", "image/jpg", "static", dir, filename, testData)
  65. So(err, ShouldBeNil)
  66. So(location, ShouldNotBeEmpty)
  67. })
  68. Convey("upload", t, func() {
  69. var (
  70. dir = ""
  71. filename = ""
  72. )
  73. location, _, err := b.Upload(context.Background(), "1b24a3d8560d2213", "415aaa6ff53659dabf8a2de394025a", "image/jpg", "static", dir, filename, testData)
  74. So(err, ShouldBeNil)
  75. So(location, ShouldNotBeEmpty)
  76. })
  77. }