portrait_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package service
  2. import (
  3. "reflect"
  4. "testing"
  5. elastic "app.yhyue.com/moapp/jybase/esv1"
  6. "app.yhyue.com/moapp/jybase/mysql"
  7. "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
  8. )
  9. var PortService PortraitService
  10. var MyConn *entity.Conn
  11. func init() {
  12. entity.Mysql = &mysql.Mysql{
  13. Address: "192.168.3.217:4000",
  14. UserName: "root",
  15. PassWord: "=PDT49#80Z!RVv52_z",
  16. DBName: "medical_fileld_data",
  17. MaxOpenConns: 5,
  18. MaxIdleConns: 5,
  19. }
  20. entity.Mysql.Init()
  21. BaseMysqlConn := &mysql.Mysql{
  22. Address: "192.168.3.217:4000",
  23. UserName: "root",
  24. PassWord: "=PDT49#80Z!RVv52_z",
  25. DBName: "base_service",
  26. MaxOpenConns: 5,
  27. MaxIdleConns: 5,
  28. }
  29. BaseMysqlConn.Init()
  30. CommonMysql := &mysql.Mysql{
  31. Address: "192.168.3.217:4000",
  32. UserName: "root",
  33. PassWord: "=PDT49#80Z!RVv52_z",
  34. DBName: "global_common_data",
  35. MaxOpenConns: 5,
  36. MaxIdleConns: 5,
  37. }
  38. CommonMysql.Init()
  39. MyConn = &entity.Conn{
  40. Mysql: entity.Mysql,
  41. BaseMysql: BaseMysqlConn,
  42. CommonMysql: CommonMysql,
  43. }
  44. elastic.InitElasticSize("http://192.168.3.206:9800", 30)
  45. PortService = *NewPortrait(MyConn)
  46. }
  47. func TestPortraitService_Info(t *testing.T) {
  48. type fields struct {
  49. Conn *entity.Conn
  50. }
  51. type args struct {
  52. companyId string
  53. }
  54. tests := []struct {
  55. name string
  56. fields fields
  57. args args
  58. want *entity.PortraitInfo
  59. wantErr bool
  60. }{
  61. // TODO: Add test cases.
  62. {
  63. name: "查询画像",
  64. fields: fields{
  65. Conn: MyConn,
  66. },
  67. args: args{
  68. companyId: "25caa43ce64036dfd1f55635e06394a6",
  69. },
  70. },
  71. {
  72. name: "无参数查看画像",
  73. fields: fields{
  74. Conn: MyConn,
  75. },
  76. args: args{
  77. companyId: "",
  78. },
  79. },
  80. {
  81. name: "错误参数查看画像",
  82. fields: fields{
  83. Conn: MyConn,
  84. },
  85. args: args{
  86. companyId: "错的",
  87. },
  88. },
  89. }
  90. for _, tt := range tests {
  91. t.Run(tt.name, func(t *testing.T) {
  92. this := &PortraitService{
  93. Conn: tt.fields.Conn,
  94. }
  95. got, err := this.Info(tt.args.companyId)
  96. if (err != nil) != tt.wantErr {
  97. t.Errorf("Info() error = %v, wantErr %v", err, tt.wantErr)
  98. return
  99. }
  100. if !reflect.DeepEqual(got, tt.want) {
  101. t.Errorf("Info() got = %v, want %v", got, tt.want)
  102. }
  103. })
  104. }
  105. }
  106. func TestPortraitService_List(t *testing.T) {
  107. type fields struct {
  108. Conn *entity.Conn
  109. }
  110. type args struct {
  111. companyId string
  112. pagesize int64
  113. pagenum int64
  114. }
  115. tests := []struct {
  116. name string
  117. fields fields
  118. args args
  119. want *entity.PortraitInfo
  120. wantErr bool
  121. }{
  122. // TODO: Add test cases.
  123. {
  124. name: "招标动态",
  125. fields: fields{
  126. Conn: MyConn,
  127. },
  128. args: args{
  129. companyId: "张家港市凤凰镇人民政府",
  130. pagesize: 5,
  131. pagenum: 1,
  132. },
  133. },
  134. }
  135. for _, tt := range tests {
  136. t.Run(tt.name, func(t *testing.T) {
  137. this := &PortraitService{
  138. Conn: tt.fields.Conn,
  139. }
  140. got, _, err := this.List(tt.args.companyId, tt.args.pagesize, tt.args.pagenum)
  141. if (err != nil) != tt.wantErr {
  142. t.Errorf("Info() error = %v, wantErr %v", err, tt.wantErr)
  143. return
  144. }
  145. if !reflect.DeepEqual(got, tt.want) {
  146. t.Errorf("Info() got = %v, want %v", got, tt.want)
  147. }
  148. })
  149. }
  150. }