assist_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package client
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. model "go-common/app/service/main/assist/model/assist"
  7. "github.com/davecgh/go-spew/spew"
  8. )
  9. const (
  10. mid = 27515256
  11. assistMid = 27515255
  12. realIP = "127.0.0.1"
  13. logID = 692
  14. subjectID = 111
  15. objectID = "222"
  16. detail = "testing"
  17. pn = 1
  18. ps = 20
  19. )
  20. func TestAssistRpcService(t *testing.T) {
  21. s := New(nil)
  22. time.Sleep(1 * time.Second)
  23. // test assist relation
  24. delAssist(t, s)
  25. addAssist(t, s)
  26. assist(t, s)
  27. assists(t, s)
  28. assistIDs(t, s)
  29. assistUps(t, s)
  30. assistExit(t, s)
  31. // test assistlog
  32. assistLogAdd(t, s)
  33. assistLogInfo(t, s)
  34. assistLogCancel(t, s)
  35. assistLogs(t, s)
  36. }
  37. func delAssist(t *testing.T, s *Service) {
  38. arg := &model.ArgAssist{
  39. Mid: mid,
  40. AssistMid: assistMid,
  41. RealIP: realIP,
  42. }
  43. if err := s.DelAssist(context.TODO(), arg); err != nil {
  44. t.Logf("call error(%v)", err)
  45. }
  46. }
  47. func addAssist(t *testing.T, s *Service) {
  48. arg := &model.ArgAssist{
  49. Mid: mid,
  50. AssistMid: assistMid,
  51. RealIP: realIP,
  52. }
  53. if err := s.AddAssist(context.TODO(), arg); err != nil {
  54. t.Logf("call error(%v)", err)
  55. }
  56. }
  57. func assistLogAdd(t *testing.T, s *Service) {
  58. arg := &model.ArgAssistLogAdd{
  59. Mid: mid,
  60. AssistMid: assistMid,
  61. Type: model.TypeComment,
  62. Action: model.ActDelete,
  63. SubjectID: subjectID,
  64. ObjectID: objectID,
  65. Detail: detail,
  66. RealIP: realIP,
  67. }
  68. if err := s.AssistLogAdd(context.TODO(), arg); err != nil {
  69. t.Logf("call error(%v)", err)
  70. }
  71. }
  72. func assists(t *testing.T, s *Service) {
  73. arg := &model.ArgAssists{
  74. Mid: mid,
  75. RealIP: realIP,
  76. }
  77. if res, err := s.Assists(context.TODO(), arg); err != nil && res != nil {
  78. t.Logf("call error(%v)", err)
  79. }
  80. }
  81. func assistIDs(t *testing.T, s *Service) {
  82. arg := &model.ArgAssists{
  83. Mid: mid,
  84. RealIP: realIP,
  85. }
  86. if res, err := s.AssistIDs(context.TODO(), arg); err != nil && res != nil {
  87. t.Logf("call error(%v)", err)
  88. }
  89. }
  90. func assistUps(t *testing.T, s *Service) {
  91. arg := &model.ArgAssistUps{
  92. AssistMid: assistMid,
  93. Ps: 20,
  94. Pn: 1,
  95. RealIP: realIP,
  96. }
  97. if res, err := s.AssistUps(context.TODO(), arg); err != nil && res != nil {
  98. spew.Dump(res)
  99. t.Logf("call error(%v)", err)
  100. }
  101. }
  102. func assistExit(t *testing.T, s *Service) {
  103. arg := &model.ArgAssist{
  104. AssistMid: assistMid,
  105. Mid: mid,
  106. RealIP: realIP,
  107. }
  108. if err := s.AssistExit(context.TODO(), arg); err != nil {
  109. t.Logf("call error(%v)", err)
  110. }
  111. }
  112. func assistLogInfo(t *testing.T, s *Service) {
  113. arg := &model.ArgAssistLog{
  114. Mid: mid,
  115. AssistMid: assistMid,
  116. LogID: logID,
  117. RealIP: realIP,
  118. }
  119. if res, err := s.AssistLogInfo(context.TODO(), arg); err != nil && res != nil {
  120. t.Logf("call error(%v)", err)
  121. }
  122. }
  123. func assist(t *testing.T, s *Service) {
  124. arg := &model.ArgAssist{
  125. Mid: mid,
  126. AssistMid: assistMid,
  127. RealIP: realIP,
  128. }
  129. if res, err := s.Assist(context.TODO(), arg); err != nil && res != nil {
  130. spew.Dump(res)
  131. t.Logf("call error(%v)", err)
  132. }
  133. }
  134. func assistLogs(t *testing.T, s *Service) {
  135. arg := &model.ArgAssistLogs{
  136. Mid: mid,
  137. AssistMid: assistMid,
  138. Stime: time.Unix(time.Now().Unix(), 0),
  139. Etime: time.Unix(time.Now().Add(48*time.Hour).Unix(), 0),
  140. Pn: ps,
  141. Ps: pn,
  142. RealIP: realIP,
  143. }
  144. if res, err := s.AssistLogs(context.TODO(), arg); err != nil && res != nil {
  145. t.Logf("call error(%v)", err)
  146. }
  147. }
  148. func assistLogCancel(t *testing.T, s *Service) {
  149. arg := &model.ArgAssistLog{
  150. Mid: mid,
  151. AssistMid: assistMid,
  152. LogID: logID,
  153. RealIP: realIP,
  154. }
  155. if err := s.AssistLogCancel(context.TODO(), arg); err != nil {
  156. t.Logf("call error(%v)", err)
  157. }
  158. }