forked from alicebob/miniredis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_test.go
37 lines (34 loc) · 963 Bytes
/
stream_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
package miniredis
import (
"testing"
)
func TestStreamID(t *testing.T) {
test := func(a, b string, want int) {
if have := streamCmp(a, b); have != want {
t.Errorf("cmp(%q, %q) have %d, want %d", a, b, have, want)
}
}
test("1-1", "2-1", -1)
test("1-1", "1-1", 0)
test("1-1", "0-1", 1)
test("1-1", "1-2", -1)
test("1-1", "1-1", 0)
test("1-1", "1-0", 1)
}
func TestFormatStreamID(t *testing.T) {
if have, _ := formatStreamID("1-1"); have != "1-1" {
t.Errorf("have %q, want %q", have, "1-1")
}
if have, _ := formatStreamID("1"); have != "1-0" {
t.Errorf("have %q, want %q", have, "1-0")
}
if have, _ := formatStreamID("1-002"); have != "1-2" {
t.Errorf("have %q, want %q", have, "1-2")
}
if _, err := formatStreamID("1-foo"); err != errInvalidEntryID {
t.Errorf("have %s, want %s", err, errInvalidEntryID)
}
if _, err := formatStreamID("foo"); err != errInvalidEntryID {
t.Errorf("have %s, want %s", err, errInvalidEntryID)
}
}