monitor_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package service
  2. import (
  3. "context"
  4. "github.com/golang/mock/gomock"
  5. . "github.com/smartystreets/goconvey/convey"
  6. "go-common/app/job/main/aegis/model/monitor"
  7. accApi "go-common/app/service/main/account/api"
  8. "testing"
  9. )
  10. func WithMock(t *testing.T, f func(mock *gomock.Controller)) func() {
  11. return func() {
  12. mockCtrl := gomock.NewController(t)
  13. defer mockCtrl.Finish()
  14. f(mockCtrl)
  15. }
  16. }
  17. func TestService_monitorArchive(t *testing.T) {
  18. var (
  19. na = &monitor.BinlogArchive{
  20. ID: 10111555,
  21. State: -100,
  22. Round: 10,
  23. MID: 666,
  24. TypeID: 2422,
  25. }
  26. )
  27. Convey("monitorUpDelArc", t, func(ctx C) {
  28. errs := s.monitorArchive("update", nil, na)
  29. So(errs, ShouldNotBeEmpty)
  30. })
  31. }
  32. func TestService_monitorUpDelArc(t *testing.T) {
  33. var (
  34. na = &monitor.BinlogArchive{
  35. ID: 10111555,
  36. State: -100,
  37. Round: 10,
  38. MID: 666,
  39. TypeID: 24,
  40. }
  41. logs []string
  42. )
  43. Convey("monitorUpDelArc", t, func(ctx C) {
  44. _, logs, _ = s.monitorUpDelArc(1, na)
  45. So(logs, ShouldNotBeEmpty)
  46. })
  47. }
  48. func TestService_monitorVideo(t *testing.T) {
  49. var (
  50. na = &monitor.BinlogVideo{
  51. ID: 10134809,
  52. Status: 0,
  53. }
  54. )
  55. Convey("monitorVideo", t, func(ctx C) {
  56. errs := s.monitorVideo("update", nil, na)
  57. So(errs, ShouldBeEmpty)
  58. })
  59. }
  60. func TestService_reflectIntVal(t *testing.T) {
  61. var (
  62. a = &monitor.BinlogArchive{
  63. ID: 123,
  64. State: 0,
  65. Round: 10,
  66. MID: 666,
  67. TypeID: 22,
  68. Addit: &monitor.ArchiveAddit{
  69. MissionID: 999,
  70. },
  71. }
  72. )
  73. Convey("reflectIntVal", t, func(ctx C) {
  74. _, err := s.reflectIntVal(a, "Addit.MissionID", 0)
  75. So(err, ShouldBeNil)
  76. _, err = s.reflectIntVal(a, "Addit111", 0)
  77. So(err, ShouldNotBeNil)
  78. _, err = s.reflectIntVal(a, "ID", 0)
  79. So(err, ShouldBeNil)
  80. })
  81. }
  82. func TestService_monitorCompSatisfy(t *testing.T) {
  83. Convey("monitorCompSatisfy >=", t, func(ctx C) {
  84. is, err := s.monitorCompSatisfy(">=10", 11)
  85. So(err, ShouldBeNil)
  86. So(is, ShouldBeTrue)
  87. is, err = s.monitorCompSatisfy(">10", 10)
  88. So(err, ShouldBeNil)
  89. So(is, ShouldBeFalse)
  90. is, err = s.monitorCompSatisfy("=10", 10)
  91. So(err, ShouldBeNil)
  92. So(is, ShouldBeTrue)
  93. is, err = s.monitorCompSatisfy("in(10,20,30)", 10)
  94. So(err, ShouldBeNil)
  95. So(is, ShouldBeTrue)
  96. is, err = s.monitorCompSatisfy("in(10,20,30)", 40)
  97. So(err, ShouldBeNil)
  98. So(is, ShouldBeFalse)
  99. })
  100. }
  101. func TestService_monitorSave(t *testing.T) {
  102. Convey("monitorSave", t, func(ctx C) {
  103. _, errs := s.monitorSave([]string{"monitor_test_1"}, []string{"monitor_test_2"}, 123)
  104. So(errs, ShouldBeEmpty)
  105. })
  106. }
  107. func TestService_multiAccounts(t *testing.T) {
  108. var c = context.Background()
  109. Convey("multiAccounts", t, WithMock(t, func(mockCtrl *gomock.Controller) {
  110. mock := accApi.NewMockAccountClient(mockCtrl)
  111. s.acc = mock
  112. mockReq := &accApi.MidReq{
  113. Mid: 123,
  114. }
  115. mock.EXPECT().ProfileWithStat3(gomock.Any(), mockReq).Return(&accApi.ProfileStatReply{}, nil)
  116. _, err := s.multiAccounts(c, []int64{123})
  117. So(err, ShouldBeNil)
  118. }))
  119. }