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

Test buildTrackerURL

This commit is contained in:
Jesse
2019-12-22 22:36:07 -05:00
parent 519d64fa9a
commit 0b46e8444c
2 changed files with 21 additions and 1 deletions

View File

@@ -54,7 +54,7 @@ func (t *Torrent) Download() error {
PieceLength: t.PieceLength,
Length: t.Length,
}
err := downloader.Download()
err = downloader.Download()
return err
}

View File

@@ -8,6 +8,26 @@ import (
"github.com/veggiedefender/torrent-client/p2p"
)
func TestBuildTrackerURL(t *testing.T) {
to := Torrent{
Announce: "http://bttracker.debian.org:6969/announce",
InfoHash: [20]byte{216, 247, 57, 206, 195, 40, 149, 108, 204, 91, 191, 31, 134, 217, 253, 207, 219, 168, 206, 182},
PieceHashes: [][20]byte{
{49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106},
{97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48},
},
PieceLength: 262144,
Length: 351272960,
Name: "debian-10.2.0-amd64-netinst.iso",
}
peerID := [20]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
var port uint16 = 6882
url, err := to.buildTrackerURL(peerID, port)
expected := "http://bttracker.debian.org:6969/announce?compact=1&downloaded=0&info_hash=%D8%F79%CE%C3%28%95l%CC%5B%BF%1F%86%D9%FD%CF%DB%A8%CE%B6&left=351272960&peer_id=%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14&port=6881&uploaded=0"
assert.Nil(t, err)
assert.Equal(t, url, expected)
}
func TestParsePeers(t *testing.T) {
tests := map[string]struct {
input string