db_test.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/reply-feed/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoSlotsMapping(t *testing.T) {
  9. convey.Convey("SlotsMapping", t, func(ctx convey.C) {
  10. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  11. slotsMap, err := d.SlotsMapping(context.Background())
  12. ctx.Convey("Then err should be nil.slotsMap should not be nil.", func(ctx convey.C) {
  13. ctx.So(err, convey.ShouldBeNil)
  14. ctx.So(slotsMap, convey.ShouldNotBeNil)
  15. })
  16. })
  17. })
  18. }
  19. func TestDaoSlotsStatManager(t *testing.T) {
  20. convey.Convey("SlotsStatManager", t, func(ctx convey.C) {
  21. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  22. s, err := d.SlotsStatManager(context.Background())
  23. ctx.Convey("Then err should be nil.s should not be nil.", func(ctx convey.C) {
  24. ctx.So(err, convey.ShouldBeNil)
  25. ctx.So(s, convey.ShouldNotBeNil)
  26. })
  27. })
  28. })
  29. }
  30. func TestDaoIdleSlot(t *testing.T) {
  31. convey.Convey("IdleSlot", t, func(ctx convey.C) {
  32. var (
  33. count = int(0)
  34. )
  35. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  36. slots, err := d.IdleSlots(context.Background(), count)
  37. ctx.Convey("Then err should be nil.slots should not be nil.", func(ctx convey.C) {
  38. ctx.So(err, convey.ShouldBeNil)
  39. ctx.So(slots, convey.ShouldBeNil)
  40. })
  41. })
  42. })
  43. }
  44. func TestDaoCountIdleSlot(t *testing.T) {
  45. convey.Convey("CountIdleSlot", t, func(ctx convey.C) {
  46. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  47. count, err := d.CountIdleSlot(context.Background())
  48. ctx.Convey("Then err should be nil. count should greater than 0.", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldBeNil)
  50. ctx.So(count, convey.ShouldBeGreaterThan, 0)
  51. })
  52. })
  53. })
  54. }
  55. func TestDaoModifyState(t *testing.T) {
  56. convey.Convey("ModifyState", t, func(ctx convey.C) {
  57. var (
  58. name = ""
  59. state = int(0)
  60. )
  61. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  62. err := d.ModifyState(context.Background(), name, state)
  63. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  64. ctx.So(err, convey.ShouldBeNil)
  65. })
  66. })
  67. })
  68. }
  69. func TestDaoUpdateSlotsStat(t *testing.T) {
  70. convey.Convey("UpdateSlotsStat", t, func(ctx convey.C) {
  71. var (
  72. name = ""
  73. algorithm = ""
  74. weight = ""
  75. slots = []int64{-1}
  76. state = int(0)
  77. )
  78. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  79. err := d.UpdateSlotsStat(context.Background(), name, algorithm, weight, slots, state)
  80. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. })
  83. })
  84. })
  85. }
  86. func TestSlotsStatByName(t *testing.T) {
  87. convey.Convey("SlotsStatByName", t, func(ctx convey.C) {
  88. var (
  89. name = ""
  90. )
  91. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  92. slots, algorithm, weight, err := d.SlotsStatByName(context.Background(), name)
  93. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  94. ctx.So(err, convey.ShouldBeNil)
  95. ctx.So(slots, convey.ShouldBeNil)
  96. ctx.So(algorithm, convey.ShouldEqual, "")
  97. ctx.So(weight, convey.ShouldEqual, "")
  98. })
  99. })
  100. })
  101. }
  102. func TestDaoUpdateWeight(t *testing.T) {
  103. convey.Convey("UpdateWeight", t, func(ctx convey.C) {
  104. var (
  105. name = ""
  106. weight = interface{}(0)
  107. )
  108. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  109. err := d.UpdateWeight(context.Background(), name, weight)
  110. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  111. ctx.So(err, convey.ShouldBeNil)
  112. })
  113. })
  114. })
  115. }
  116. func TestDaoUpsertStatistics(t *testing.T) {
  117. convey.Convey("UpsertStatistics", t, func(ctx convey.C) {
  118. var (
  119. name = ""
  120. date = int(0)
  121. hour = int(0)
  122. s = &model.StatisticsStat{}
  123. )
  124. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  125. err := d.UpsertStatistics(context.Background(), name, date, hour, s)
  126. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  127. ctx.So(err, convey.ShouldBeNil)
  128. })
  129. })
  130. })
  131. }
  132. func TestDaoStatisticsByDate(t *testing.T) {
  133. convey.Convey("StatisticsByDate", t, func(ctx convey.C) {
  134. var (
  135. begin = int64(0)
  136. end = int64(0)
  137. )
  138. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  139. stats, err := d.StatisticsByDate(context.Background(), begin, end)
  140. ctx.Convey("Then err should be nil.stats should not be nil.", func(ctx convey.C) {
  141. ctx.So(err, convey.ShouldBeNil)
  142. ctx.So(stats, convey.ShouldNotBeNil)
  143. })
  144. })
  145. })
  146. }