1
0
mirror of https://github.com/veggiedefender/torrent-client.git synced 2025-11-06 09:29:16 +02:00

Implement parsing and serializing handshake

This commit is contained in:
Jesse Li
2019-12-22 16:03:38 -05:00
parent 5ebabfabcd
commit 4256e5110f
4 changed files with 143 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
)
func TestSerialize(t *testing.T) {
func TestMessageSerialize(t *testing.T) {
tests := map[string]struct {
input *Message
output []byte
@@ -28,13 +28,13 @@ func TestSerialize(t *testing.T) {
}
}
func TestRead(t *testing.T) {
func TestReadMessage(t *testing.T) {
tests := map[string]struct {
input []byte
output *Message
fails bool
}{
"parse normal message intro struct": {
"parse normal message into struct": {
input: []byte{0, 0, 0, 5, 4, 1, 2, 3, 4},
output: &Message{ID: MsgHave, Payload: []byte{1, 2, 3, 4}},
fails: false,
@@ -58,7 +58,7 @@ func TestRead(t *testing.T) {
for _, test := range tests {
reader := bytes.NewReader(test.input)
m, err := Read(reader)
m, err := ReadMessage(reader)
if test.fails {
assert.NotNil(t, err)
} else {
@@ -68,7 +68,7 @@ func TestRead(t *testing.T) {
}
}
func TestString(t *testing.T) {
func TestMessageString(t *testing.T) {
tests := []struct {
input *Message
output string