-
Notifications
You must be signed in to change notification settings - Fork 1
/
upgrade_test.go
60 lines (55 loc) · 1.1 KB
/
upgrade_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
// Copyright (c) 2019 Meng Huang ([email protected])
// This package is licensed under a MIT license that can be found in the LICENSE file.
package rpc
import (
"testing"
)
func TestUpgrade(t *testing.T) {
testUpgrade(nil, t)
testUpgrade(make([]byte, 1), t)
}
func testUpgrade(buf []byte, t *testing.T) {
u := &upgrade{
NoRequest: noRequest,
NoResponse: noResponse,
Heartbeat: heartbeat,
Stream: streaming,
}
if u.IsZero() {
t.Error()
}
data, err := u.Marshal(buf)
if err != nil {
t.Error(err)
}
u.Reset()
n, err := u.Unmarshal(data)
if err != nil {
t.Error(err)
}
if n != 1 {
t.Errorf("%d", n)
}
if u.NoRequest != noRequest {
t.Error("NoRequest Unmarshal error")
}
if u.NoResponse != noResponse {
t.Error("NoResponse Unmarshal error")
}
if u.Heartbeat != heartbeat {
t.Error("Heartbeat Unmarshal error")
}
if u.Stream != streaming {
t.Error("Watch Unmarshal error")
}
}
func TestUpgradeUnmarshal(t *testing.T) {
u := &upgrade{}
offset, err := u.Unmarshal(nil)
if offset != 0 {
t.Error(offset)
}
if err == nil {
t.Error("The err should not be nil")
}
}