-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_test.go
70 lines (63 loc) · 1.65 KB
/
user_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
59
60
61
62
63
64
65
66
67
68
69
70
package test
import (
"context"
"log"
"testing"
"github.com/gabivlj/chat-it/internals/domain"
"github.com/gabivlj/chat-it/internals/repository"
)
func BenchmarkFindByIDs(b *testing.B) {
const benchmarkIterations = 1
if b.N > benchmarkIterations {
return
}
userRep, _, _, _ := repository.NewRepository()
defer userRep.Disconnect(context.TODO())
users, err := userRep.FindByIDs(context.TODO(), []string{"5ecff485476916b6cc2d180f", "5ecff4b7fac656a1633f04f7"})
if err != nil {
b.Error(err)
b.FailNow()
}
for _, user := range users {
b.Log(*user)
}
}
func BenchmarkRegister(b *testing.B) {
const benchmarkIterations = 1
if b.N > benchmarkIterations {
return
}
userRep, _, _, _ := repository.NewRepository()
defer userRep.Disconnect(context.TODO())
user, _, err := userRep.SaveUser(context.TODO(), &domain.User{Username: "gabivlj053", Password: "123456"})
if err != nil {
b.Error(err)
b.FailNow()
}
b.Log(user)
}
func BenchmarkUserLog(b *testing.B) {
userRep, _, _, _ := repository.NewRepository()
defer userRep.Disconnect(context.TODO())
user, err := userRep.FindByID(context.TODO(), "5ecff485476916b6cc2d180f")
if err != nil {
b.Error(err)
b.FailNow()
}
if user.ID != "5ecff485476916b6cc2d180f" {
b.Errorf("ERROR, ids don't match")
b.FailNow()
}
b.Log(user)
}
func BenchmarkUserLogIn(b *testing.B) {
userRep, _, _, _ := repository.NewRepository()
defer userRep.Disconnect(context.TODO())
user, session, err := userRep.LogUser(context.TODO(), &domain.User{Password: "123456", Username: "gabivlj02"})
if err != nil {
b.Error(err)
b.FailNow()
}
us, err := userRep.VerifySession(session)
log.Println(user, session, us, err)
}