mysql_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "testing"
  6. "time"
  7. "go-common/app/interface/main/push-archive/model"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func Test_mxID(t *testing.T) {
  11. _, err := d.SettingsMaxID(context.TODO())
  12. convey.Convey("获取最大的设置id", t, func() {
  13. convey.So(err, convey.ShouldBeNil)
  14. })
  15. }
  16. func Test_settingsall(t *testing.T) {
  17. res := make(map[int64]*model.Setting)
  18. start, end := int64(2), int64(3)
  19. err := d.SettingsAll(context.TODO(), start, end, &res)
  20. convey.Convey("batch search settings", t, func() {
  21. convey.So(err, convey.ShouldBeNil)
  22. convey.So(len(res), convey.ShouldEqual, 0)
  23. })
  24. start, end = int64(0), int64(10)
  25. err = d.SettingsAll(context.TODO(), start, end, &res)
  26. convey.Convey("batch search settings", t, func() {
  27. convey.So(err, convey.ShouldBeNil)
  28. convey.So(len(res), convey.ShouldBeGreaterThan, 0)
  29. })
  30. }
  31. func Test_statistics(t *testing.T) {
  32. fans := []int64{1, 2, 3, 4, 5}
  33. b, err1 := json.Marshal(fans)
  34. ps := model.PushStatistic{
  35. Aid: int64(101),
  36. Group: "ai:pushlist_follow_recent",
  37. Type: model.StatisticsUnpush,
  38. Mids: string(b),
  39. MidsCounter: len(fans),
  40. CTime: time.Now(),
  41. }
  42. rows, err := d.SetStatistics(context.TODO(), &ps)
  43. convey.Convey("添加统计数据", t, func() {
  44. convey.So(err1, convey.ShouldBeNil)
  45. convey.So(err, convey.ShouldBeNil)
  46. convey.So(rows, convey.ShouldEqual, 1)
  47. })
  48. }