knowledge_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package test
  2. import (
  3. "context"
  4. "flag"
  5. "github.com/zeromicro/go-zero/core/conf"
  6. "github.com/zeromicro/go-zero/zrpc"
  7. "knowledgeBase/rpc/knowledge/internal/config"
  8. "knowledgeBase/rpc/knowledge/knowledgeclient"
  9. "log"
  10. "testing"
  11. "time"
  12. )
  13. var configFile = flag.String("f", "../etc/knowledge.yaml", "the config file")
  14. var c config.Config
  15. func init() {
  16. conf.MustLoad(*configFile, &c)
  17. }
  18. func Test_KnowledgeAdd(t *testing.T) {
  19. ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
  20. TestSystem := knowledgeclient.NewKnowledge(zrpc.MustNewClient(c.TestConf))
  21. req := &knowledgeclient.AddRequest{}
  22. req.AppId = "10000"
  23. req.TenantId = "10000"
  24. req.Question = "超级订阅在哪设置订阅提醒,超级订阅用户有哪些权益?"
  25. req.Answer = "超级订阅用户权益有订阅设置。"
  26. req.Person = "王三"
  27. res, err := TestSystem.KnowledgeAdd(ctx, req)
  28. log.Println("res ", res)
  29. log.Println("err ", err)
  30. }
  31. func Test_KnowledgeList(t *testing.T) {
  32. ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
  33. TestSystem := knowledgeclient.NewKnowledge(zrpc.MustNewClient(c.TestConf))
  34. req := &knowledgeclient.ListRequest{}
  35. req.TenantId = 10000
  36. req.PageSize = 10
  37. req.PageIndex = 1
  38. res, err := TestSystem.KnowledgeList(ctx, req)
  39. log.Println("res ", res)
  40. log.Println("err ", err)
  41. }
  42. func Test_KnowledgeInfo(t *testing.T) {
  43. ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
  44. TestSystem := knowledgeclient.NewKnowledge(zrpc.MustNewClient(c.TestConf))
  45. req := &knowledgeclient.KnowledgeEntity{}
  46. req.AnswerId = 23
  47. res, err := TestSystem.KnowledgeInfo(ctx, req)
  48. log.Println("res ", res)
  49. log.Println("err ", err)
  50. }
  51. func Test_KnowledgeEdit(t *testing.T) {
  52. ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
  53. TestSystem := knowledgeclient.NewKnowledge(zrpc.MustNewClient(c.TestConf))
  54. req := &knowledgeclient.KnowledgeEditReq{}
  55. req.AnswerId = 23
  56. req.KnowledgeId = 1
  57. req.TenantId = 10000
  58. req.Question = "大会员权益有哪些,如何购买?"
  59. req.Answer = "大会员有超级多的权益,好处多多,在剑鱼网站直接购买。"
  60. res, err := TestSystem.KnowledgeEdit(ctx, req)
  61. log.Println("res ", res)
  62. log.Println("err ", err)
  63. }