agent_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package report
  2. import (
  3. "sync"
  4. "testing"
  5. "time"
  6. "go-common/library/queue/databus"
  7. xtime "go-common/library/time"
  8. )
  9. var (
  10. mnOnce sync.Once
  11. mnUatOnce sync.Once
  12. userOnce sync.Once
  13. userUatOnce sync.Once
  14. )
  15. func newManager() {
  16. InitManager(nil)
  17. }
  18. func newUatManager() {
  19. InitManager(&databus.Config{
  20. Key: "2511663d546f1413",
  21. Secret: "cde3b480836cc76df3d635470f991caa",
  22. Group: "LogAudit-MainSearch-P",
  23. Topic: "LogAudit-T",
  24. Action: "pub",
  25. Buffer: 10240,
  26. Name: "log-audit/log-sub",
  27. Proto: "tcp",
  28. Addr: "172.18.33.50:6205",
  29. Active: 100,
  30. Idle: 100,
  31. DialTimeout: xtime.Duration(time.Millisecond * 200),
  32. ReadTimeout: xtime.Duration(time.Millisecond * 200),
  33. WriteTimeout: xtime.Duration(time.Millisecond * 200),
  34. IdleTimeout: xtime.Duration(time.Second * 80),
  35. })
  36. }
  37. func newUser() {
  38. InitUser(nil)
  39. }
  40. func newUatUser() {
  41. InitManager(&databus.Config{
  42. Key: "2511663d546f1413",
  43. Secret: "cde3b480836cc76df3d635470f991caa",
  44. Group: "LogUserAction-MainSearch-P",
  45. Topic: "LogUserAction-T",
  46. Action: "pub",
  47. Buffer: 10240,
  48. Name: "log-user-action/log-sub",
  49. Proto: "tcp",
  50. Addr: "172.18.33.50:6205",
  51. Active: 100,
  52. Idle: 100,
  53. DialTimeout: xtime.Duration(time.Millisecond * 200),
  54. ReadTimeout: xtime.Duration(time.Millisecond * 200),
  55. WriteTimeout: xtime.Duration(time.Millisecond * 200),
  56. IdleTimeout: xtime.Duration(time.Second * 80),
  57. })
  58. }
  59. func Test_Manager(b *testing.T) {
  60. mnOnce.Do(newManager)
  61. Manager(&ManagerInfo{
  62. Uname: "dz",
  63. UID: 64,
  64. Business: 0,
  65. Type: 1,
  66. Oid: 2,
  67. Action: "action",
  68. Ctime: time.Now(),
  69. Index: []interface{}{5, 6, 7, "a", "b", "c"},
  70. Content: map[string]interface{}{
  71. "json": "json",
  72. },
  73. })
  74. }
  75. func Test_UatManager(b *testing.T) {
  76. mnUatOnce.Do(newUatManager)
  77. Manager(&ManagerInfo{
  78. Uname: "dz",
  79. UID: 64,
  80. Business: 0,
  81. Type: 1,
  82. Oid: 2,
  83. Action: "action",
  84. Ctime: time.Now(),
  85. Index: []interface{}{5, 6, 7, "a", "b", "c"},
  86. Content: map[string]interface{}{
  87. "json": "json",
  88. },
  89. })
  90. }
  91. func Test_User(b *testing.T) {
  92. userOnce.Do(newUser)
  93. User(&UserInfo{
  94. Mid: 1,
  95. Platform: "platform",
  96. Build: 2,
  97. Buvid: "buvid",
  98. Business: 0,
  99. Type: 3,
  100. Oid: 4,
  101. Action: "action",
  102. Ctime: time.Now(),
  103. IP: "127.0.0.1",
  104. // extra
  105. Index: []interface{}{5, 6, 7, "a", "b", "c"},
  106. Content: map[string]interface{}{
  107. "json": "json",
  108. },
  109. })
  110. }
  111. func Test_UatUser(b *testing.T) {
  112. userUatOnce.Do(newUatUser)
  113. User(&UserInfo{
  114. Mid: 1,
  115. Platform: "platform",
  116. Build: 2,
  117. Buvid: "buvid",
  118. Business: 0,
  119. Type: 3,
  120. Oid: 4,
  121. Action: "action",
  122. Ctime: time.Now(),
  123. IP: "127.0.0.1",
  124. // extra
  125. Index: []interface{}{5, 6, 7, "a", "b", "c"},
  126. Content: map[string]interface{}{
  127. "json": "json",
  128. },
  129. })
  130. }