redis_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. model "go-common/app/service/main/secure/model"
  7. xtime "go-common/library/time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestRedis(t *testing.T) {
  11. convey.Convey("TestRedis", t, func() {
  12. lput := &model.Log{
  13. Mid: 2,
  14. Location: "上海",
  15. LocationID: 11,
  16. Time: xtime.Time(time.Now().Unix()),
  17. }
  18. d.AddExpectionMsg(context.TODO(), lput)
  19. lget, _ := d.ExpectionMsg(context.TODO(), 2)
  20. convey.So(lget.LocationID, convey.ShouldEqual, lput.LocationID)
  21. d.AddUnNotify(context.TODO(), 2, "1234")
  22. b, _ := d.UnNotify(context.TODO(), 2, "1234")
  23. convey.So(b, convey.ShouldBeTrue)
  24. d.DelUnNotify(context.TODO(), 2)
  25. b, _ = d.UnNotify(context.TODO(), 2, "1234")
  26. convey.So(b, convey.ShouldBeFalse)
  27. d.AddCount(context.TODO(), 2, "1234")
  28. d.AddCount(context.TODO(), 2, "1234")
  29. count, _ := d.Count(context.TODO(), 2, "1234")
  30. convey.So(count, convey.ShouldEqual, 2)
  31. d.DelCount(context.TODO(), 2)
  32. count, _ = d.Count(context.TODO(), 2, "1234")
  33. convey.So(count, convey.ShouldEqual, 0)
  34. })
  35. }
  36. func TestDoubleCheckKey(t *testing.T) {
  37. convey.Convey("doubleCheckKey", t, func() {
  38. p1 := doubleCheckKey(0)
  39. convey.So(p1, convey.ShouldNotBeNil)
  40. })
  41. }
  42. func TestChangePWDKey(t *testing.T) {
  43. convey.Convey("changePWDKey", t, func() {
  44. p1 := changePWDKey(0)
  45. convey.So(p1, convey.ShouldNotBeNil)
  46. })
  47. }
  48. func TestMsgKey(t *testing.T) {
  49. convey.Convey("msgKey", t, func() {
  50. p1 := msgKey(0)
  51. convey.So(p1, convey.ShouldNotBeNil)
  52. })
  53. }
  54. func TestUnnotifyKey(t *testing.T) {
  55. convey.Convey("unnotifyKey", t, func() {
  56. p1 := unnotifyKey(0)
  57. convey.So(p1, convey.ShouldNotBeNil)
  58. })
  59. }
  60. func TestCountKey(t *testing.T) {
  61. convey.Convey("countKey", t, func() {
  62. p1 := countKey(0)
  63. convey.So(p1, convey.ShouldNotBeNil)
  64. })
  65. }
  66. func TestDaoAddExpectionMsg(t *testing.T) {
  67. var mid int64 = 7593623
  68. convey.Convey("AddExpectionMsg", t, func() {
  69. l := &model.Log{Mid: mid}
  70. err := d.AddExpectionMsg(context.TODO(), l)
  71. convey.So(err, convey.ShouldBeNil)
  72. })
  73. convey.Convey("ExpectionMsg", t, func() {
  74. msg, err := d.ExpectionMsg(context.TODO(), mid)
  75. convey.So(err, convey.ShouldBeNil)
  76. convey.So(msg, convey.ShouldNotBeNil)
  77. })
  78. }
  79. func TestDaoAddUnNotify(t *testing.T) {
  80. convey.Convey("AddUnNotify", t, func() {
  81. err := d.AddUnNotify(context.TODO(), 0, "")
  82. convey.So(err, convey.ShouldBeNil)
  83. })
  84. }
  85. func TestDaoDelUnNotify(t *testing.T) {
  86. convey.Convey("DelUnNotify", t, func() {
  87. err := d.DelUnNotify(context.TODO(), 0)
  88. convey.So(err, convey.ShouldBeNil)
  89. })
  90. }
  91. func TestDaoUnNotify(t *testing.T) {
  92. convey.Convey("UnNotify", t, func() {
  93. b, err := d.UnNotify(context.TODO(), 0, "")
  94. convey.So(err, convey.ShouldBeNil)
  95. convey.So(b, convey.ShouldNotBeNil)
  96. })
  97. }
  98. func TestDaoCount(t *testing.T) {
  99. convey.Convey("Count", t, func() {
  100. count, err := d.Count(context.TODO(), 0, "")
  101. convey.So(err, convey.ShouldBeNil)
  102. convey.So(count, convey.ShouldNotBeNil)
  103. })
  104. }
  105. func TestDaoAddCount(t *testing.T) {
  106. convey.Convey("AddCount", t, func() {
  107. err := d.AddCount(context.TODO(), 0, "")
  108. convey.So(err, convey.ShouldBeNil)
  109. })
  110. }
  111. func TestDaoAddChangePWDRecord(t *testing.T) {
  112. convey.Convey("AddChangePWDRecord", t, func() {
  113. err := d.AddChangePWDRecord(context.TODO(), 0)
  114. convey.So(err, convey.ShouldBeNil)
  115. })
  116. }
  117. func TestDaoChangePWDRecord(t *testing.T) {
  118. convey.Convey("ChangePWDRecord", t, func() {
  119. b, err := d.ChangePWDRecord(context.TODO(), 0)
  120. convey.So(err, convey.ShouldBeNil)
  121. convey.So(b, convey.ShouldNotBeNil)
  122. })
  123. }
  124. func TestDaoDelCount(t *testing.T) {
  125. convey.Convey("DelCount", t, func() {
  126. err := d.DelCount(context.TODO(), 0)
  127. convey.So(err, convey.ShouldBeNil)
  128. })
  129. }
  130. func TestDaoAddDCheckCache(t *testing.T) {
  131. convey.Convey("AddDCheckCache", t, func() {
  132. err := d.AddDCheckCache(context.TODO(), 0)
  133. convey.So(err, convey.ShouldBeNil)
  134. })
  135. }
  136. func TestDaoDCheckCache(t *testing.T) {
  137. convey.Convey("DCheckCache", t, func() {
  138. b, err := d.DCheckCache(context.TODO(), 0)
  139. convey.So(err, convey.ShouldBeNil)
  140. convey.So(b, convey.ShouldNotBeNil)
  141. })
  142. }