rpc_test.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. package server
  2. import (
  3. "go-common/app/service/main/assist/conf"
  4. "go-common/app/service/main/assist/model/assist"
  5. model "go-common/app/service/main/assist/model/assist"
  6. "go-common/app/service/main/assist/service"
  7. "net/rpc"
  8. "testing"
  9. "time"
  10. "github.com/davecgh/go-spew/spew"
  11. )
  12. const (
  13. addr = "127.0.0.1:6729"
  14. _assists = "RPC.Assists"
  15. _assist = "RPC.Assist"
  16. _addAssist = "RPC.AddAssist"
  17. _delAssist = "RPC.DelAssist"
  18. _assistExit = "RPC.AssistExit"
  19. _assistLogInfo = "RPC.AssistLogInfo"
  20. _assistLogs = "RPC.AssistLogs"
  21. _assistLogAdd = "RPC.AssistLogAdd"
  22. _assistLogCancel = "RPC.AssistLogCancel"
  23. _assistUps = "RPC.AssistUps"
  24. )
  25. func TestAssistExit(t *testing.T) {
  26. if err := conf.Init(); err != nil {
  27. t.Errorf("conf.Init() error(%v)", err)
  28. t.FailNow()
  29. }
  30. svr := service.New(conf.Conf)
  31. New(conf.Conf, svr)
  32. client, err := rpc.Dial("tcp", addr)
  33. defer client.Close()
  34. if err != nil {
  35. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  36. t.FailNow()
  37. }
  38. assistExit(client, t)
  39. }
  40. func assistExit(client *rpc.Client, t *testing.T) {
  41. assistInfo := new(struct{})
  42. arg := &model.ArgAssist{
  43. Mid: 254386,
  44. AssistMid: 2,
  45. RealIP: "127.0.0.1",
  46. }
  47. err := client.Call(_assistExit, arg, assistInfo)
  48. if err != nil {
  49. t.Logf("err:%v.", err)
  50. }
  51. spew.Dump(assistInfo)
  52. }
  53. func TestAssistUps(t *testing.T) {
  54. if err := conf.Init(); err != nil {
  55. t.Errorf("conf.Init() error(%v)", err)
  56. t.FailNow()
  57. }
  58. svr := service.New(conf.Conf)
  59. New(conf.Conf, svr)
  60. client, err := rpc.Dial("tcp", addr)
  61. defer client.Close()
  62. if err != nil {
  63. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  64. t.FailNow()
  65. }
  66. assistUps(client, t)
  67. }
  68. func assistUps(client *rpc.Client, t *testing.T) {
  69. var res = &assist.AssistUpsPager{}
  70. arg := &model.ArgAssistUps{
  71. AssistMid: 88889017,
  72. Pn: 1,
  73. Ps: 20,
  74. RealIP: "127.0.0.1",
  75. }
  76. err := client.Call(_assistUps, arg, &res)
  77. if err != nil {
  78. t.Logf("err:%v.", err)
  79. }
  80. t.Logf("%+v", res)
  81. spew.Dump(res)
  82. }
  83. func TestAssists(t *testing.T) {
  84. if err := conf.Init(); err != nil {
  85. t.Errorf("conf.Init() error(%v)", err)
  86. t.FailNow()
  87. }
  88. svr := service.New(conf.Conf)
  89. New(conf.Conf, svr)
  90. client, err := rpc.Dial("tcp", addr)
  91. defer client.Close()
  92. if err != nil {
  93. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  94. t.FailNow()
  95. }
  96. assists(client, t)
  97. }
  98. func TestAssistInfo(t *testing.T) {
  99. if err := conf.Init(); err != nil {
  100. t.Errorf("conf.Init() error(%v)", err)
  101. t.FailNow()
  102. }
  103. svr := service.New(conf.Conf)
  104. New(conf.Conf, svr)
  105. client, err := rpc.Dial("tcp", addr)
  106. defer client.Close()
  107. if err != nil {
  108. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  109. t.FailNow()
  110. }
  111. assistInfo(client, t)
  112. }
  113. func TestAddAssist(t *testing.T) {
  114. if err := conf.Init(); err != nil {
  115. t.Errorf("conf.Init() error(%v)", err)
  116. t.FailNow()
  117. }
  118. svr := service.New(conf.Conf)
  119. New(conf.Conf, svr)
  120. client, err := rpc.Dial("tcp", addr)
  121. defer client.Close()
  122. if err != nil {
  123. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  124. t.FailNow()
  125. }
  126. addAssist(client, t)
  127. }
  128. func TestDelAssist(t *testing.T) {
  129. if err := conf.Init(); err != nil {
  130. t.Errorf("conf.Init() error(%v)", err)
  131. t.FailNow()
  132. }
  133. svr := service.New(conf.Conf)
  134. New(conf.Conf, svr)
  135. client, err := rpc.Dial("tcp", addr)
  136. defer client.Close()
  137. if err != nil {
  138. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  139. t.FailNow()
  140. }
  141. delAssist(client, t)
  142. }
  143. func TestAssistLogInfo(t *testing.T) {
  144. if err := conf.Init(); err != nil {
  145. t.Errorf("conf.Init() error(%v)", err)
  146. t.FailNow()
  147. }
  148. svr := service.New(conf.Conf)
  149. New(conf.Conf, svr)
  150. client, err := rpc.Dial("tcp", addr)
  151. defer client.Close()
  152. if err != nil {
  153. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  154. t.FailNow()
  155. }
  156. assistLogInfo(client, t)
  157. }
  158. func TestAssistLogAdd(t *testing.T) {
  159. if err := conf.Init(); err != nil {
  160. t.Errorf("conf.Init() error(%v)", err)
  161. t.FailNow()
  162. }
  163. svr := service.New(conf.Conf)
  164. New(conf.Conf, svr)
  165. client, err := rpc.Dial("tcp", addr)
  166. defer client.Close()
  167. if err != nil {
  168. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  169. t.FailNow()
  170. }
  171. assistLogAdd(client, t)
  172. }
  173. func TestAssistLogCancel(t *testing.T) {
  174. if err := conf.Init(); err != nil {
  175. t.Errorf("conf.Init() error(%v)", err)
  176. t.FailNow()
  177. }
  178. svr := service.New(conf.Conf)
  179. New(conf.Conf, svr)
  180. client, err := rpc.Dial("tcp", addr)
  181. defer client.Close()
  182. if err != nil {
  183. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  184. t.FailNow()
  185. }
  186. assistLogCancel(client, t)
  187. }
  188. func TestAssistLogs(t *testing.T) {
  189. if err := conf.Init(); err != nil {
  190. t.Errorf("conf.Init() error(%v)", err)
  191. t.FailNow()
  192. }
  193. svr := service.New(conf.Conf)
  194. New(conf.Conf, svr)
  195. client, err := rpc.Dial("tcp", addr)
  196. defer client.Close()
  197. if err != nil {
  198. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  199. t.FailNow()
  200. }
  201. assistLogs(client, t)
  202. }
  203. func assistLogCancel(client *rpc.Client, t *testing.T) {
  204. res := new(struct{})
  205. arg := &model.ArgAssistLog{
  206. Mid: 254386,
  207. AssistMid: 2089809,
  208. LogID: 670,
  209. RealIP: "127.0.0.1",
  210. }
  211. err := client.Call(_assistLogCancel, arg, &res)
  212. if err != nil {
  213. t.Logf("err:%v.", err)
  214. }
  215. t.Logf("%+v", res)
  216. }
  217. func assistLogAdd(client *rpc.Client, t *testing.T) {
  218. res := new(struct{})
  219. arg := &model.ArgAssistLogAdd{
  220. Mid: 254386,
  221. AssistMid: 2089809,
  222. Type: model.TypeComment,
  223. Action: model.ActDelete,
  224. SubjectID: 111,
  225. ObjectID: "444",
  226. Detail: "testing",
  227. RealIP: "127.0.0.1",
  228. }
  229. err := client.Call(_assistLogAdd, arg, &res)
  230. if err != nil {
  231. t.Logf("err:%v.", err)
  232. }
  233. t.Logf("%+v", res)
  234. }
  235. func assistInfo(client *rpc.Client, t *testing.T) {
  236. var res = &assist.AssistRes{}
  237. arg := &model.ArgAssist{
  238. Mid: 27515256,
  239. AssistMid: 27515255,
  240. RealIP: "127.0.0.1",
  241. }
  242. err := client.Call(_assist, arg, &res)
  243. if err != nil {
  244. t.Logf("err:%v.", err)
  245. }
  246. t.Logf("%+v", res)
  247. }
  248. func addAssist(client *rpc.Client, t *testing.T) {
  249. assistInfo := new(struct{})
  250. arg := &model.ArgAssist{
  251. Mid: 27515256,
  252. AssistMid: 27515255,
  253. RealIP: "127.0.0.1",
  254. }
  255. err := client.Call(_addAssist, arg, assistInfo)
  256. if err != nil {
  257. t.Logf("err:%v.", err)
  258. }
  259. spew.Dump(assistInfo)
  260. }
  261. func delAssist(client *rpc.Client, t *testing.T) {
  262. assistInfo := new(struct{})
  263. arg := &model.ArgAssist{
  264. Mid: 27515256,
  265. AssistMid: 27515255,
  266. RealIP: "127.0.0.1",
  267. }
  268. err := client.Call(_delAssist, arg, assistInfo)
  269. if err != nil {
  270. t.Logf("err:%v.", err)
  271. }
  272. spew.Dump(assistInfo)
  273. }
  274. func assists(client *rpc.Client, t *testing.T) {
  275. var res = make([]*assist.Assist, 0)
  276. arg := &model.ArgAssists{
  277. Mid: 254386,
  278. RealIP: "127.0.0.1",
  279. }
  280. err := client.Call(_assists, arg, &res)
  281. if err != nil {
  282. t.Logf("err:%v.", err)
  283. }
  284. t.Logf("%+v", res)
  285. spew.Dump(res)
  286. }
  287. func assistLogs(client *rpc.Client, t *testing.T) {
  288. var res = make([]*assist.Log, 0)
  289. arg := &model.ArgAssistLogs{
  290. Mid: 254386,
  291. AssistMid: 2089809,
  292. Stime: time.Unix(1496205563, 0),
  293. Etime: time.Unix(1496291963, 0),
  294. Pn: 1,
  295. Ps: 30,
  296. RealIP: "127.0.0.1",
  297. }
  298. err := client.Call(_assistLogs, arg, &res)
  299. if err != nil {
  300. t.Logf("err:%v.", err)
  301. }
  302. t.Logf("%+v", res)
  303. spew.Dump(res)
  304. }
  305. func assistLogInfo(client *rpc.Client, t *testing.T) {
  306. var res = &assist.Log{}
  307. arg := &model.ArgAssistLog{
  308. Mid: 254386,
  309. AssistMid: 2089809,
  310. LogID: 15,
  311. RealIP: "127.0.0.1",
  312. }
  313. err := client.Call(_assistLogInfo, arg, &res)
  314. if err != nil {
  315. t.Logf("err:%v.", err)
  316. }
  317. t.Logf("%+v", res)
  318. spew.Dump(res)
  319. }