dao_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package upper
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "path/filepath"
  7. "testing"
  8. "go-common/app/job/main/tv/conf"
  9. ugcMdl "go-common/app/job/main/tv/model/ugc"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. ctx = context.TODO()
  14. d *Dao
  15. )
  16. func WithDao(f func(d *Dao)) func() {
  17. return func() {
  18. dir, _ := filepath.Abs("../../cmd/tv-job-test.toml")
  19. flag.Set("conf", dir)
  20. conf.Init()
  21. if d == nil {
  22. d = New(conf.Conf)
  23. }
  24. f(d)
  25. }
  26. }
  27. func TestDao_LoadUpMeta(t *testing.T) {
  28. Convey("TestDao_LoadUpMeta", t, WithDao(func(d *Dao) {
  29. res, err := d.LoadUpMeta(ctx, 88895270)
  30. So(err, ShouldBeNil)
  31. fmt.Println(res)
  32. }))
  33. }
  34. func TestDao_CountUP(t *testing.T) {
  35. Convey("TestDao_CountUP", t, WithDao(func(d *Dao) {
  36. res, err := d.CountUP(ctx)
  37. So(err, ShouldBeNil)
  38. fmt.Println(res)
  39. }))
  40. }
  41. func TestDao_PickUppers(t *testing.T) {
  42. Convey("TestDao_PickUppers", t, WithDao(func(d *Dao) {
  43. res, myLast, err := d.PickUppers(ctx, 0, 50)
  44. So(err, ShouldBeNil)
  45. So(myLast, ShouldBeGreaterThan, 0)
  46. So(len(res), ShouldBeGreaterThan, 0)
  47. fmt.Println(myLast)
  48. }))
  49. }
  50. func TestDao_RefreshUp(t *testing.T) {
  51. Convey("TestDao_RefreshUp", t, WithDao(func(d *Dao) {
  52. res, _, _ := d.PickUppers(ctx, 0, 50)
  53. if len(res) > 0 {
  54. err := d.RefreshUp(ctx, &ugcMdl.ReqSetUp{
  55. MID: res[0],
  56. Value: "Face666",
  57. UpType: _upFace,
  58. })
  59. So(err, ShouldBeNil)
  60. }
  61. }))
  62. }
  63. func TestDao_TosyncUps(t *testing.T) {
  64. Convey("TestDao_TosyncUps", t, WithDao(func(d *Dao) {
  65. mids, err := d.TosyncUps(ctx)
  66. So(err, ShouldBeNil)
  67. fmt.Println(mids)
  68. }))
  69. }
  70. func TestDao_FinsyncUps(t *testing.T) {
  71. Convey("TestDao_FinsyncUps", t, WithDao(func(d *Dao) {
  72. err := d.FinsyncUps(ctx, 88895270)
  73. So(err, ShouldBeNil)
  74. }))
  75. }
  76. func TestDao_IsSame(t *testing.T) {
  77. Convey("TestDao_IsSame", t, WithDao(func(d *Dao) {
  78. var u = &ugcMdl.Upper{
  79. OriFace: "http://i0.hdslb.com/bfs/face/589568b0b0228d5a38b2e6f14b83bcb174637140.jpg",
  80. }
  81. var faceSame, _ = u.IsSame("", "http://i1.hdslb.com/bfs/face/589568b0b0228d5a38b2e6f14b83bcb174637140.jpg")
  82. So(faceSame, ShouldBeTrue)
  83. faceSame, _ = u.IsSame("", "http://i0.hdslb.com/bfs/face/xxx.jpg")
  84. So(faceSame, ShouldBeFalse)
  85. }))
  86. }