Skip to content

Commit

Permalink
test: Add BitTorrent v2 test torrents
Browse files Browse the repository at this point in the history
  • Loading branch information
jhermsmeier committed Dec 13, 2020
1 parent b7246d2 commit a733975
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Binary file added test/data/bittorrent-v2-hybrid-test.torrent
Binary file not shown.
Binary file added test/data/bittorrent-v2-test.torrent
Binary file not shown.
36 changes: 36 additions & 0 deletions test/torrents.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var bencode = require('..')
var test = require('tape').test
var fs = require('fs')
var path = require('path')

var files = {
test: fs.readFileSync(path.join(__dirname, 'data', 'test.torrent')),
bittorrent2: fs.readFileSync(path.join(__dirname, 'data', 'bittorrent-v2-test.torrent')),
bittorrent2Hybrid: fs.readFileSync(path.join(__dirname, 'data', 'bittorrent-v2-hybrid-test.torrent'))
}

test('Torrent test files', function (t) {
t.test('should decode & encode `test.torrent` file', function (t) {
t.plan(2)
var decoded = bencode.decode(files.test)
var encoded = bencode.encode(decoded)
t.equal(encoded.length, files.test.length)
t.deepEqual(encoded, files.test)
})

t.test('should decode & encode `bittorrent-v2-test.torrent` file', function (t) {
t.plan(2)
var decoded = bencode.decode(files.bittorrent2)
var encoded = bencode.encode(decoded)
t.equal(encoded.length, files.bittorrent2.length)
t.deepEqual(encoded, files.bittorrent2)
})

t.test('should decode & encode `bittorrent-v2-hybrid-test.torrent` file', function (t) {
t.plan(2)
var decoded = bencode.decode(files.bittorrent2Hybrid)
var encoded = bencode.encode(decoded)
t.equal(encoded.length, files.bittorrent2Hybrid.length)
t.deepEqual(encoded, files.bittorrent2Hybrid)
})
})

0 comments on commit a733975

Please sign in to comment.