monitor_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/apm/model/monitor"
  6. "go-common/library/log"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestService_AddMonitor(t *testing.T) {
  10. var (
  11. c = context.Background()
  12. err error
  13. )
  14. convey.Convey("Test AddMonitor", t, func(ctx convey.C) {
  15. err = svr.AddMonitor(c)
  16. ctx.So(err, convey.ShouldBeNil)
  17. })
  18. }
  19. func TestService_PrometheusList(t *testing.T) {
  20. var (
  21. c = context.Background()
  22. )
  23. convey.Convey("Test PrometheusList", t, func(ctx convey.C) {
  24. ret, err := svr.PrometheusList(c, "main.account.member-service", "xx", "count")
  25. ctx.So(ret, convey.ShouldNotBeEmpty)
  26. ctx.So(err, convey.ShouldBeNil)
  27. })
  28. }
  29. func TestService_BroadCastList(t *testing.T) {
  30. var (
  31. c = context.Background()
  32. )
  33. convey.Convey("Test BroadCastList", t, func(ctx convey.C) {
  34. ret, err := svr.BroadCastList(c)
  35. ctx.So(ret, convey.ShouldNotBeEmpty)
  36. ctx.So(err, convey.ShouldBeNil)
  37. })
  38. }
  39. func TestService_Times(t *testing.T) {
  40. mt := &monitor.Monitor{}
  41. if err := svr.DB.Where("app_id = ?", "main.app-svr.app-feed-http").First(mt).Error; err != nil {
  42. log.Error("s.Prometheus query first error(%v)", err)
  43. return
  44. }
  45. convey.Convey("Test Times", t, func(ctx convey.C) {
  46. ret := svr.times(mt.MTime)
  47. t.Logf("times=%v", ret)
  48. })
  49. }