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

Implement handshake.New()

This commit is contained in:
Jesse Li
2019-12-24 11:05:22 -05:00
parent c20965ebf5
commit 415666a020
3 changed files with 22 additions and 5 deletions

View File

@@ -7,6 +7,18 @@ import (
"github.com/stretchr/testify/assert"
)
func TestNew(t *testing.T) {
infoHash := [20]byte{134, 212, 200, 0, 36, 164, 105, 190, 76, 80, 188, 90, 16, 44, 247, 23, 128, 49, 0, 116}
peerID := [20]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
h := New(infoHash, peerID)
expected := &Handshake{
Pstr: "BitTorrent protocol",
InfoHash: [20]byte{134, 212, 200, 0, 36, 164, 105, 190, 76, 80, 188, 90, 16, 44, 247, 23, 128, 49, 0, 116},
PeerID: [20]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
}
assert.Equal(t, expected, h)
}
func TestSerialize(t *testing.T) {
tests := map[string]struct {
input *Handshake