2018-08-28 18:34:08 +01:00
|
|
|
const { leavesMetadata } = require('webtorrent-fixtures')
|
|
|
|
const bencode = require('bencode')
|
|
|
|
const Protocol = require('bittorrent-protocol')
|
|
|
|
const test = require('tape')
|
|
|
|
const utMetadata = require('../')
|
2014-03-23 03:34:50 +00:00
|
|
|
|
2018-08-28 18:34:08 +01:00
|
|
|
test('wire.use(utMetadata())', t => {
|
|
|
|
const wire = new Protocol()
|
2014-03-23 03:34:50 +00:00
|
|
|
wire.pipe(wire)
|
|
|
|
|
2016-04-24 09:32:47 +01:00
|
|
|
wire.use(utMetadata())
|
2014-03-23 03:34:50 +00:00
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
2018-08-28 18:34:08 +01:00
|
|
|
test('wire.use(utMetadata(metadata))', t => {
|
|
|
|
const wire = new Protocol()
|
2014-03-23 03:34:50 +00:00
|
|
|
wire.pipe(wire)
|
|
|
|
|
2018-08-28 18:34:08 +01:00
|
|
|
wire.use(utMetadata(leavesMetadata.torrent))
|
2014-03-23 03:34:50 +00:00
|
|
|
|
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)
|
2018-08-28 18:34:08 +01:00
|
|
|
t.equal(
|
|
|
|
wire.ut_metadata.metadata.toString('hex'),
|
|
|
|
bencode.encode(bencode.decode(leavesMetadata.torrent).info).toString('hex')
|
|
|
|
)
|
2014-03-23 03:34:50 +00:00
|
|
|
t.end()
|
|
|
|
})
|