;(function () {
'use strict'
- var request = require('supertest')
var chai = require('chai')
var expect = chai.expect
+ var request = require('supertest')
- var utils = require('../utils')
+ var utils = require('./utils')
describe('Test parameters validator', function () {
var app = null
description: 'my super description'
}
var attach = {
- 'input_video': __dirname + '/../fixtures/video_short.webm'
+ 'input_video': __dirname + '/fixtures/video_short.webm'
}
makePostRequest(path, data, attach, done)
})
description: 'my super description'
}
var attach = {
- 'input_video': __dirname + '/../fixtures/video_short.webm'
+ 'input_video': __dirname + '/fixtures/video_short.webm'
}
makePostRequest(path, data, attach, done)
})
name: 'my super name'
}
var attach = {
- 'input_video': __dirname + '/../fixtures/video_short.webm'
+ 'input_video': __dirname + '/fixtures/video_short.webm'
}
makePostRequest(path, data, attach, done)
})
'very very very very very very very very very very very very very very very long'
}
var attach = {
- 'input_video': __dirname + '/../fixtures/video_short.webm'
+ 'input_video': __dirname + '/fixtures/video_short.webm'
}
makePostRequest(path, data, attach, done)
})
description: 'my super description'
}
var attach = {
- 'input_video': __dirname + '/../fixtures/video_short.webm'
+ 'input_video': __dirname + '/fixtures/video_short.webm'
}
makePostRequest(path, data, attach, function () {
- attach.input_video = __dirname + '/../fixtures/video_short.mp4'
+ attach.input_video = __dirname + '/fixtures/video_short.mp4'
makePostRequest(path, data, attach, function () {
- attach.input_video = __dirname + '/../fixtures/video_short.ogv'
+ attach.input_video = __dirname + '/fixtures/video_short.ogv'
makePostRequest(path, data, attach, done, true)
}, true)
}, true)
;(function () {
'use strict'
- var request = require('supertest')
var chai = require('chai')
var expect = chai.expect
- var utils = require('../utils')
+ var utils = require('./utils')
describe('Test advanced friends', function () {
- var path = '/api/v1/pods/makefriends'
var apps = []
var urls = []
function makeFriend (pod_number, callback) {
- // The first pod make friend with the third
- request(urls[pod_number - 1])
- .get(path)
- .set('Accept', 'application/json')
- .expect(204)
- .end(function (err, res) {
- if (err) throw err
-
- // Wait for the request between pods
- setTimeout(function () {
- callback()
- }, 1000)
- })
+ return utils.makeFriend(urls[pod_number - 1], callback)
}
function getFriendsList (pod_number, end) {
- var path = '/api/v1/pods/'
-
- request(urls[pod_number - 1])
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
+ return utils.getFriendsList(urls[pod_number - 1], end)
}
function uploadVideo (pod_number, callback) {
- var path = '/api/v1/videos'
-
- request(urls[pod_number - 1])
- .post(path)
- .set('Accept', 'application/json')
- .field('name', 'my super video')
- .field('description', 'my super description')
- .attach('input_video', __dirname + '/../fixtures/video_short.webm')
- .expect(201)
- .end(function (err) {
- if (err) throw err
-
- // Wait for the retry requests
- setTimeout(callback, 10000)
- })
+ var name = 'my super video'
+ var description = 'my super description'
+ var fixture = 'video_short.webm'
+
+ return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
}
beforeEach(function (done) {
;(function () {
'use strict'
- var request = require('supertest')
+ var async = require('async')
var chai = require('chai')
var expect = chai.expect
- var async = require('async')
-
- var utils = require('../utils')
-
- function getFriendsList (url, end) {
- var path = '/api/v1/pods/'
+ var request = require('supertest')
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
- }
+ var utils = require('./utils')
describe('Test basic friends', function () {
var apps = []
it('Should not have friends', function (done) {
async.each(urls, function (url, callback) {
- getFriendsList(url, function (err, res) {
+ utils.getFriendsList(url, function (err, res) {
if (err) throw err
var result = res.body
friends.push(urls[i])
}
- getFriendsList(url_to_test, function (err, res) {
+ utils.getFriendsList(url_to_test, function (err, res) {
if (err) throw err
var result = res.body
// Wait for the request between pods
setTimeout(function () {
// The second pod should have the third as a friend
- getFriendsList(urls[1], function (err, res) {
+ utils.getFriendsList(urls[1], function (err, res) {
if (err) throw err
var result = res.body
expect(result[0].url).to.be.equal(urls[2])
// Same here, the third pod should have the second pod as a friend
- getFriendsList(urls[2], function (err, res) {
+ utils.getFriendsList(urls[2], function (err, res) {
if (err) throw err
var result = res.body
;(function () {
'use strict'
- var request = require('supertest')
+ var async = require('async')
var chai = require('chai')
var expect = chai.expect
- var async = require('async')
- var utils = require('../utils')
+ var utils = require('./utils')
var webtorrent = require(__dirname + '/../../src/webTorrentNode')
webtorrent.silent = true
describe('Test multiple pods', function () {
- var path = '/api/v1/videos'
var apps = []
var urls = []
var to_remove = []
- function getVideosList (url, end) {
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(end)
- }
-
- function uploadVideo (url, name, description, fixture, end) {
- request(url)
- .post(path)
- .set('Accept', 'application/json')
- .field('name', name)
- .field('description', description)
- .attach('input_video', __dirname + '/../fixtures/' + fixture)
- .expect(201)
- .end(end)
- }
-
- function removeVideo (url, id, end) {
- request(url)
- .delete(path + '/' + id)
- .set('Accept', 'application/json')
- .expect(204)
- .end(end)
- }
-
before(function (done) {
this.timeout(30000)
- var path_friends = '/api/v1/pods/makefriends'
utils.runMultipleServers(3, function (apps_run, urls_run) {
apps = apps_run
urls = urls_run
// The second pod make friend with the third
- request(urls[1])
- .get(path_friends)
- .set('Accept', 'application/json')
- .expect(204)
- .end(function (err, res) {
- if (err) throw err
+ utils.makeFriend(urls[1], function (err, res) {
+ if (err) throw err
- // Wait for the request between pods
- setTimeout(function () {
- request(urls[0])
- .get(path_friends)
- .set('Accept', 'application/json')
- .expect(204)
- .end(function (err, res) {
- if (err) throw err
+ // Wait for the request between pods
+ setTimeout(function () {
+ utils.makeFriend(urls[0], function (err, res) {
+ if (err) throw err
- webtorrent.create({ host: 'client', port: '1' }, function () {
- done()
- })
- })
- }, 10000)
- })
+ webtorrent.create({ host: 'client', port: '1' }, function () {
+ done()
+ })
+ })
+ }, 10000)
+ })
})
})
it('Should not have videos for all pods', function (done) {
async.each(urls, function (url, callback) {
- getVideosList(url, function (err, res) {
+ utils.getVideosList(url, function (err, res) {
if (err) throw err
expect(res.body).to.be.an('array')
it('Should upload the video on pod 1 and propagate on each pod', function (done) {
this.timeout(15000)
- uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err) {
+ utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err) {
if (err) throw err
setTimeout(function () {
async.each(urls, function (url, callback) {
var base_magnet = null
- getVideosList(url, function (err, res) {
+ utils.getVideosList(url, function (err, res) {
if (err) throw err
var videos = res.body
it('Should upload the video on pod 2 and propagate on each pod', function (done) {
this.timeout(15000)
- uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err) {
+ utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err) {
if (err) throw err
setTimeout(function () {
async.each(urls, function (url, callback) {
var base_magnet = null
- getVideosList(url, function (err, res) {
+ utils.getVideosList(url, function (err, res) {
if (err) throw err
var videos = res.body
it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
this.timeout(15000)
- uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err) {
+ utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err) {
if (err) throw err
- uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', function (err) {
+ utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', function (err) {
if (err) throw err
setTimeout(function () {
var base_magnet = null
// All pods should have this video
async.each(urls, function (url, callback) {
- getVideosList(url, function (err, res) {
+ utils.getVideosList(url, function (err, res) {
if (err) throw err
var videos = res.body
// Yes, this could be long
this.timeout(200000)
- getVideosList(urls[2], function (err, res) {
+ utils.getVideosList(urls[2], function (err, res) {
if (err) throw err
var video = res.body[0]
// Yes, this could be long
this.timeout(200000)
- getVideosList(urls[0], function (err, res) {
+ utils.getVideosList(urls[0], function (err, res) {
if (err) throw err
var video = res.body[1]
// Yes, this could be long
this.timeout(200000)
- getVideosList(urls[1], function (err, res) {
+ utils.getVideosList(urls[1], function (err, res) {
if (err) throw err
var video = res.body[2]
// Yes, this could be long
this.timeout(200000)
- getVideosList(urls[0], function (err, res) {
+ utils.getVideosList(urls[0], function (err, res) {
if (err) throw err
var video = res.body[3]
it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
this.timeout(15000)
- removeVideo(urls[2], to_remove[0], function (err) {
+ utils.removeVideo(urls[2], to_remove[0], function (err) {
if (err) throw err
- removeVideo(urls[2], to_remove[1], function (err) {
+ utils.removeVideo(urls[2], to_remove[1], function (err) {
if (err) throw err
// Wait the propagation to the other pods
it('Should have videos 1 and 3 on each pod', function (done) {
async.each(urls, function (url, callback) {
- getVideosList(url, function (err, res) {
+ utils.getVideosList(url, function (err, res) {
if (err) throw err
var videos = res.body
;(function () {
'use strict'
- var request = require('supertest')
var chai = require('chai')
var fs = require('fs')
var expect = chai.expect
+
var webtorrent = require(__dirname + '/../../src/webTorrentNode')
webtorrent.silent = true
- var utils = require('../utils')
+ var utils = require('./utils')
describe('Test a single pod', function () {
- var path = '/api/v1/videos'
var app = null
var url = ''
var video_id = -1
})
it('Should not have videos', function (done) {
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(function (err, res) {
- if (err) throw err
+ utils.getVideosList(url, function (err, res) {
+ if (err) throw err
- expect(res.body).to.be.an('array')
- expect(res.body.length).to.equal(0)
+ expect(res.body).to.be.an('array')
+ expect(res.body.length).to.equal(0)
- done()
- })
+ done()
+ })
})
it('Should upload the video', function (done) {
this.timeout(5000)
-
- request(url)
- .post(path)
- .set('Accept', 'application/json')
- .field('name', 'my super name')
- .field('description', 'my super description')
- .attach('input_video', __dirname + '/../fixtures/video_short.webm')
- .expect(201, done)
+ utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done)
})
it('Should seed the uploaded video', function (done) {
// Yes, this could be long
this.timeout(60000)
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(function (err, res) {
- if (err) throw err
+ utils.getVideosList(url, function (err, res) {
+ if (err) throw err
- expect(res.body).to.be.an('array')
- expect(res.body.length).to.equal(1)
+ expect(res.body).to.be.an('array')
+ expect(res.body.length).to.equal(1)
- var video = res.body[0]
- expect(video.name).to.equal('my super name')
- expect(video.description).to.equal('my super description')
- expect(video.podUrl).to.equal('http://localhost:9001')
- expect(video.magnetUri).to.exist
+ var video = res.body[0]
+ expect(video.name).to.equal('my super name')
+ expect(video.description).to.equal('my super description')
+ expect(video.podUrl).to.equal('http://localhost:9001')
+ expect(video.magnetUri).to.exist
- video_id = video._id
+ video_id = video._id
- webtorrent.add(video.magnetUri, function (torrent) {
- expect(torrent.files).to.exist
- expect(torrent.files.length).to.equal(1)
- expect(torrent.files[0].path).to.exist.and.to.not.equal('')
+ webtorrent.add(video.magnetUri, function (torrent) {
+ expect(torrent.files).to.exist
+ expect(torrent.files.length).to.equal(1)
+ expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- done()
- })
+ done()
})
+ })
})
it('Should search the video', function (done) {
- request(url)
- .get(path + '/search/my')
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(function (err, res) {
- if (err) throw err
+ utils.searchVideo(url, 'my', function (err, res) {
+ if (err) throw err
- expect(res.body).to.be.an('array')
- expect(res.body.length).to.equal(1)
+ expect(res.body).to.be.an('array')
+ expect(res.body.length).to.equal(1)
- var video = res.body[0]
- expect(video.name).to.equal('my super name')
- expect(video.description).to.equal('my super description')
- expect(video.podUrl).to.equal('http://localhost:9001')
- expect(video.magnetUri).to.exist
+ var video = res.body[0]
+ expect(video.name).to.equal('my super name')
+ expect(video.description).to.equal('my super description')
+ expect(video.podUrl).to.equal('http://localhost:9001')
+ expect(video.magnetUri).to.exist
- done()
- })
+ done()
+ })
})
it('Should not find a search', function (done) {
- request(url)
- .get(path + '/search/hello')
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(function (err, res) {
- if (err) throw err
+ utils.searchVideo(url, 'hello', function (err, res) {
+ if (err) throw err
- expect(res.body).to.be.an('array')
- expect(res.body.length).to.equal(0)
+ expect(res.body).to.be.an('array')
+ expect(res.body.length).to.equal(0)
- done()
- })
+ done()
+ })
})
it('Should remove the video', function (done) {
- request(url)
- .delete(path + '/' + video_id)
- .set('Accept', 'application/json')
- .expect(204)
- .end(function (err, res) {
- if (err) throw err
+ utils.removeVideo(url, video_id, function (err) {
+ if (err) throw err
- fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
- if (err) throw err
+ fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
+ if (err) throw err
- expect(files.length).to.equal(0)
- done()
- })
+ expect(files.length).to.equal(0)
+ done()
})
+ })
})
it('Should not have videos', function (done) {
- request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
- .end(function (err, res) {
- if (err) throw err
+ utils.getVideosList(url, function (err, res) {
+ if (err) throw err
- expect(res.body).to.be.an('array')
- expect(res.body.length).to.equal(0)
+ expect(res.body).to.be.an('array')
+ expect(res.body.length).to.equal(0)
- done()
- })
+ done()
+ })
})
after(function (done) {
--- /dev/null
+;(function () {
+ 'use strict'
+
+ var child_process = require('child_process')
+ var exec = child_process.exec
+ var fork = child_process.fork
+ var request = require('supertest')
+
+ function flushTests (callback) {
+ exec(__dirname + '/../../scripts/clean_test.sh', function () {
+ callback()
+ })
+ }
+
+ function getFriendsList (url, end) {
+ var path = '/api/v1/pods/'
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+ }
+
+ function getVideosList (url, end) {
+ var path = '/api/v1/videos'
+
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+ }
+
+ function makeFriend (url, callback) {
+ var path = '/api/v1/pods/makefriends'
+
+ // The first pod make friend with the third
+ request(url)
+ .get(path)
+ .set('Accept', 'application/json')
+ .expect(204)
+ .end(function (err, res) {
+ if (err) throw err
+
+ // Wait for the request between pods
+ setTimeout(function () {
+ callback()
+ }, 1000)
+ })
+ }
+
+ function uploadVideo (url, name, description, fixture, end) {
+ var path = '/api/v1/videos'
+
+ request(url)
+ .post(path)
+ .set('Accept', 'application/json')
+ .field('name', name)
+ .field('description', description)
+ .attach('input_video', __dirname + '/fixtures/' + fixture)
+ .expect(201)
+ .end(end)
+ }
+
+ function removeVideo (url, id, end) {
+ var path = '/api/v1/videos'
+
+ request(url)
+ .delete(path + '/' + id)
+ .set('Accept', 'application/json')
+ .expect(204)
+ .end(end)
+ }
+
+ function runMultipleServers (total_servers, serversRun) {
+ var apps = []
+ var urls = []
+ var i = 0
+
+ function anotherServerDone (number, app, url) {
+ apps[number - 1] = app
+ urls[number - 1] = url
+ i++
+ if (i === total_servers) {
+ serversRun(apps, urls)
+ }
+ }
+
+ flushTests(function () {
+ for (var j = 1; j <= total_servers; j++) {
+ (function (k) { // TODO: ES6 with let
+ // For the virtual buffer
+ setTimeout(function () {
+ runServer(k, function (app, url) {
+ anotherServerDone(k, app, url)
+ })
+ }, 1000 * k)
+ })(j)
+ }
+ })
+ }
+
+ function runServer (number, callback) {
+ var port = 9000 + number
+ var server_run_string = {
+ 'Connected to mongodb': false,
+ 'Server listening on port': false
+ }
+
+ // Share the environment
+ var env = Object.create(process.env)
+ env.NODE_ENV = 'test'
+ env.NODE_APP_INSTANCE = number
+ var options = {
+ silent: true,
+ env: env,
+ detached: true
+ }
+
+ var app = fork(__dirname + '/../../server.js', [], options)
+ app.stdout.on('data', function onStdout (data) {
+ var dont_continue = false
+ // Check if all required sentences are here
+ for (var key of Object.keys(server_run_string)) {
+ if (data.toString().indexOf(key) !== -1) server_run_string[key] = true
+ if (server_run_string[key] === false) dont_continue = true
+ }
+
+ // If no, there is maybe one thing not already initialized (mongodb...)
+ if (dont_continue === true) return
+
+ app.stdout.removeListener('data', onStdout)
+ callback(app, 'http://localhost:' + port)
+ })
+ }
+
+ function searchVideo (url, search, end) {
+ var path = '/api/v1/videos'
+
+ request(url)
+ .get(path + '/search/' + search)
+ .set('Accept', 'application/json')
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .end(end)
+ }
+
+ module.exports = {
+ flushTests: flushTests,
+ getFriendsList: getFriendsList,
+ getVideosList: getVideosList,
+ makeFriend: makeFriend,
+ removeVideo: removeVideo,
+ runMultipleServers: runMultipleServers,
+ runServer: runServer,
+ searchVideo: searchVideo,
+ uploadVideo: uploadVideo
+ }
+})()
+++ /dev/null
-;(function () {
- 'use strict'
-
- var child_process = require('child_process')
- var fork = child_process.fork
- var exec = child_process.exec
-
- function runMultipleServers (total_servers, serversRun) {
- var apps = []
- var urls = []
- var i = 0
-
- function anotherServerDone (number, app, url) {
- apps[number - 1] = app
- urls[number - 1] = url
- i++
- if (i === total_servers) {
- serversRun(apps, urls)
- }
- }
-
- flushTests(function () {
- for (var j = 1; j <= total_servers; j++) {
- (function (k) { // TODO: ES6 with let
- // For the virtual buffer
- setTimeout(function () {
- runServer(k, function (app, url) {
- anotherServerDone(k, app, url)
- })
- }, 1000 * k)
- })(j)
- }
- })
- }
-
- function runServer (number, callback) {
- var port = 9000 + number
- var server_run_string = {
- 'Connected to mongodb': false,
- 'Server listening on port': false
- }
-
- // Share the environment
- var env = Object.create(process.env)
- env.NODE_ENV = 'test'
- env.NODE_APP_INSTANCE = number
- var options = {
- silent: true,
- env: env,
- detached: true
- }
-
- var app = fork(__dirname + '/../server.js', [], options)
- app.stdout.on('data', function onStdout (data) {
- var dont_continue = false
- // Check if all required sentences are here
- for (var key of Object.keys(server_run_string)) {
- if (data.toString().indexOf(key) !== -1) server_run_string[key] = true
- if (server_run_string[key] === false) dont_continue = true
- }
-
- // If no, there is maybe one thing not already initialized (mongodb...)
- if (dont_continue === true) return
-
- app.stdout.removeListener('data', onStdout)
- callback(app, 'http://localhost:' + port)
- })
- }
-
- function flushTests (callback) {
- exec(__dirname + '/../scripts/clean_test.sh', function () {
- callback()
- })
- }
-
- module.exports = {
- flushTests: flushTests,
- runMultipleServers: runMultipleServers,
- runServer: runServer
- }
-})()