-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathheartbeat_test.go
30 lines (23 loc) · 1.12 KB
/
heartbeat_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
package client
import "testing"
var emptyHeartbeatRequestBytes = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
var goodHeartbeatRequestBytes = []byte{0x00, 0x05, 'g', 'r', 'o', 'u', 'p', 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'm', 'e', 'm', 'b', 'e', 'r'}
var errorHeartbeatResponseBytes = []byte{0x00, 25}
var goodHeartbeatResponseBytes = []byte{0x00, 0x00}
func TestHeartbeatRequest(t *testing.T) {
emptyHeartbeatRequest := new(HeartbeatRequest)
testRequest(t, emptyHeartbeatRequest, emptyHeartbeatRequestBytes)
goodHeartbeatRequest := new(HeartbeatRequest)
goodHeartbeatRequest.GroupID = "group"
goodHeartbeatRequest.GenerationID = 3
goodHeartbeatRequest.MemberID = "member"
testRequest(t, goodHeartbeatRequest, goodHeartbeatRequestBytes)
}
func TestHeartbeatResponse(t *testing.T) {
errorHeartbeatResponse := new(HeartbeatResponse)
decode(t, errorHeartbeatResponse, errorHeartbeatResponseBytes)
assert(t, errorHeartbeatResponse.Error, ErrUnknownMemberID)
goodHeartbeatResponse := new(HeartbeatResponse)
decode(t, goodHeartbeatResponse, goodHeartbeatResponseBytes)
assert(t, goodHeartbeatResponse.Error, ErrNoError)
}