upper_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "testing"
  7. "go-common/app/admin/main/tv/model"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func getMids(limit int) (res []int64, err error) {
  11. var (
  12. db = d.DB.Where("deleted = 0")
  13. ups []*model.Upper
  14. )
  15. if err = db.Limit(limit).Find(&ups).Error; err != nil {
  16. fmt.Println("pickMid err ", err)
  17. }
  18. for _, v := range ups {
  19. res = append(res, v.MID)
  20. }
  21. return
  22. }
  23. func TestDao_UpList(t *testing.T) {
  24. Convey("TestDao_UpList", t, WithDao(func(d *Dao) {
  25. mids, errGet := getMids(5)
  26. if errGet != nil {
  27. fmt.Println("empty mids")
  28. return
  29. }
  30. res, pager, err := d.UpList(1, 1, mids)
  31. So(err, ShouldBeNil)
  32. So(pager, ShouldNotBeNil)
  33. So(len(res), ShouldBeGreaterThan, 0)
  34. }))
  35. }
  36. func TestDao_VerifyIds(t *testing.T) {
  37. Convey("TestDao_VerifyIds", t, WithDao(func(d *Dao) {
  38. mids, errGet := getMids(25)
  39. if errGet != nil {
  40. fmt.Println("empty mids")
  41. return
  42. }
  43. okMids, err := d.VerifyIds(mids)
  44. So(err, ShouldBeNil)
  45. So(len(mids), ShouldBeGreaterThanOrEqualTo, len(okMids))
  46. data, _ := json.Marshal(okMids)
  47. fmt.Println(string(data))
  48. }))
  49. }
  50. func TestDao_AuditIds(t *testing.T) {
  51. Convey("TestDao_AuditIds", t, WithDao(func(d *Dao) {
  52. mids, errGet := getMids(15)
  53. if errGet != nil {
  54. fmt.Println("empty mids")
  55. return
  56. }
  57. err := d.AuditIds(mids, 1)
  58. So(err, ShouldBeNil)
  59. }))
  60. }
  61. func TestDao_DelCache(t *testing.T) {
  62. Convey("TestDao_DelCache", t, WithDao(func(d *Dao) {
  63. var (
  64. mid = int64(88895270)
  65. ctx = context.Background()
  66. )
  67. err := d.SetUpMetaCache(ctx, &model.UpMC{
  68. MID: mid,
  69. })
  70. So(err, ShouldBeNil)
  71. err = d.DelCache(ctx, mid)
  72. So(err, ShouldBeNil)
  73. }))
  74. }