redis_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package monitor
  2. import (
  3. "context"
  4. "go-common/app/job/main/aegis/model/monitor"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestMonitorAddToSet(t *testing.T) {
  9. convey.Convey("AddToSet", t, func(convCtx convey.C) {
  10. var (
  11. c = context.Background()
  12. keys = []string{"monitor_test"}
  13. oid = int64(123)
  14. )
  15. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  16. _, err := d.AddToSet(c, keys, oid)
  17. convCtx.Convey("Then err should be nil.logs should not be nil.", func(convCtx convey.C) {
  18. convCtx.So(err, convey.ShouldBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestMonitorRemFromSet(t *testing.T) {
  24. convey.Convey("RemFromSet", t, func(convCtx convey.C) {
  25. var (
  26. c = context.Background()
  27. keys = []string{"monitor_test"}
  28. oid = int64(123)
  29. )
  30. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  31. _, err := d.RemFromSet(c, keys, oid)
  32. convCtx.Convey("Then err should be nil.logs should not be nil.", func(convCtx convey.C) {
  33. convCtx.So(err, convey.ShouldBeNil)
  34. })
  35. })
  36. })
  37. }
  38. func TestMonitorClearExpireSet(t *testing.T) {
  39. convey.Convey("ClearExpireSet", t, func(convCtx convey.C) {
  40. var (
  41. c = context.Background()
  42. keys = []string{"monitor_test"}
  43. )
  44. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  45. _, err := d.ClearExpireSet(c, keys)
  46. convCtx.Convey("Then err should be nil.logs should not be nil.", func(convCtx convey.C) {
  47. convCtx.So(err, convey.ShouldBeNil)
  48. })
  49. })
  50. })
  51. }
  52. func TestMonitorAddToDelArc(t *testing.T) {
  53. convey.Convey("AddToDelArc", t, func(convCtx convey.C) {
  54. var (
  55. c = context.Background()
  56. a = &monitor.BinlogArchive{
  57. ID: 123,
  58. }
  59. )
  60. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  61. err := d.AddToDelArc(c, a)
  62. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  63. convCtx.So(err, convey.ShouldBeNil)
  64. })
  65. })
  66. })
  67. }
  68. func TestMonitorArcDelInfos(t *testing.T) {
  69. convey.Convey("ArcDelInfos", t, func(convCtx convey.C) {
  70. var (
  71. c = context.Background()
  72. aids = []int64{123}
  73. )
  74. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  75. _, err := d.ArcDelInfos(c, aids)
  76. convCtx.Convey("Then err should be nil.infos should not be nil.", func(convCtx convey.C) {
  77. convCtx.So(err, convey.ShouldBeNil)
  78. })
  79. })
  80. })
  81. }
  82. func TestMonitorMoniRuleStats(t *testing.T) {
  83. convey.Convey("MoniRuleStats", t, func(convCtx convey.C) {
  84. var (
  85. c = context.Background()
  86. id = int64(1)
  87. min = int64(0)
  88. max = int64(0)
  89. )
  90. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  91. _, err := d.MoniRuleStats(c, id, min, max)
  92. convCtx.Convey("Then err should be nil.stats should not be nil.", func(convCtx convey.C) {
  93. convCtx.So(err, convey.ShouldBeNil)
  94. })
  95. })
  96. })
  97. }
  98. func TestMonitorMoniRuleOids(t *testing.T) {
  99. convey.Convey("MoniRuleOids", t, func(convCtx convey.C) {
  100. var (
  101. c = context.Background()
  102. id = int64(1)
  103. min = int64(0)
  104. max = int64(0)
  105. )
  106. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  107. _, err := d.MoniRuleOids(c, id, min, max)
  108. convCtx.Convey("Then err should be nil.oidMap should not be nil.", func(convCtx convey.C) {
  109. convCtx.So(err, convey.ShouldBeNil)
  110. })
  111. })
  112. })
  113. }