Tests refractoring
This commit is contained in:
parent
4d5f813870
commit
876d1bcfd0
|
@ -1,11 +1,11 @@
|
||||||
;(function () {
|
;(function () {
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
var request = require('supertest')
|
|
||||||
var chai = require('chai')
|
var chai = require('chai')
|
||||||
var expect = chai.expect
|
var expect = chai.expect
|
||||||
|
var request = require('supertest')
|
||||||
|
|
||||||
var utils = require('../utils')
|
var utils = require('./utils')
|
||||||
|
|
||||||
describe('Test parameters validator', function () {
|
describe('Test parameters validator', function () {
|
||||||
var app = null
|
var app = null
|
||||||
|
@ -129,7 +129,7 @@
|
||||||
description: 'my super description'
|
description: 'my super description'
|
||||||
}
|
}
|
||||||
var attach = {
|
var attach = {
|
||||||
'input_video': __dirname + '/../fixtures/video_short.webm'
|
'input_video': __dirname + '/fixtures/video_short.webm'
|
||||||
}
|
}
|
||||||
makePostRequest(path, data, attach, done)
|
makePostRequest(path, data, attach, done)
|
||||||
})
|
})
|
||||||
|
@ -140,7 +140,7 @@
|
||||||
description: 'my super description'
|
description: 'my super description'
|
||||||
}
|
}
|
||||||
var attach = {
|
var attach = {
|
||||||
'input_video': __dirname + '/../fixtures/video_short.webm'
|
'input_video': __dirname + '/fixtures/video_short.webm'
|
||||||
}
|
}
|
||||||
makePostRequest(path, data, attach, done)
|
makePostRequest(path, data, attach, done)
|
||||||
})
|
})
|
||||||
|
@ -150,7 +150,7 @@
|
||||||
name: 'my super name'
|
name: 'my super name'
|
||||||
}
|
}
|
||||||
var attach = {
|
var attach = {
|
||||||
'input_video': __dirname + '/../fixtures/video_short.webm'
|
'input_video': __dirname + '/fixtures/video_short.webm'
|
||||||
}
|
}
|
||||||
makePostRequest(path, data, attach, done)
|
makePostRequest(path, data, attach, done)
|
||||||
})
|
})
|
||||||
|
@ -163,7 +163,7 @@
|
||||||
'very very very very very very very very very very very very very very very long'
|
'very very very very very very very very very very very very very very very long'
|
||||||
}
|
}
|
||||||
var attach = {
|
var attach = {
|
||||||
'input_video': __dirname + '/../fixtures/video_short.webm'
|
'input_video': __dirname + '/fixtures/video_short.webm'
|
||||||
}
|
}
|
||||||
makePostRequest(path, data, attach, done)
|
makePostRequest(path, data, attach, done)
|
||||||
})
|
})
|
||||||
|
@ -194,12 +194,12 @@
|
||||||
description: 'my super description'
|
description: 'my super description'
|
||||||
}
|
}
|
||||||
var attach = {
|
var attach = {
|
||||||
'input_video': __dirname + '/../fixtures/video_short.webm'
|
'input_video': __dirname + '/fixtures/video_short.webm'
|
||||||
}
|
}
|
||||||
makePostRequest(path, data, attach, function () {
|
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 () {
|
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)
|
makePostRequest(path, data, attach, done, true)
|
||||||
}, true)
|
}, true)
|
||||||
}, true)
|
}, true)
|
||||||
|
|
|
@ -1,60 +1,29 @@
|
||||||
;(function () {
|
;(function () {
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
var request = require('supertest')
|
|
||||||
var chai = require('chai')
|
var chai = require('chai')
|
||||||
var expect = chai.expect
|
var expect = chai.expect
|
||||||
|
|
||||||
var utils = require('../utils')
|
var utils = require('./utils')
|
||||||
|
|
||||||
describe('Test advanced friends', function () {
|
describe('Test advanced friends', function () {
|
||||||
var path = '/api/v1/pods/makefriends'
|
|
||||||
var apps = []
|
var apps = []
|
||||||
var urls = []
|
var urls = []
|
||||||
|
|
||||||
function makeFriend (pod_number, callback) {
|
function makeFriend (pod_number, callback) {
|
||||||
// The first pod make friend with the third
|
return utils.makeFriend(urls[pod_number - 1], callback)
|
||||||
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)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFriendsList (pod_number, end) {
|
function getFriendsList (pod_number, end) {
|
||||||
var path = '/api/v1/pods/'
|
return utils.getFriendsList(urls[pod_number - 1], end)
|
||||||
|
|
||||||
request(urls[pod_number - 1])
|
|
||||||
.get(path)
|
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.expect(200)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.end(end)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadVideo (pod_number, callback) {
|
function uploadVideo (pod_number, callback) {
|
||||||
var path = '/api/v1/videos'
|
var name = 'my super video'
|
||||||
|
var description = 'my super description'
|
||||||
|
var fixture = 'video_short.webm'
|
||||||
|
|
||||||
request(urls[pod_number - 1])
|
return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
|
||||||
.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)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
|
|
|
@ -1,23 +1,12 @@
|
||||||
;(function () {
|
;(function () {
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
var request = require('supertest')
|
var async = require('async')
|
||||||
var chai = require('chai')
|
var chai = require('chai')
|
||||||
var expect = chai.expect
|
var expect = chai.expect
|
||||||
var async = require('async')
|
var request = require('supertest')
|
||||||
|
|
||||||
var utils = require('../utils')
|
var utils = require('./utils')
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Test basic friends', function () {
|
describe('Test basic friends', function () {
|
||||||
var apps = []
|
var apps = []
|
||||||
|
@ -34,7 +23,7 @@
|
||||||
|
|
||||||
it('Should not have friends', function (done) {
|
it('Should not have friends', function (done) {
|
||||||
async.each(urls, function (url, callback) {
|
async.each(urls, function (url, callback) {
|
||||||
getFriendsList(url, function (err, res) {
|
utils.getFriendsList(url, function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var result = res.body
|
var result = res.body
|
||||||
|
@ -59,7 +48,7 @@
|
||||||
friends.push(urls[i])
|
friends.push(urls[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
getFriendsList(url_to_test, function (err, res) {
|
utils.getFriendsList(url_to_test, function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var result = res.body
|
var result = res.body
|
||||||
|
@ -88,7 +77,7 @@
|
||||||
// Wait for the request between pods
|
// Wait for the request between pods
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
// The second pod should have the third as a friend
|
// 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
|
if (err) throw err
|
||||||
|
|
||||||
var result = res.body
|
var result = res.body
|
||||||
|
@ -97,7 +86,7 @@
|
||||||
expect(result[0].url).to.be.equal(urls[2])
|
expect(result[0].url).to.be.equal(urls[2])
|
||||||
|
|
||||||
// Same here, the third pod should have the second pod as a friend
|
// 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
|
if (err) throw err
|
||||||
|
|
||||||
var result = res.body
|
var result = res.body
|
||||||
|
|
|
@ -1,86 +1,47 @@
|
||||||
;(function () {
|
;(function () {
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
var request = require('supertest')
|
var async = require('async')
|
||||||
var chai = require('chai')
|
var chai = require('chai')
|
||||||
var expect = chai.expect
|
var expect = chai.expect
|
||||||
var async = require('async')
|
|
||||||
|
|
||||||
var utils = require('../utils')
|
var utils = require('./utils')
|
||||||
var webtorrent = require(__dirname + '/../../src/webTorrentNode')
|
var webtorrent = require(__dirname + '/../../src/webTorrentNode')
|
||||||
webtorrent.silent = true
|
webtorrent.silent = true
|
||||||
|
|
||||||
describe('Test multiple pods', function () {
|
describe('Test multiple pods', function () {
|
||||||
var path = '/api/v1/videos'
|
|
||||||
var apps = []
|
var apps = []
|
||||||
var urls = []
|
var urls = []
|
||||||
var to_remove = []
|
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) {
|
before(function (done) {
|
||||||
this.timeout(30000)
|
this.timeout(30000)
|
||||||
var path_friends = '/api/v1/pods/makefriends'
|
|
||||||
|
|
||||||
utils.runMultipleServers(3, function (apps_run, urls_run) {
|
utils.runMultipleServers(3, function (apps_run, urls_run) {
|
||||||
apps = apps_run
|
apps = apps_run
|
||||||
urls = urls_run
|
urls = urls_run
|
||||||
|
|
||||||
// The second pod make friend with the third
|
// The second pod make friend with the third
|
||||||
request(urls[1])
|
utils.makeFriend(urls[1], function (err, res) {
|
||||||
.get(path_friends)
|
if (err) throw err
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.expect(204)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) throw err
|
|
||||||
|
|
||||||
// Wait for the request between pods
|
// Wait for the request between pods
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
request(urls[0])
|
utils.makeFriend(urls[0], function (err, res) {
|
||||||
.get(path_friends)
|
if (err) throw err
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.expect(204)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) throw err
|
|
||||||
|
|
||||||
webtorrent.create({ host: 'client', port: '1' }, function () {
|
webtorrent.create({ host: 'client', port: '1' }, function () {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}, 10000)
|
}, 10000)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not have videos for all pods', function (done) {
|
it('Should not have videos for all pods', function (done) {
|
||||||
async.each(urls, function (url, callback) {
|
async.each(urls, function (url, callback) {
|
||||||
getVideosList(url, function (err, res) {
|
utils.getVideosList(url, function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
expect(res.body).to.be.an('array')
|
expect(res.body).to.be.an('array')
|
||||||
|
@ -99,7 +60,7 @@
|
||||||
it('Should upload the video on pod 1 and propagate on each pod', function (done) {
|
it('Should upload the video on pod 1 and propagate on each pod', function (done) {
|
||||||
this.timeout(15000)
|
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
|
if (err) throw err
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -107,7 +68,7 @@
|
||||||
async.each(urls, function (url, callback) {
|
async.each(urls, function (url, callback) {
|
||||||
var base_magnet = null
|
var base_magnet = null
|
||||||
|
|
||||||
getVideosList(url, function (err, res) {
|
utils.getVideosList(url, function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var videos = res.body
|
var videos = res.body
|
||||||
|
@ -140,7 +101,7 @@
|
||||||
it('Should upload the video on pod 2 and propagate on each pod', function (done) {
|
it('Should upload the video on pod 2 and propagate on each pod', function (done) {
|
||||||
this.timeout(15000)
|
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
|
if (err) throw err
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -148,7 +109,7 @@
|
||||||
async.each(urls, function (url, callback) {
|
async.each(urls, function (url, callback) {
|
||||||
var base_magnet = null
|
var base_magnet = null
|
||||||
|
|
||||||
getVideosList(url, function (err, res) {
|
utils.getVideosList(url, function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var videos = res.body
|
var videos = res.body
|
||||||
|
@ -181,16 +142,16 @@
|
||||||
it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
|
it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
|
||||||
this.timeout(15000)
|
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
|
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
|
if (err) throw err
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var base_magnet = null
|
var base_magnet = null
|
||||||
// All pods should have this video
|
// All pods should have this video
|
||||||
async.each(urls, function (url, callback) {
|
async.each(urls, function (url, callback) {
|
||||||
getVideosList(url, function (err, res) {
|
utils.getVideosList(url, function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var videos = res.body
|
var videos = res.body
|
||||||
|
@ -233,7 +194,7 @@
|
||||||
// Yes, this could be long
|
// Yes, this could be long
|
||||||
this.timeout(200000)
|
this.timeout(200000)
|
||||||
|
|
||||||
getVideosList(urls[2], function (err, res) {
|
utils.getVideosList(urls[2], function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var video = res.body[0]
|
var video = res.body[0]
|
||||||
|
@ -254,7 +215,7 @@
|
||||||
// Yes, this could be long
|
// Yes, this could be long
|
||||||
this.timeout(200000)
|
this.timeout(200000)
|
||||||
|
|
||||||
getVideosList(urls[0], function (err, res) {
|
utils.getVideosList(urls[0], function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var video = res.body[1]
|
var video = res.body[1]
|
||||||
|
@ -273,7 +234,7 @@
|
||||||
// Yes, this could be long
|
// Yes, this could be long
|
||||||
this.timeout(200000)
|
this.timeout(200000)
|
||||||
|
|
||||||
getVideosList(urls[1], function (err, res) {
|
utils.getVideosList(urls[1], function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var video = res.body[2]
|
var video = res.body[2]
|
||||||
|
@ -292,7 +253,7 @@
|
||||||
// Yes, this could be long
|
// Yes, this could be long
|
||||||
this.timeout(200000)
|
this.timeout(200000)
|
||||||
|
|
||||||
getVideosList(urls[0], function (err, res) {
|
utils.getVideosList(urls[0], function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var video = res.body[3]
|
var video = res.body[3]
|
||||||
|
@ -310,9 +271,9 @@
|
||||||
it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
|
it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
|
||||||
this.timeout(15000)
|
this.timeout(15000)
|
||||||
|
|
||||||
removeVideo(urls[2], to_remove[0], function (err) {
|
utils.removeVideo(urls[2], to_remove[0], function (err) {
|
||||||
if (err) throw 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
|
if (err) throw err
|
||||||
|
|
||||||
// Wait the propagation to the other pods
|
// Wait the propagation to the other pods
|
||||||
|
@ -325,7 +286,7 @@
|
||||||
|
|
||||||
it('Should have videos 1 and 3 on each pod', function (done) {
|
it('Should have videos 1 and 3 on each pod', function (done) {
|
||||||
async.each(urls, function (url, callback) {
|
async.each(urls, function (url, callback) {
|
||||||
getVideosList(url, function (err, res) {
|
utils.getVideosList(url, function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
var videos = res.body
|
var videos = res.body
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
;(function () {
|
;(function () {
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
var request = require('supertest')
|
|
||||||
var chai = require('chai')
|
var chai = require('chai')
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
var expect = chai.expect
|
var expect = chai.expect
|
||||||
|
|
||||||
var webtorrent = require(__dirname + '/../../src/webTorrentNode')
|
var webtorrent = require(__dirname + '/../../src/webTorrentNode')
|
||||||
webtorrent.silent = true
|
webtorrent.silent = true
|
||||||
|
|
||||||
var utils = require('../utils')
|
var utils = require('./utils')
|
||||||
|
|
||||||
describe('Test a single pod', function () {
|
describe('Test a single pod', function () {
|
||||||
var path = '/api/v1/videos'
|
|
||||||
var app = null
|
var app = null
|
||||||
var url = ''
|
var url = ''
|
||||||
var video_id = -1
|
var video_id = -1
|
||||||
|
@ -32,135 +31,99 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not have videos', function (done) {
|
it('Should not have videos', function (done) {
|
||||||
request(url)
|
utils.getVideosList(url, function (err, res) {
|
||||||
.get(path)
|
if (err) throw err
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.expect(200)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) throw err
|
|
||||||
|
|
||||||
expect(res.body).to.be.an('array')
|
expect(res.body).to.be.an('array')
|
||||||
expect(res.body.length).to.equal(0)
|
expect(res.body.length).to.equal(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should upload the video', function (done) {
|
it('Should upload the video', function (done) {
|
||||||
this.timeout(5000)
|
this.timeout(5000)
|
||||||
|
utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done)
|
||||||
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)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should seed the uploaded video', function (done) {
|
it('Should seed the uploaded video', function (done) {
|
||||||
// Yes, this could be long
|
// Yes, this could be long
|
||||||
this.timeout(60000)
|
this.timeout(60000)
|
||||||
|
|
||||||
request(url)
|
utils.getVideosList(url, function (err, res) {
|
||||||
.get(path)
|
if (err) throw err
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.expect(200)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) throw err
|
|
||||||
|
|
||||||
expect(res.body).to.be.an('array')
|
expect(res.body).to.be.an('array')
|
||||||
expect(res.body.length).to.equal(1)
|
expect(res.body.length).to.equal(1)
|
||||||
|
|
||||||
var video = res.body[0]
|
var video = res.body[0]
|
||||||
expect(video.name).to.equal('my super name')
|
expect(video.name).to.equal('my super name')
|
||||||
expect(video.description).to.equal('my super description')
|
expect(video.description).to.equal('my super description')
|
||||||
expect(video.podUrl).to.equal('http://localhost:9001')
|
expect(video.podUrl).to.equal('http://localhost:9001')
|
||||||
expect(video.magnetUri).to.exist
|
expect(video.magnetUri).to.exist
|
||||||
|
|
||||||
video_id = video._id
|
video_id = video._id
|
||||||
|
|
||||||
webtorrent.add(video.magnetUri, function (torrent) {
|
webtorrent.add(video.magnetUri, function (torrent) {
|
||||||
expect(torrent.files).to.exist
|
expect(torrent.files).to.exist
|
||||||
expect(torrent.files.length).to.equal(1)
|
expect(torrent.files.length).to.equal(1)
|
||||||
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
|
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should search the video', function (done) {
|
it('Should search the video', function (done) {
|
||||||
request(url)
|
utils.searchVideo(url, 'my', function (err, res) {
|
||||||
.get(path + '/search/my')
|
if (err) throw err
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.expect(200)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) throw err
|
|
||||||
|
|
||||||
expect(res.body).to.be.an('array')
|
expect(res.body).to.be.an('array')
|
||||||
expect(res.body.length).to.equal(1)
|
expect(res.body.length).to.equal(1)
|
||||||
|
|
||||||
var video = res.body[0]
|
var video = res.body[0]
|
||||||
expect(video.name).to.equal('my super name')
|
expect(video.name).to.equal('my super name')
|
||||||
expect(video.description).to.equal('my super description')
|
expect(video.description).to.equal('my super description')
|
||||||
expect(video.podUrl).to.equal('http://localhost:9001')
|
expect(video.podUrl).to.equal('http://localhost:9001')
|
||||||
expect(video.magnetUri).to.exist
|
expect(video.magnetUri).to.exist
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not find a search', function (done) {
|
it('Should not find a search', function (done) {
|
||||||
request(url)
|
utils.searchVideo(url, 'hello', function (err, res) {
|
||||||
.get(path + '/search/hello')
|
if (err) throw err
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.expect(200)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) throw err
|
|
||||||
|
|
||||||
expect(res.body).to.be.an('array')
|
expect(res.body).to.be.an('array')
|
||||||
expect(res.body.length).to.equal(0)
|
expect(res.body.length).to.equal(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should remove the video', function (done) {
|
it('Should remove the video', function (done) {
|
||||||
request(url)
|
utils.removeVideo(url, video_id, function (err) {
|
||||||
.delete(path + '/' + video_id)
|
if (err) throw err
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.expect(204)
|
fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
|
expect(files.length).to.equal(0)
|
||||||
if (err) throw err
|
done()
|
||||||
|
|
||||||
expect(files.length).to.equal(0)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not have videos', function (done) {
|
it('Should not have videos', function (done) {
|
||||||
request(url)
|
utils.getVideosList(url, function (err, res) {
|
||||||
.get(path)
|
if (err) throw err
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.expect(200)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) throw err
|
|
||||||
|
|
||||||
expect(res.body).to.be.an('array')
|
expect(res.body).to.be.an('array')
|
||||||
expect(res.body.length).to.equal(0)
|
expect(res.body.length).to.equal(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function (done) {
|
after(function (done) {
|
||||||
|
|
|
@ -0,0 +1,162 @@
|
||||||
|
;(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
|
||||||
|
}
|
||||||
|
})()
|
|
@ -1,81 +0,0 @@
|
||||||
;(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
|
|
||||||
}
|
|
||||||
})()
|
|
Loading…
Reference in New Issue