forked from docker-archive/go-redis-server
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhandler_test.go
More file actions
37 lines (34 loc) · 802 Bytes
/
Copy pathhandler_test.go
File metadata and controls
37 lines (34 loc) · 802 Bytes
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
package redis
import (
"strings"
"testing"
)
func TestEmptyHandler(t *testing.T) {
c := make(chan struct{})
defer close(c)
srv := &Server{}
reply, err := srv.ApplyString(&Request{})
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
if !strings.Contains(reply, "-ERROR") {
t.Fatalf("Eexpected error reply, got: %s", err)
}
}
func TestCustomHandler(t *testing.T) {
srv, err := NewServer(DefaultConfig())
if err != nil {
t.Fatal(err)
}
srv.Register("GET", func(r *Request) (ReplyWriter, error) {
return &BulkReply{value: []byte("42")}, nil
})
reply, err := srv.ApplyString(&Request{Name: "gEt"})
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
expected := "$2\r\n42\r\n"
if reply != expected {
t.Fatalf("Eexpected reply %q, got: %q", expected, reply)
}
}