2014-03-23 03:34:50 +00:00
|
|
|
var fs = require('fs')
|
|
|
|
var Protocol = require('bittorrent-protocol')
|
|
|
|
var ut_metadata = require('../')
|
2014-06-12 01:56:20 +01:00
|
|
|
var bencode = require('bencode')
|
2014-03-23 03:34:50 +00:00
|
|
|
var test = require('tape')
|
|
|
|
|
|
|
|
// Used in multiple tests
|
|
|
|
var metadata = fs.readFileSync(__dirname + '/torrents/leaves-magnet.torrent')
|
|
|
|
|
|
|
|
test('wire.use(ut_metadata())', function (t) {
|
|
|
|
var wire = new Protocol()
|
|
|
|
wire.pipe(wire)
|
|
|
|
|
|
|
|
wire.use(ut_metadata())
|
|
|
|
|
2014-03-26 09:03:13 +00:00
|
|
|
t.ok(wire.ut_metadata)
|
|
|
|
t.ok(wire.ut_metadata.fetch)
|
|
|
|
t.ok(wire.ut_metadata.cancel)
|
|
|
|
t.notOk(wire.ut_metadata.metadata)
|
2014-03-23 03:34:50 +00:00
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('wire.use(ut_metadata(metadata))', function (t) {
|
|
|
|
var wire = new Protocol()
|
|
|
|
wire.pipe(wire)
|
|
|
|
|
|
|
|
wire.use(ut_metadata(metadata))
|
|
|
|
|
2014-03-26 09:03:13 +00:00
|
|
|
t.ok(wire.ut_metadata)
|
|
|
|
t.ok(wire.ut_metadata.fetch)
|
|
|
|
t.ok(wire.ut_metadata.cancel)
|
2014-06-12 01:56:20 +01:00
|
|
|
t.equal(wire.ut_metadata.metadata.toString('hex'), bencode.encode(bencode.decode(metadata).info).toString('hex'))
|
2014-03-23 03:34:50 +00:00
|
|
|
t.end()
|
|
|
|
})
|