dao_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package ugc
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "path/filepath"
  7. "testing"
  8. "go-common/app/job/main/tv/conf"
  9. "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. queryMid = "SELECT mid FROM ugc_archive WHERE result=1 AND valid=1 AND deleted=0 LIMIT 1"
  16. queryAid = "SELECT aid FROM ugc_archive WHERE result=1 AND valid=1 AND deleted=0 LIMIT 1"
  17. )
  18. func WithDao(f func(d *Dao)) func() {
  19. return func() {
  20. dir, _ := filepath.Abs("../../cmd/tv-job-test.toml")
  21. flag.Set("conf", dir)
  22. conf.Init()
  23. if d == nil {
  24. d = New(conf.Conf)
  25. }
  26. f(d)
  27. }
  28. }
  29. func TestDao_UpArcs(t *testing.T) {
  30. Convey("TestDao_UpArcs", t, WithDao(func(d *Dao) {
  31. var mid int64
  32. d.DB.QueryRow(ctx, queryMid).Scan(&mid)
  33. if mid == 0 {
  34. return
  35. }
  36. res, err := d.UpArcs(ctx, mid)
  37. So(err, ShouldBeNil)
  38. So(len(res), ShouldBeGreaterThan, 0)
  39. }))
  40. }
  41. func TestDao_SetArcCMS(t *testing.T) {
  42. Convey("TestDao_SetArcCMS", t, WithDao(func(d *Dao) {
  43. var aid int64
  44. d.DB.QueryRow(ctx, queryAid).Scan(&aid)
  45. if aid != 0 {
  46. err := d.SetArcCMS(ctx, &ugc.ArcCMS{
  47. AID: aid,
  48. Title: "test",
  49. })
  50. So(err, ShouldBeNil)
  51. fmt.Println(aid)
  52. }
  53. }))
  54. }
  55. func TestDao_CountArcs(t *testing.T) {
  56. Convey("TestDao_CountArcs", t, WithDao(func(d *Dao) {
  57. res, err := d.CountUpArcs(ctx, 452156)
  58. So(err, ShouldBeNil)
  59. So(res, ShouldBeGreaterThan, 0)
  60. fmt.Println(res)
  61. }))
  62. }