-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
58 lines (55 loc) · 1.35 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"reflect"
"testing"
"time"
"github.com/Monkey-Mouse/mo2log/logmodel"
"github.com/Monkey-Mouse/mo2log/service/logservice"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func Test_server_Count(t *testing.T) {
type args struct {
ctx context.Context
u *logservice.UserID
}
now := time.Now()
id := primitive.NewObjectID()
col.InsertMany(context.TODO(), []interface{}{
logmodel.LogModel{
OperatorID: id,
CreateTime: now,
},
logmodel.LogModel{
OperatorID: id,
CreateTime: now.AddDate(0, 0, -2),
},
logmodel.LogModel{
OperatorID: id,
CreateTime: now.Add(-time.Hour),
},
})
tests := []struct {
name string
s *server
args args
wantNum *logservice.Num
wantErr bool
}{
{name: "Test count", s: &server{}, args: args{context.TODO(), &logservice.UserID{UserId: id[:]}}, wantNum: &logservice.Num{Num: 2}, wantErr: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotNum, err := tt.s.Count(tt.args.ctx, tt.args.u)
if (err != nil) != tt.wantErr {
t.Errorf("server.Count() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(gotNum, tt.wantNum) {
t.Errorf("server.Count() = %v, want %v", gotNum, tt.wantNum)
}
})
}
col.DeleteMany(context.TODO(), bson.M{"operator_id": id})
}