123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package service
- import (
- "testing"
- "time"
- "app.yhyue.com/moapp/jybase/mongodb"
- )
- var MgoT *mongodb.MongodbSim
- func init() {
- MgoT = &mongodb.MongodbSim{
- MongodbAddr: "192.168.3.206:27080",
- Size: 10,
- DbName: "qfw",
- ReplSet: "",
- }
- MgoT.InitPool()
- }
- func TestSubseribeService_Update(t *testing.T) {
- type fields struct {
- Mgo *mongodb.MongodbSim
- UserId string
- Types string
- Area map[string]interface{}
- Buyerclass []string
- Items []map[string]interface{}
- Infotype []string
- Matchway string
- Projectmatch string
- Ratemode string
- Apppush string
- Mailpush string
- Mail string
- }
- tests := []struct {
- name string
- fields fields
- want int64
- wantErr bool
- }{
- // TODO: Add test cases.
- {
- name: "无user测试",
- fields: fields{
- Mgo: MgoT,
- UserId: "",
- },
- },
- {
- fields: fields{
- Mgo: MgoT,
- UserId: "6103bb722abfa5f4d81bb1d2",
- Area: map[string]interface{}{},
- },
- },
- {
- fields: fields{
- Mgo: MgoT,
- UserId: "6103bb722abfa5f4d81bb1d1",
- Area: map[string]interface{}{
- "北京": []string{},
- },
- Items: []map[string]interface{}{
- map[string]interface{}{
- "s_item": "zxl的分类名称1",
- "updatetime": time.Now().Unix(),
- "a_key": []map[string]interface{}{
- map[string]interface{}{
- "key": []string{"你好2"},
- "notkey": []string{},
- "appendkey": []string{},
- "updatetime": time.Now().Unix(),
- },
- map[string]interface{}{
- "key": []string{"你好1"},
- "notkey": []string{},
- "appendkey": []string{},
- "updatetime": time.Now().Unix(),
- },
- },
- },
- },
- },
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- this := &SubseribeService{
- Mgo: *MgoT,
- UserId: tt.fields.UserId,
- Types: tt.fields.Types,
- Area: tt.fields.Area,
- Buyerclass: tt.fields.Buyerclass,
- Items: tt.fields.Items,
- Infotype: tt.fields.Infotype,
- Matchway: tt.fields.Matchway,
- Projectmatch: tt.fields.Projectmatch,
- Ratemode: tt.fields.Ratemode,
- Apppush: tt.fields.Apppush,
- Mailpush: tt.fields.Mailpush,
- Mail: tt.fields.Mail,
- }
- got, err := this.Update()
- if (err != nil) != tt.wantErr {
- t.Errorf("Update() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if got != tt.want {
- t.Errorf("Update() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
|