12 func TestReadUntil(t *testing.T) {
13 test := func(data, until string, leftover int, expectedErr error) {
14 r := bytes.NewReader([]byte(data))
15 err := readUntil(r, []byte(until))
16 if err != expectedErr {
19 if r.Len() != leftover {
23 test("feakjfeafeafegbaabc00", "abc", 2, nil)
24 test("feakjfeafeafegbaadc00", "abc", 0, io.EOF)
27 func TestSuffixMatchLen(t *testing.T) {
28 test := func(a, b string, expected int) {
29 actual := suffixMatchLen([]byte(a), []byte(b))
30 if actual != expected {
31 t.Fatalf("expected %d, got %d for %q and %q", expected, actual, a, b)
34 test("hello", "world", 0)
35 test("hello", "lo", 2)
36 test("hello", "llo", 3)
37 test("hello", "hell", 0)
38 test("hello", "helloooo!", 5)
39 test("hello", "lol!", 2)
40 test("hello", "mondo", 0)
41 test("mongo", "webscale", 0)
42 test("sup", "person", 1)
45 func TestHandshake(t *testing.T) {
47 wg := sync.WaitGroup{}
51 a, err := Handshake(a, true, []byte("yep"))
60 b, err := Handshake(b, false, []byte("yep"))