| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package protocol
- import (
- "bytes"
- "testing"
- )
- var (
- fetchRequestNoBlocks = []byte{
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00}
- fetchRequestWithProperties = []byte{
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xEF,
- 0x00, 0x00, 0x00, 0x00}
- fetchRequestOneBlock = []byte{
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x05, 't', 'o', 'p', 'i', 'c',
- 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x56}
- )
- func testEncodable(t *testing.T, name string, in encoder, result []byte) {
- packet, err := encode(in)
- if err != nil {
- t.Error(err)
- }
- if !bytes.Equal(packet, result) {
- t.Error("Encoding", name, "failed\ngot ", packet, "\nwant", result)
- }
- }
- func TestFetchRequestEncoding(t *testing.T) {
- request := new(FetchRequest)
- testEncodable(t, "no blocks", request, fetchRequestNoBlocks)
- request.MaxWaitTime = 0x20
- request.MinBytes = 0xEF
- testEncodable(t, "with properties", request, fetchRequestWithProperties)
- request.MaxWaitTime = 0
- request.MinBytes = 0
- request.AddBlock("topic", 0x12, 0x34, 0x56)
- testEncodable(t, "one block", request, fetchRequestOneBlock)
- }
|