redis_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package monitor
  2. import (
  3. "context"
  4. "go-common/app/admin/main/videoup/model/monitor"
  5. "testing"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDao_GetRules(t *testing.T) {
  9. Convey("GetRules", t, func() {
  10. rules, err := d.GetRules(context.TODO(), 1, 1, true)
  11. So(err, ShouldBeNil)
  12. So(rules, ShouldNotBeNil)
  13. })
  14. }
  15. func TestDao_SetRule(t *testing.T) {
  16. Convey("SetRule", t, func() {
  17. rule := &monitor.Rule{
  18. ID: 1,
  19. Type: 1,
  20. Business: 1,
  21. Name: "一审阶段",
  22. State: 1,
  23. RuleConf: &monitor.RuleConf{
  24. Name: "一审长耗时",
  25. MoniCdt: map[string]struct {
  26. Comp string `json:"comparison"`
  27. Value int64 `json:"value"`
  28. }{
  29. "state": {
  30. Comp: "=",
  31. Value: -1,
  32. },
  33. },
  34. NotifyCdt: map[string]struct {
  35. Comp string `json:"comparison"`
  36. Value int64 `json:"value"`
  37. }{
  38. "count": {
  39. Comp: ">",
  40. Value: 10,
  41. },
  42. "time": {
  43. Comp: ">",
  44. Value: 10,
  45. },
  46. },
  47. Notify: struct {
  48. Way int8 `json:"way"`
  49. Member []string `json:"member"`
  50. }{
  51. Way: monitor.NotifyTypeEmail,
  52. Member: []string{"liusiming@bilibili.com"},
  53. },
  54. },
  55. }
  56. /*rule := &monitor.Rule{
  57. ID: 6,
  58. Type: 1,
  59. Business: 2,
  60. Name: "二审阶段",
  61. State: 1,
  62. RuleConf: &monitor.RuleConf{
  63. Name: "二审长耗时",
  64. MoniCdt: map[string]struct {
  65. Comp string `json:"comparison"`
  66. Value int64 `json:"value"`
  67. }{
  68. "state": {
  69. Comp: "=",
  70. Value: -1,
  71. },
  72. "round": {
  73. Comp: "=",
  74. Value: 10,
  75. },
  76. },
  77. NotifyCdt: map[string]struct {
  78. Comp string `json:"comparison"`
  79. Value int64 `json:"value"`
  80. }{
  81. "count": {
  82. Comp: ">",
  83. Value: 10,
  84. },
  85. "time": {
  86. Comp: ">",
  87. Value: 10,
  88. },
  89. },
  90. Notify: struct {
  91. Way int8 `json:"way"`
  92. Member []string `json:"member"`
  93. }{
  94. Way: monitor.NotifyTypeEmail,
  95. Member: []string{"liusiming@bilibili.com"},
  96. },
  97. },
  98. }*/
  99. err := d.SetRule(context.TODO(), rule)
  100. So(err, ShouldBeNil)
  101. })
  102. }
  103. func TestDao_SetRuleState(t *testing.T) {
  104. Convey("SetRuleState", t, func() {
  105. err := d.SetRuleState(context.TODO(), 1, 1, 1, monitor.RuleStateOK)
  106. So(err, ShouldBeNil)
  107. })
  108. }
  109. func TestDao_BusKeys(t *testing.T) {
  110. Convey("BusKeys", t, func() {
  111. _, keys, err := d.BusStatsKeys(context.TODO(), 1)
  112. So(err, ShouldBeNil)
  113. So(keys, ShouldNotBeNil)
  114. })
  115. }
  116. func TestDao_GetAllRules(t *testing.T) {
  117. Convey("BusKeys", t, func() {
  118. _, err := d.GetAllRules(context.Background(), true)
  119. So(err, ShouldBeNil)
  120. })
  121. }