rpc_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package gorpc
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/interface/main/history/model"
  6. rpcClient "go-common/app/interface/main/history/rpc/client"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. var (
  10. ctx = context.TODO()
  11. client *rpcClient.Service
  12. )
  13. func WithRPC(f func(client *rpcClient.Service)) func() {
  14. return func() {
  15. client = rpcClient.New(nil)
  16. f(client)
  17. }
  18. }
  19. func Test_Histroy_rpc(t *testing.T) {
  20. Convey("rpc client Add", t, WithRPC(func(client *rpcClient.Service) {
  21. arg := &model.ArgHistory{
  22. Mid: 14771787,
  23. History: &model.History{
  24. Aid: 17406762,
  25. TP: 1,
  26. Pro: 122,
  27. },
  28. }
  29. client.Add(ctx, arg)
  30. }))
  31. Convey("rpc client preogress", t, WithRPC(func(client *rpcClient.Service) {
  32. arg := &model.ArgPro{
  33. Mid: 14771787,
  34. Aids: []int64{17406762},
  35. }
  36. client.Progress(ctx, arg)
  37. }))
  38. Convey("rpc client delete", t, WithRPC(func(client *rpcClient.Service) {
  39. r := &model.Resource{Oid: 100, Business: "archive"}
  40. arg := &model.ArgDelete{
  41. Mid: 14771787,
  42. Resources: []*model.Resource{r},
  43. }
  44. client.Delete(ctx, arg)
  45. }))
  46. Convey("rpc client history", t, WithRPC(func(client *rpcClient.Service) {
  47. arg := &model.ArgHistories{Mid: 14771787}
  48. client.History(ctx, arg)
  49. }))
  50. }