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-10 09:03:19 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-01-10 09:03:19 +0300
commit6a666528fdaa23230d45676f24bbb5f3b899ada1 (patch)
tree4c9822a59b52c28ef5027d2ceac5bc800870f009 /test/cmd.js
parentb76408ac5d6f56d2fbb8ae1603286417393e3850 (diff)
command line: add `info` command
Fix #233
Diffstat (limited to 'test/cmd.js')
-rw-r--r--test/cmd.js79
1 files changed, 66 insertions, 13 deletions
diff --git a/test/cmd.js b/test/cmd.js
index b7c11c0..2cd0024 100644
--- a/test/cmd.js
+++ b/test/cmd.js
@@ -1,29 +1,82 @@
var cp = require('child_process')
+var fs = require('fs')
+var parseTorrent = require('parse-torrent')
var test = require('tape')
-test('Command line: --help', function (t) {
- t.plan(2)
+var CMD = __dirname + '/../bin/cmd.js'
+
+test('Command line: webtorrent help', function (t) {
+ t.plan(6)
+
+ cp.exec(CMD + ' help', function (err, data) {
+ t.error(err) // no error, exit code 0
+ t.ok(data.toLowerCase().indexOf('usage') !== -1)
+ })
+
+ cp.exec(CMD + ' --help', function (err, data) {
+ t.error(err) // no error, exit code 0
+ t.ok(data.toLowerCase().indexOf('usage') !== -1)
+ })
- var bin = __dirname + '/../bin/cmd.js --help'
- cp.exec(bin, function (err, data) {
+ cp.exec(CMD, function (err, data) {
t.error(err) // no error, exit code 0
- t.ok(data.indexOf('usage') !== 0)
+ t.ok(data.toLowerCase().indexOf('usage') !== -1)
})
+
})
-test('Command line: -v --version', function (t) {
- t.plan(4)
+test('Command line: webtorrent version', function (t) {
+ t.plan(6)
var expectedVersion = require(__dirname + '/../package.json').version + '\n'
- var bin = __dirname + '/../bin/cmd.js --version'
- cp.exec(bin, function (err, data) {
- t.error(err) // no error, exit code 0
+ cp.exec(CMD + ' version', function (err, data) {
+ t.error(err)
t.equal(data, expectedVersion)
})
- bin = __dirname + '/../bin/cmd.js -v'
- cp.exec(bin, function (err, data) {
- t.error(err) // no error, exit code 0
+ cp.exec(CMD + ' --version', function (err, data) {
+ t.error(err)
+ t.equal(data, expectedVersion)
+ })
+
+ cp.exec(CMD + ' -v', function (err, data) {
+ t.error(err)
t.equal(data, expectedVersion)
})
})
+
+test('Command line: webtorrent info /path/to/file.torrent', function (t) {
+ t.plan(3)
+
+ var leavesPath = __dirname + '/torrents/leaves.torrent'
+ var leaves = fs.readFileSync(leavesPath)
+
+ cp.exec(CMD + ' info ' + leavesPath, function (err, data) {
+ t.error(err)
+ data = JSON.parse(data)
+ var parsedTorrent = parseTorrent(leaves)
+ delete parsedTorrent.info
+ delete parsedTorrent.infoBuffer
+ t.deepEqual(data, JSON.parse(JSON.stringify(parsedTorrent, undefined, 2)))
+ })
+
+ cp.exec(CMD + ' info /bad/path', function (err, data) {
+ t.ok(err instanceof Error)
+ })
+})
+
+test('Command line: webtorrent info magnet_uri', function (t) {
+ t.plan(2)
+
+ var leavesMagnetURI = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce'
+
+ cp.exec(CMD + ' info "' + leavesMagnetURI + '"', function (err, data) {
+ t.error(err)
+ data = JSON.parse(data)
+ var parsedTorrent = parseTorrent(leavesMagnetURI)
+ t.deepEqual(data, JSON.parse(JSON.stringify(parsedTorrent, undefined, 2)))
+ })
+})
+
+// TODO: test 'webtorrent download /path/to/torrent'
+// TODO: test 'webtorrent download magnet_uri'