mysql_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. artmdl "go-common/app/interface/openplatform/article/model"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func Test_Update(t *testing.T) {
  9. var (
  10. c = context.TODO()
  11. cnt1 = int64(1)
  12. cnt2 = int64(2)
  13. st1 = &artmdl.StatMsg{
  14. Aid: 888,
  15. View: &cnt1,
  16. Favorite: &cnt1,
  17. Like: &cnt1,
  18. Dislike: &cnt1,
  19. Reply: &cnt1,
  20. Share: &cnt1,
  21. }
  22. st2 = &artmdl.StatMsg{
  23. Aid: 888,
  24. View: &cnt2,
  25. Favorite: &cnt2,
  26. Like: &cnt2,
  27. Dislike: &cnt2,
  28. Reply: &cnt2,
  29. Share: &cnt2,
  30. }
  31. )
  32. Convey("update stats", t, WithDao(func(d *Dao) {
  33. rows, err := d.Update(c, st1)
  34. So(err, ShouldBeNil)
  35. So(rows, ShouldBeGreaterThan, 0)
  36. Convey("get st1", func() {
  37. stat, err1 := d.Stat(c, 888)
  38. So(err1, ShouldBeNil)
  39. So(stat, ShouldResemble, st1)
  40. })
  41. rows, err = d.Update(c, st2)
  42. So(err, ShouldBeNil)
  43. So(rows, ShouldBeGreaterThan, 0)
  44. Convey("get st2", func() {
  45. stat, err1 := d.Stat(c, 888)
  46. So(err1, ShouldBeNil)
  47. So(stat, ShouldResemble, st2)
  48. })
  49. }))
  50. }
  51. func Test_GameList(t *testing.T) {
  52. Convey("work", t, WithDao(func(d *Dao) {
  53. mids, err := d.GameList(context.Background())
  54. So(err, ShouldBeNil)
  55. So(mids, ShouldNotBeEmpty)
  56. }))
  57. }
  58. func Test_NewestArtIDByCategory(t *testing.T) {
  59. var _dataCategory = int64(6)
  60. Convey("get data", t, WithDao(func(d *Dao) {
  61. res, err := d.NewestArtIDByCategory(context.TODO(), []int64{_dataCategory}, 100)
  62. So(err, ShouldBeNil)
  63. So(res, ShouldNotBeEmpty)
  64. }))
  65. Convey("no data", t, WithDao(func(d *Dao) {
  66. res, err := d.NewestArtIDByCategory(context.TODO(), []int64{1000}, 100)
  67. So(err, ShouldBeNil)
  68. So(res, ShouldBeEmpty)
  69. }))
  70. }
  71. func Test_NewestArtIDs(t *testing.T) {
  72. Convey("get data", t, WithDao(func(d *Dao) {
  73. res, err := d.NewestArtIDs(context.TODO(), 100)
  74. So(err, ShouldBeNil)
  75. So(res, ShouldNotBeEmpty)
  76. }))
  77. }
  78. func Test_SearchArts(t *testing.T) {
  79. Convey("should get data", t, WithDao(func(d *Dao) {
  80. _searchInterval = 24 * 3600 * 365
  81. res, err := d.SearchArts(context.TODO(), 0)
  82. So(err, ShouldBeNil)
  83. So(res, ShouldNotBeEmpty)
  84. }))
  85. }