rpc_test.go 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package server
  2. import (
  3. artmdl "go-common/app/interface/openplatform/article/model"
  4. feed "go-common/app/service/main/feed/model"
  5. "net/rpc"
  6. "testing"
  7. )
  8. const (
  9. addr = "172.16.33.57:6361"
  10. _testArticleFeed = "RPC.ArticleFeed"
  11. )
  12. func TestFeedRpc(t *testing.T) {
  13. client, err := rpc.Dial("tcp", addr)
  14. defer client.Close()
  15. if err != nil {
  16. t.Errorf("rpc.Dial(tcp, \"%s\") error(%v)", addr, err)
  17. t.FailNow()
  18. }
  19. feedRPC(client, t)
  20. }
  21. func feedRPC(client *rpc.Client, t *testing.T) {
  22. arg := &feed.ArgFeed{}
  23. arg.Mid = 88888929
  24. res := &[]*artmdl.Meta{}
  25. if err := client.Call(_testArticleFeed, arg, &res); err != nil {
  26. t.Errorf("client.Call(%s) error(%v)", _testArticleFeed, err)
  27. t.FailNow()
  28. } else {
  29. result("article", t, res)
  30. }
  31. }
  32. func result(name string, t *testing.T, res interface{}) {
  33. t.Log("[==========" + name + "单元测试结果==========]")
  34. t.Log(res)
  35. t.Log("[↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑]\r\n")
  36. }