ut_metadata/test/basic.js

32 lines
841 B
JavaScript
Raw Normal View History

2016-02-05 22:32:52 +00:00
var bencode = require('bencode')
2016-03-16 19:33:57 +00:00
var fixtures = require('webtorrent-fixtures')
2014-03-23 03:34:50 +00:00
var Protocol = require('bittorrent-protocol')
var test = require('tape')
2016-04-24 09:32:47 +01:00
var utMetadata = require('../')
2014-03-23 03:34:50 +00:00
2016-04-24 09:32:47 +01:00
test('wire.use(utMetadata())', function (t) {
2014-03-23 03:34:50 +00:00
var wire = new Protocol()
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()
})
2016-04-24 09:32:47 +01:00
test('wire.use(utMetadata(metadata))', function (t) {
2014-03-23 03:34:50 +00:00
var wire = new Protocol()
wire.pipe(wire)
2016-04-24 09:32:47 +01:00
wire.use(utMetadata(fixtures.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)
2016-03-16 19:33:57 +00:00
t.equal(wire.ut_metadata.metadata.toString('hex'), bencode.encode(bencode.decode(fixtures.leavesMetadata.torrent).info).toString('hex'))
2014-03-23 03:34:50 +00:00
t.end()
})