monitor_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/aegis/model/monitor"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestServiceMonitorBuzResult(t *testing.T) {
  9. convey.Convey("MonitorBuzResult", t, func(convCtx convey.C) {
  10. var (
  11. c = context.Background()
  12. bid = int64(2)
  13. )
  14. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  15. _, err := s.MonitorBuzResult(c, bid)
  16. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  17. convCtx.So(err, convey.ShouldBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestServiceMonitorResultOids(t *testing.T) {
  23. convey.Convey("MonitorBuzResult", t, func(convCtx convey.C) {
  24. var (
  25. c = context.Background()
  26. id = int64(1)
  27. )
  28. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  29. _, err := s.MonitorResultOids(c, id)
  30. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  31. convCtx.So(err, convey.ShouldBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestServiceMonitorNotifyTime(t *testing.T) {
  37. convey.Convey("MonitorNotifyTime", t, func(convCtx convey.C) {
  38. var (
  39. conf = &monitor.RuleConf{
  40. NotifyCdt: map[string]struct {
  41. Comp string `json:"comparison"`
  42. Value int64 `json:"value"`
  43. }{
  44. "time": {
  45. Comp: ">",
  46. Value: 1,
  47. },
  48. },
  49. }
  50. )
  51. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  52. _, _, err := s.monitorNotifyTime(conf)
  53. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  54. convCtx.So(err, convey.ShouldBeNil)
  55. })
  56. })
  57. })
  58. }