subscribe_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package service
  2. import (
  3. "testing"
  4. "time"
  5. "app.yhyue.com/moapp/jybase/mongodb"
  6. )
  7. var MgoT *mongodb.MongodbSim
  8. func init() {
  9. MgoT = &mongodb.MongodbSim{
  10. MongodbAddr: "192.168.3.206:27080",
  11. Size: 10,
  12. DbName: "qfw",
  13. ReplSet: "",
  14. }
  15. MgoT.InitPool()
  16. }
  17. func TestSubseribeService_Update(t *testing.T) {
  18. type fields struct {
  19. Mgo *mongodb.MongodbSim
  20. UserId string
  21. Types string
  22. Area map[string]interface{}
  23. Buyerclass []string
  24. Items []map[string]interface{}
  25. Infotype []string
  26. Matchway string
  27. Projectmatch string
  28. Ratemode string
  29. Apppush string
  30. Mailpush string
  31. Mail string
  32. }
  33. tests := []struct {
  34. name string
  35. fields fields
  36. want int64
  37. wantErr bool
  38. }{
  39. // TODO: Add test cases.
  40. {
  41. name: "无user测试",
  42. fields: fields{
  43. Mgo: MgoT,
  44. UserId: "",
  45. },
  46. },
  47. {
  48. fields: fields{
  49. Mgo: MgoT,
  50. UserId: "6103bb722abfa5f4d81bb1d2",
  51. Area: map[string]interface{}{},
  52. },
  53. },
  54. {
  55. fields: fields{
  56. Mgo: MgoT,
  57. UserId: "6103bb722abfa5f4d81bb1d1",
  58. Area: map[string]interface{}{
  59. "北京": []string{},
  60. },
  61. Items: []map[string]interface{}{
  62. map[string]interface{}{
  63. "s_item": "zxl的分类名称1",
  64. "updatetime": time.Now().Unix(),
  65. "a_key": []map[string]interface{}{
  66. map[string]interface{}{
  67. "key": []string{"你好2"},
  68. "notkey": []string{},
  69. "appendkey": []string{},
  70. "updatetime": time.Now().Unix(),
  71. },
  72. map[string]interface{}{
  73. "key": []string{"你好1"},
  74. "notkey": []string{},
  75. "appendkey": []string{},
  76. "updatetime": time.Now().Unix(),
  77. },
  78. },
  79. },
  80. },
  81. },
  82. },
  83. }
  84. for _, tt := range tests {
  85. t.Run(tt.name, func(t *testing.T) {
  86. this := &SubseribeService{
  87. Mgo: tt.fields.Mgo,
  88. UserId: tt.fields.UserId,
  89. Types: tt.fields.Types,
  90. Area: tt.fields.Area,
  91. Buyerclass: tt.fields.Buyerclass,
  92. Items: tt.fields.Items,
  93. Infotype: tt.fields.Infotype,
  94. Matchway: tt.fields.Matchway,
  95. Projectmatch: tt.fields.Projectmatch,
  96. Ratemode: tt.fields.Ratemode,
  97. Apppush: tt.fields.Apppush,
  98. Mailpush: tt.fields.Mailpush,
  99. Mail: tt.fields.Mail,
  100. }
  101. got, err := this.Update()
  102. if (err != nil) != tt.wantErr {
  103. t.Errorf("Update() error = %v, wantErr %v", err, tt.wantErr)
  104. return
  105. }
  106. if got != tt.want {
  107. t.Errorf("Update() got = %v, want %v", got, tt.want)
  108. }
  109. })
  110. }
  111. }