Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-01-04 06:59:28 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-01-04 06:59:28 +0300
commit09e345eb12f30f73e9492c7a6921a4442226e38e (patch)
tree9d72c741274fc34547eb2f7143ebba8f83a4fef9
parent8b36f9d607c4acf3b439278b5a6e1e8b72be6eb9 (diff)
test: verify file content in download tests
-rw-r--r--test/download-dht-magnet.js12
-rw-r--r--test/download-dht-torrent.js12
-rw-r--r--test/download-tracker-magnet.js12
-rw-r--r--test/download-tracker-torrent.js12
-rw-r--r--test/server.js22
5 files changed, 41 insertions, 29 deletions
diff --git a/test/download-dht-magnet.js b/test/download-dht-magnet.js
index 1a0b3bc..639f485 100644
--- a/test/download-dht-magnet.js
+++ b/test/download-dht-magnet.js
@@ -5,7 +5,8 @@ var parseTorrent = require('parse-torrent')
var test = require('tape')
var WebTorrent = require('../')
-var leavesFile = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
+var leavesPath = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
+var leavesFile = fs.readFileSync(leavesPath)
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesParsed = parseTorrent(leavesTorrent)
@@ -14,7 +15,7 @@ leavesParsed.announce = []
leavesParsed.announceList = []
test('Download using DHT (via magnet uri)', function (t) {
- t.plan(7)
+ t.plan(8)
var dhtServer = new DHT({ bootstrap: false })
dhtServer.on('error', function (err) {
@@ -55,7 +56,7 @@ test('Download using DHT (via magnet uri)', function (t) {
maybeDone(null)
})
- torrent.storage.load(fs.createReadStream(leavesFile), function (err) {
+ torrent.storage.load(fs.createReadStream(leavesPath), function (err) {
wroteStorage = true
maybeDone(err)
})
@@ -73,7 +74,10 @@ test('Download using DHT (via magnet uri)', function (t) {
client2.on('torrent', function (torrent) {
torrent.files.forEach(function (file) {
- file.createReadStream()
+ file.getBuffer(function (err, buf) {
+ if (err) throw err
+ t.deepEqual(buf, leavesFile, 'downloaded correct content')
+ })
})
torrent.once('done', function () {
diff --git a/test/download-dht-torrent.js b/test/download-dht-torrent.js
index 19b998e..0e38512 100644
--- a/test/download-dht-torrent.js
+++ b/test/download-dht-torrent.js
@@ -5,7 +5,8 @@ var fs = require('fs')
var parseTorrent = require('parse-torrent')
var test = require('tape')
-var leavesFile = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
+var leavesPath = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
+var leavesFile = fs.readFileSync(leavesPath)
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesParsed = parseTorrent(leavesTorrent)
@@ -14,7 +15,7 @@ leavesParsed.announce = []
leavesParsed.announceList = []
test('Download using DHT (via .torrent file)', function (t) {
- t.plan(7)
+ t.plan(8)
var dhtServer = new DHT({ bootstrap: false })
@@ -54,7 +55,7 @@ test('Download using DHT (via .torrent file)', function (t) {
maybeDone(null)
})
- torrent.storage.load(fs.createReadStream(leavesFile), function (err) {
+ torrent.storage.load(fs.createReadStream(leavesPath), function (err) {
wroteStorage = true
maybeDone(err)
})
@@ -72,7 +73,10 @@ test('Download using DHT (via .torrent file)', function (t) {
client2.on('torrent', function (torrent) {
torrent.files.forEach(function (file) {
- file.createReadStream()
+ file.getBuffer(function (err, buf) {
+ if (err) throw err
+ t.deepEqual(buf, leavesFile, 'downloaded correct content')
+ })
})
torrent.once('done', function () {
diff --git a/test/download-tracker-magnet.js b/test/download-tracker-magnet.js
index 8d44abc..4564a3a 100644
--- a/test/download-tracker-magnet.js
+++ b/test/download-tracker-magnet.js
@@ -5,7 +5,8 @@ var test = require('tape')
var TrackerServer = require('bittorrent-tracker/server')
var WebTorrent = require('../')
-var leavesFile = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
+var leavesPath = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
+var leavesFile = fs.readFileSync(leavesPath)
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesParsed = parseTorrent(leavesTorrent)
@@ -18,7 +19,7 @@ test('Download using HTTP tracker (via magnet uri)', function (t) {
})
function magnetDownloadTest (t, serverType) {
- t.plan(8)
+ t.plan(9)
var trackerStartCount = 0
var magnetUri
@@ -65,7 +66,7 @@ function magnetDownloadTest (t, serverType) {
t.deepEqual(torrent.files.map(function (file) { return file.name }), names)
- torrent.storage.load(fs.createReadStream(leavesFile), function (err) {
+ torrent.storage.load(fs.createReadStream(leavesPath), function (err) {
cb(err, client1)
})
})
@@ -79,7 +80,10 @@ function magnetDownloadTest (t, serverType) {
client2.on('torrent', function (torrent) {
torrent.files.forEach(function (file) {
- file.createReadStream()
+ file.getBuffer(function (err, buf) {
+ if (err) throw err
+ t.deepEqual(buf, leavesFile, 'downloaded correct content')
+ })
})
torrent.once('done', function () {
diff --git a/test/download-tracker-torrent.js b/test/download-tracker-torrent.js
index 0838b0b..f0ecf03 100644
--- a/test/download-tracker-torrent.js
+++ b/test/download-tracker-torrent.js
@@ -5,7 +5,8 @@ var test = require('tape')
var TrackerServer = require('bittorrent-tracker/server')
var WebTorrent = require('../')
-var leavesFile = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
+var leavesPath = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
+var leavesFile = fs.readFileSync(leavesPath)
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesParsed = parseTorrent(leavesTorrent)
@@ -18,7 +19,7 @@ test('Download using HTTP tracker (via .torrent file)', function (t) {
})
function torrentDownloadTest (t, serverType) {
- t.plan(8)
+ t.plan(9)
var trackerStartCount = 0
@@ -65,7 +66,7 @@ function torrentDownloadTest (t, serverType) {
t.deepEqual(torrent.files.map(function (file) { return file.name }), names)
- torrent.storage.load(fs.createReadStream(leavesFile), function (err) {
+ torrent.storage.load(fs.createReadStream(leavesPath), function (err) {
cb(err, client1)
})
})
@@ -79,7 +80,10 @@ function torrentDownloadTest (t, serverType) {
client2.on('torrent', function (torrent) {
torrent.files.forEach(function (file) {
- file.createReadStream()
+ file.getBuffer(function (err, buf) {
+ if (err) throw err
+ t.deepEqual(buf, leavesFile, 'downloaded correct content')
+ })
})
torrent.once('done', function () {
diff --git a/test/server.js b/test/server.js
index f00c22b..f8b2722 100644
--- a/test/server.js
+++ b/test/server.js
@@ -1,11 +1,10 @@
-var concat = require('concat-stream')
+var get = require('simple-get')
var fs = require('fs')
-var http = require('http')
var portfinder = require('portfinder')
var test = require('tape')
var WebTorrent = require('../')
-var leavesFile = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
+var leavesPath = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
test('start http server programmatically', function (t) {
@@ -18,20 +17,17 @@ test('start http server programmatically', function (t) {
var server = torrent.createServer()
server.listen(port)
- http.get('http://localhost:' + port + '/0', function (res) {
- res.pipe(concat(function (data) {
+ get.concat('http://localhost:' + port + '/0', function (err, data) {
+ // Verify data for first (and only file)
+ t.deepEqual(data, fs.readFileSync(leavesPath))
- // Verify data for first (and only file)
- t.deepEqual(data, fs.readFileSync(leavesFile))
-
- server.close()
- client.destroy()
- t.end()
- }))
+ server.close()
+ client.destroy()
+ t.end()
})
})
})
torrent.on('ready', function () {
- torrent.storage.load(fs.createReadStream(leavesFile))
+ torrent.storage.load(fs.createReadStream(leavesPath))
})
})