Пример #1
0
func TestChunkingProducesCorrectChunks(t *testing.T) {
	c := control.NewChunker()
	ctrl := &control.Acknowledgement{5}

	out, err := c.Chunk(ctrl)

	assert.Nil(t, err)
	assert.IsType(t, &chunk.Chunk{}, out)

	assert.EqualValues(t, 0, out.Header.BasicHeader.FormatId)
	assert.EqualValues(t, control.ControlChunkStreamId,
		out.Header.BasicHeader.StreamId)

	assert.EqualValues(t, 0, out.Header.MessageHeader.FormatId)
	assert.EqualValues(t, 4, out.Header.MessageHeader.Length)
	assert.EqualValues(t, ctrl.TypeId(), out.Header.MessageHeader.TypeId)
	assert.EqualValues(t, control.ControlMessageStreamId,
		out.Header.MessageHeader.StreamId)

	assert.Equal(t, []byte{
		0, 0, 0, 5,
	}, out.Data)
}
Пример #2
0
// New instantiates and returns a pointer to a new instance of type Client. The
// client is initialized with the given connection.
func New(conn io.ReadWriter) *Client {
	chunkWriter := chunk.NewWriter(conn, 4096)
	chunks := chunk.NewParser(chunk.NewReader(
		conn, chunk.DefaultReadSize, chunk.NewNormalizer(),
	))

	controlChunks, _ := chunks.Stream(2)
	netChunks, _ := chunks.Stream(3, 4, 5, 8)

	return &Client{
		chunks: chunks,

		controlStream: control.NewStream(
			controlChunks,
			chunkWriter,
			control.NewParser(),
			control.NewChunker(),
		),

		cmdManager: cmd.New(netChunks, chunkWriter),

		Conn: conn,
	}
}
Пример #3
0
func TestChunkerConstruction(t *testing.T) {
	c := control.NewChunker()

	assert.IsType(t, &control.DefaultChunker{}, c)
}