rpc_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package gorpc
  2. import (
  3. "flag"
  4. "net/rpc"
  5. "testing"
  6. "time"
  7. "go-common/app/service/main/member/conf"
  8. "go-common/app/service/main/member/model"
  9. "go-common/app/service/main/member/service"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. func init() {
  13. flag.Set("conf", "../../cmd/member-service-example.toml")
  14. startService()
  15. }
  16. const (
  17. addr = "127.0.0.1:6689"
  18. _testPing = "RPC.Ping"
  19. )
  20. var (
  21. _noArg = &struct{}{}
  22. svr *service.Service
  23. client *rpc.Client
  24. )
  25. func startService() {
  26. if err := conf.Init(); err != nil {
  27. panic(err)
  28. }
  29. svr = service.New(conf.Conf)
  30. New(conf.Conf, svr)
  31. time.Sleep(time.Second * 3)
  32. var err error
  33. client, err = rpc.Dial("tcp", addr)
  34. if err != nil {
  35. panic(err)
  36. }
  37. }
  38. func TestAccountRpc(t *testing.T) {
  39. Convey("ping", t, func() {
  40. err := client.Call(_testPing, &_noArg, &_noArg)
  41. So(err, ShouldBeNil)
  42. })
  43. }
  44. func TestExp(t *testing.T) {
  45. Convey("update", t, func() {
  46. err := client.Call("RPC.UpdateExp", &model.ArgAddExp{
  47. Mid: 1,
  48. Count: 2,
  49. Reason: "test",
  50. Operate: "other",
  51. IP: "111",
  52. }, &_noArg)
  53. So(err, ShouldBeNil)
  54. })
  55. Convey("exp", t, func() {
  56. res := new(model.LevelInfo)
  57. err := client.Call("RPC.Exp", &model.ArgMid{Mid: 1}, res)
  58. So(err, ShouldBeNil)
  59. So(res.NextExp, ShouldNotEqual, 0)
  60. })
  61. }
  62. func TestLevel(t *testing.T) {
  63. Convey("level", t, func() {
  64. res := new(model.LevelInfo)
  65. err := client.Call("RPC.Level", &model.ArgMid{
  66. Mid: 1,
  67. }, res)
  68. So(err, ShouldNotBeNil)
  69. So(res.NextExp, ShouldNotEqual, 0)
  70. })
  71. }
  72. func TestLog(t *testing.T) {
  73. Convey("log", t, func() {
  74. var res []*model.UserLog
  75. err := client.Call("RPC.Log", &model.ArgMid{Mid: 1}, &res)
  76. So(err, ShouldNotBeNil)
  77. })
  78. }