forked from LevInteractive/dwarf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers_test.go
53 lines (45 loc) · 899 Bytes
/
handlers_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
package main
import (
"context"
"log"
"testing"
"github.com/LevInteractive/dwarf/pb"
"github.com/LevInteractive/dwarf/storage"
"github.com/go-redis/redis"
)
func TestGRPCCreate(t *testing.T) {
store := storage.Redis{
CharFloor: 2,
Conn: &redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 2,
},
}
store.Init()
server := &CreateServer{
Store: store,
}
tests := []struct {
req *pb.CreateRequest
value int
}{
{
req: &pb.CreateRequest{Urls: []string{"http://hello.com"}},
value: 1,
},
{
req: &pb.CreateRequest{Urls: []string{"http://a.com", "http://foo.com"}},
value: 2,
},
}
for _, tt := range tests {
resp, err := server.Create(context.Background(), tt.req)
if err != nil {
log.Fatal(err)
}
if len(resp.Urls) != tt.value {
t.Fatalf("Length of response should be 1. Got %v", len(tt.req.Urls))
}
}
}