mysql_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func Test_Categories(t *testing.T) {
  9. Convey("should get data", t, func() {
  10. res, err := d.Categories(context.TODO())
  11. So(err, ShouldBeNil)
  12. So(res, ShouldNotBeEmpty)
  13. })
  14. }
  15. func Test_ArticlesStats(t *testing.T) {
  16. Convey("get data", t, func() {
  17. res, err := d.ArticlesStats(context.TODO(), []int64{1})
  18. So(err, ShouldBeNil)
  19. So(res, ShouldNotBeEmpty)
  20. })
  21. Convey("no data", t, func() {
  22. res, err := d.ArticlesStats(context.TODO(), []int64{100000})
  23. So(err, ShouldBeNil)
  24. So(res, ShouldBeNil)
  25. })
  26. }
  27. func Test_AddComplaint(t *testing.T) {
  28. Convey("add data", t, func() {
  29. err := d.AddComplaint(context.TODO(), 1, 2, 3, "reason", "http://1.ipg")
  30. So(err, ShouldBeNil)
  31. })
  32. }
  33. func Test_Notices(t *testing.T) {
  34. Convey("get data", t, func() {
  35. t := time.Unix(1513322993, 0)
  36. res, err := d.Notices(context.TODO(), t)
  37. So(err, ShouldBeNil)
  38. So(res, ShouldNotBeEmpty)
  39. })
  40. }
  41. func Test_NoticeState(t *testing.T) {
  42. Convey("add data", t, func() {
  43. mid := int64(100)
  44. state := int64(1)
  45. err := d.UpdateNoticeState(context.TODO(), mid, state)
  46. So(err, ShouldBeNil)
  47. Convey("get data", func() {
  48. res, err := d.NoticeState(context.TODO(), mid)
  49. So(err, ShouldBeNil)
  50. So(res, ShouldEqual, state)
  51. })
  52. })
  53. }
  54. func Test_Hotspot(t *testing.T) {
  55. Convey("should get data", t, func() {
  56. res, err := d.Hotspots(context.TODO())
  57. So(err, ShouldBeNil)
  58. So(res, ShouldNotBeEmpty)
  59. })
  60. }
  61. func Test_SearchArts(t *testing.T) {
  62. Convey("should get data", t, func() {
  63. _searchInterval = 24 * 3600 * 365
  64. res, err := d.SearchArts(context.TODO(), 0)
  65. So(err, ShouldBeNil)
  66. So(res, ShouldNotBeEmpty)
  67. })
  68. }
  69. func Test_CheatFilter(t *testing.T) {
  70. Convey("add data", t, func() {
  71. err := d.AddCheatFilter(context.TODO(), 100, 2)
  72. So(err, ShouldBeNil)
  73. err = d.DelCheatFilter(context.TODO(), 100)
  74. So(err, ShouldBeNil)
  75. })
  76. }