From cda021079ff455cc0fd0eb95a5395fa808ab63d1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 30 Jan 2016 17:05:22 +0100 Subject: New directory organization --- test/api/checkParams.js | 301 ----------------------------- test/api/fixtures/video_short.mp4 | Bin 38783 -> 0 bytes test/api/fixtures/video_short.ogv | Bin 140849 -> 0 bytes test/api/fixtures/video_short.webm | Bin 218910 -> 0 bytes test/api/fixtures/video_short1.webm | Bin 572456 -> 0 bytes test/api/fixtures/video_short2.webm | Bin 942961 -> 0 bytes test/api/fixtures/video_short3.webm | Bin 292677 -> 0 bytes test/api/fixtures/video_short_fake.webm | 1 - test/api/friendsAdvanced.js | 252 ------------------------ test/api/friendsBasic.js | 187 ------------------ test/api/index.js | 10 - test/api/multiplePods.js | 329 -------------------------------- test/api/singlePod.js | 147 -------------- test/api/utils.js | 182 ------------------ test/index.js | 6 - 15 files changed, 1415 deletions(-) delete mode 100644 test/api/checkParams.js delete mode 100644 test/api/fixtures/video_short.mp4 delete mode 100644 test/api/fixtures/video_short.ogv delete mode 100644 test/api/fixtures/video_short.webm delete mode 100644 test/api/fixtures/video_short1.webm delete mode 100644 test/api/fixtures/video_short2.webm delete mode 100644 test/api/fixtures/video_short3.webm delete mode 100644 test/api/fixtures/video_short_fake.webm delete mode 100644 test/api/friendsAdvanced.js delete mode 100644 test/api/friendsBasic.js delete mode 100644 test/api/index.js delete mode 100644 test/api/multiplePods.js delete mode 100644 test/api/singlePod.js delete mode 100644 test/api/utils.js delete mode 100644 test/index.js (limited to 'test') diff --git a/test/api/checkParams.js b/test/api/checkParams.js deleted file mode 100644 index 11fc68ff9..000000000 --- a/test/api/checkParams.js +++ /dev/null @@ -1,301 +0,0 @@ -;(function () { - 'use strict' - - var async = require('async') - var chai = require('chai') - var expect = chai.expect - var request = require('supertest') - - var utils = require('./utils') - - describe('Test parameters validator', function () { - var app = null - var url = '' - - function makePostRequest (path, fields, attach, done, fail) { - var status_code = 400 - if (fail !== undefined && fail === false) status_code = 200 - - var req = request(url) - .post(path) - .set('Accept', 'application/json') - - Object.keys(fields).forEach(function (field) { - var value = fields[field] - req.field(field, value) - }) - - req.expect(status_code, done) - } - - function makePostBodyRequest (path, fields, done, fail) { - var status_code = 400 - if (fail !== undefined && fail === false) status_code = 200 - - request(url) - .post(path) - .set('Accept', 'application/json') - .send(fields) - .expect(status_code, done) - } - - // --------------------------------------------------------------- - - before(function (done) { - this.timeout(20000) - - async.series([ - function (next) { - utils.flushTests(next) - }, - function (next) { - utils.runServer(1, function (app1, url1) { - app = app1 - url = url1 - next() - }) - } - ], done) - }) - - describe('Of the pods API', function () { - var path = '/api/v1/pods/' - - describe('When adding a pod', function () { - it('Should fail with nothing', function (done) { - var data = {} - makePostBodyRequest(path, data, done) - }) - - it('Should fail without public key', function (done) { - var data = { - data: { - url: 'http://coucou.com' - } - } - makePostBodyRequest(path, data, done) - }) - - it('Should fail without an url', function (done) { - var data = { - data: { - publicKey: 'mysuperpublickey' - } - } - makePostBodyRequest(path, data, done) - }) - - it('Should fail with an incorrect url', function (done) { - var data = { - data: { - url: 'coucou.com', - publicKey: 'mysuperpublickey' - } - } - makePostBodyRequest(path, data, function () { - data.data.url = 'http://coucou' - makePostBodyRequest(path, data, function () { - data.data.url = 'coucou' - makePostBodyRequest(path, data, done) - }) - }) - }) - - it('Should succeed with the correct parameters', function (done) { - var data = { - data: { - url: 'http://coucou.com', - publicKey: 'mysuperpublickey' - } - } - makePostBodyRequest(path, data, done, false) - }) - }) - }) - - describe('Of the videos API', function () { - var path = '/api/v1/videos/' - - describe('When searching a video', function () { - it('Should fail with nothing', function (done) { - request(url) - .get(path + '/search/') - .set('Accept', 'application/json') - .expect(400, done) - }) - }) - - describe('When adding a video', function () { - it('Should fail with nothing', function (done) { - var data = {} - var attach = {} - makePostRequest(path, data, attach, done) - }) - - it('Should fail without name', function (done) { - var data = { - description: 'my super description' - } - var attach = { - 'input_video': __dirname + '/fixtures/video_short.webm' - } - makePostRequest(path, data, attach, done) - }) - - it('Should fail with a long name', function (done) { - var data = { - name: 'My very very very very very very very very very very very very very very very very long name', - description: 'my super description' - } - var attach = { - 'input_video': __dirname + '/fixtures/video_short.webm' - } - makePostRequest(path, data, attach, done) - }) - - it('Should fail without description', function (done) { - var data = { - name: 'my super name' - } - var attach = { - 'input_video': __dirname + '/fixtures/video_short.webm' - } - makePostRequest(path, data, attach, done) - }) - - it('Should fail with a long description', function (done) { - var data = { - name: 'my super name', - description: 'my super description which is very very very very very very very very very very very very very very' + - 'very very very very very very very very very very very very very very very very very very very very very' + - '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' - } - makePostRequest(path, data, attach, done) - }) - - it('Should fail without an input file', function (done) { - var data = { - name: 'my super name', - description: 'my super description' - } - var attach = {} - makePostRequest(path, data, attach, done) - }) - - it('Should fail without an incorrect input file', function (done) { - var data = { - name: 'my super name', - description: 'my super description' - } - var attach = { - 'input_video': __dirname + '/../fixtures/video_short_fake.webm' - } - makePostRequest(path, data, attach, done) - }) - - it('Should succeed with the correct parameters', function (done) { - var data = { - name: 'my super name', - description: 'my super description' - } - var attach = { - 'input_video': __dirname + '/fixtures/video_short.webm' - } - makePostRequest(path, data, attach, function () { - attach.input_video = __dirname + '/fixtures/video_short.mp4' - makePostRequest(path, data, attach, function () { - attach.input_video = __dirname + '/fixtures/video_short.ogv' - makePostRequest(path, data, attach, done, true) - }, true) - }, true) - }) - }) - - describe('When getting a video', function () { - it('Should return the list of the videos with nothing', function (done) { - request(url) - .get(path) - .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.length).to.equal(0) - - done() - }) - }) - - it('Should fail without a mongodb id', function (done) { - request(url) - .get(path + 'coucou') - .set('Accept', 'application/json') - .expect(400, done) - }) - - it('Should return 404 with an incorrect video', function (done) { - request(url) - .get(path + '123456789012345678901234') - .set('Accept', 'application/json') - .expect(404, done) - }) - - it('Should succeed with the correct parameters') - }) - - describe('When removing a video', function () { - it('Should have 404 with nothing', function (done) { - request(url) - .delete(path) - .expect(404, done) - }) - - it('Should fail without a mongodb id', function (done) { - request(url) - .delete(path + 'hello') - .expect(400, done) - }) - - it('Should fail with a video which does not exist', function (done) { - request(url) - .delete(path + '123456789012345678901234') - .expect(404, done) - }) - - it('Should fail with a video of another pod') - - it('Should succeed with the correct parameters') - }) - }) - - describe('Of the remote videos API', function () { - describe('When making a secure request', function () { - it('Should check a secure request') - }) - - describe('When adding a video', function () { - it('Should check when adding a video') - }) - - describe('When removing a video', function () { - it('Should check when removing a video') - }) - }) - - after(function (done) { - process.kill(-app.pid) - - // Keep the logs if the test failed - if (this.ok) { - utils.flushTests(done) - } else { - done() - } - }) - }) -})() diff --git a/test/api/fixtures/video_short.mp4 b/test/api/fixtures/video_short.mp4 deleted file mode 100644 index 35678362b..000000000 Binary files a/test/api/fixtures/video_short.mp4 and /dev/null differ diff --git a/test/api/fixtures/video_short.ogv b/test/api/fixtures/video_short.ogv deleted file mode 100644 index 9e253da82..000000000 Binary files a/test/api/fixtures/video_short.ogv and /dev/null differ diff --git a/test/api/fixtures/video_short.webm b/test/api/fixtures/video_short.webm deleted file mode 100644 index bf4b0ab6c..000000000 Binary files a/test/api/fixtures/video_short.webm and /dev/null differ diff --git a/test/api/fixtures/video_short1.webm b/test/api/fixtures/video_short1.webm deleted file mode 100644 index 70ac0c644..000000000 Binary files a/test/api/fixtures/video_short1.webm and /dev/null differ diff --git a/test/api/fixtures/video_short2.webm b/test/api/fixtures/video_short2.webm deleted file mode 100644 index 13d72dff7..000000000 Binary files a/test/api/fixtures/video_short2.webm and /dev/null differ diff --git a/test/api/fixtures/video_short3.webm b/test/api/fixtures/video_short3.webm deleted file mode 100644 index cde5dcd58..000000000 Binary files a/test/api/fixtures/video_short3.webm and /dev/null differ diff --git a/test/api/fixtures/video_short_fake.webm b/test/api/fixtures/video_short_fake.webm deleted file mode 100644 index d85290ae5..000000000 --- a/test/api/fixtures/video_short_fake.webm +++ /dev/null @@ -1 +0,0 @@ -this is a fake video mouahahah diff --git a/test/api/friendsAdvanced.js b/test/api/friendsAdvanced.js deleted file mode 100644 index 61483bee6..000000000 --- a/test/api/friendsAdvanced.js +++ /dev/null @@ -1,252 +0,0 @@ -;(function () { - 'use strict' - - var async = require('async') - var chai = require('chai') - var expect = chai.expect - - var utils = require('./utils') - - describe('Test advanced friends', function () { - var apps = [] - var urls = [] - - function makeFriends (pod_number, callback) { - return utils.makeFriends(urls[pod_number - 1], callback) - } - - function quitFriends (pod_number, callback) { - return utils.quitFriends(urls[pod_number - 1], callback) - } - - function getFriendsList (pod_number, end) { - return utils.getFriendsList(urls[pod_number - 1], end) - } - - function uploadVideo (pod_number, callback) { - 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) - } - - function getVideos (pod_number, callback) { - return utils.getVideosList(urls[pod_number - 1], callback) - } - - // --------------------------------------------------------------- - - before(function (done) { - this.timeout(30000) - utils.flushAndRunMultipleServers(6, function (apps_run, urls_run) { - apps = apps_run - urls = urls_run - done() - }) - }) - - it('Should make friends with two pod each in a different group', function (done) { - this.timeout(20000) - - async.series([ - // Pod 3 makes friend with the first one - function (next) { - makeFriends(3, next) - }, - // Pod 4 makes friend with the second one - function (next) { - makeFriends(4, next) - }, - // Now if the fifth wants to make friends with the third et the first - function (next) { - makeFriends(5, next) - }, - function (next) { - setTimeout(next, 11000) - }], - function (err) { - if (err) throw err - - // It should have 0 friends - getFriendsList(5, function (err, res) { - if (err) throw err - - expect(res.body.length).to.equal(0) - - done() - }) - } - ) - }) - - it('Should quit all friends', function (done) { - this.timeout(10000) - - async.series([ - function (next) { - quitFriends(1, next) - }, - function (next) { - quitFriends(2, next) - }], - function (err) { - if (err) throw err - - async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) { - getFriendsList(i, function (err, res) { - if (err) throw err - - expect(res.body.length).to.equal(0) - - callback() - }) - }, done) - } - ) - }) - - it('Should make friends with the pods 1, 2, 3', function (done) { - this.timeout(150000) - - async.series([ - // Pods 1, 2, 3 and 4 become friends - function (next) { - makeFriends(2, next) - }, - function (next) { - makeFriends(1, next) - }, - function (next) { - makeFriends(4, next) - }, - // Kill pod 4 - function (next) { - apps[3].kill() - next() - }, - // Expulse pod 4 from pod 1 and 2 - function (next) { - uploadVideo(1, next) - }, - function (next) { - uploadVideo(2, next) - }, - function (next) { - setTimeout(next, 11000) - }, - function (next) { - uploadVideo(1, next) - }, - function (next) { - uploadVideo(2, next) - }, - function (next) { - setTimeout(next, 20000) - }, - // Rerun server 4 - function (next) { - utils.runServer(4, function (app, url) { - apps[3] = app - next() - }) - }, - function (next) { - getFriendsList(4, function (err, res) { - if (err) throw err - - // Pod 4 didn't know pod 1 and 2 removed it - expect(res.body.length).to.equal(3) - - next() - }) - }, - // Pod 6 ask pod 1, 2 and 3 - function (next) { - makeFriends(6, next) - }], - function (err) { - if (err) throw err - - getFriendsList(6, function (err, res) { - if (err) throw err - - // Pod 4 should not be our friend - var result = res.body - expect(result.length).to.equal(3) - for (var pod of result) { - expect(pod.url).not.equal(urls[3]) - } - - done() - }) - } - ) - }) - - it('Should pod 1 quit friends', function (done) { - this.timeout(25000) - - async.series([ - // Upload a video on server 3 for aditionnal tests - function (next) { - uploadVideo(3, next) - }, - function (next) { - setTimeout(next, 15000) - }, - function (next) { - quitFriends(1, next) - }, - // Remove pod 1 from pod 2 - function (next) { - getVideos(1, function (err, res) { - if (err) throw err - expect(res.body).to.be.an('array') - expect(res.body.length).to.equal(2) - - next() - }) - }], - function (err) { - if (err) throw err - - getVideos(2, function (err, res) { - if (err) throw err - expect(res.body).to.be.an('array') - expect(res.body.length).to.equal(3) - done() - }) - } - ) - }) - - it('Should make friends between pod 1 and 2 and exchange their videos', function (done) { - this.timeout(20000) - makeFriends(1, function () { - setTimeout(function () { - getVideos(1, function (err, res) { - if (err) throw err - - expect(res.body).to.be.an('array') - expect(res.body.length).to.equal(5) - - done() - }) - }, 5000) - }) - }) - - after(function (done) { - apps.forEach(function (app) { - process.kill(-app.pid) - }) - - if (this.ok) { - utils.flushTests(done) - } else { - done() - } - }) - }) -})() diff --git a/test/api/friendsBasic.js b/test/api/friendsBasic.js deleted file mode 100644 index dbc918383..000000000 --- a/test/api/friendsBasic.js +++ /dev/null @@ -1,187 +0,0 @@ -;(function () { - 'use strict' - - var async = require('async') - var chai = require('chai') - var expect = chai.expect - var request = require('supertest') - - var utils = require('./utils') - - describe('Test basic friends', function () { - var apps = [] - var urls = [] - - function testMadeFriends (urls, url_to_test, callback) { - var friends = [] - for (var i = 0; i < urls.length; i++) { - if (urls[i] === url_to_test) continue - friends.push(urls[i]) - } - - utils.getFriendsList(url_to_test, function (err, res) { - if (err) throw err - - var result = res.body - var result_urls = [ result[0].url, result[1].url ] - expect(result).to.be.an('array') - expect(result.length).to.equal(2) - expect(result_urls[0]).to.not.equal(result_urls[1]) - - var error_string = 'Friends url do not correspond for ' + url_to_test - expect(friends).to.contain(result_urls[0], error_string) - expect(friends).to.contain(result_urls[1], error_string) - callback() - }) - } - - // --------------------------------------------------------------- - - before(function (done) { - this.timeout(20000) - utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) { - apps = apps_run - urls = urls_run - done() - }) - }) - - it('Should not have friends', function (done) { - async.each(urls, function (url, callback) { - utils.getFriendsList(url, function (err, res) { - if (err) throw err - - var result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(0) - callback() - }) - }, done) - }) - - it('Should make friends', function (done) { - this.timeout(10000) - - var path = '/api/v1/pods/makefriends' - - async.series([ - // The second pod make friend with the third - function (next) { - request(urls[1]) - .get(path) - .set('Accept', 'application/json') - .expect(204) - .end(next) - }, - // Wait for the request between pods - function (next) { - setTimeout(next, 1000) - }, - // The second pod should have the third as a friend - function (next) { - utils.getFriendsList(urls[1], function (err, res) { - if (err) throw err - - var result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(1) - expect(result[0].url).to.be.equal(urls[2]) - - next() - }) - }, - // Same here, the third pod should have the second pod as a friend - function (next) { - utils.getFriendsList(urls[2], function (err, res) { - if (err) throw err - - var result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(1) - expect(result[0].url).to.be.equal(urls[1]) - - next() - }) - }, - // Finally the first pod make friend with the second pod - function (next) { - request(urls[0]) - .get(path) - .set('Accept', 'application/json') - .expect(204) - .end(next) - }, - // Wait for the request between pods - function (next) { - setTimeout(next, 1000) - } - ], - // Now each pod should be friend with the other ones - function (err) { - if (err) throw err - async.each(urls, function (url, callback) { - testMadeFriends(urls, url, callback) - }, done) - }) - }) - - it('Should not be allowed to make friend again', function (done) { - utils.makeFriends(urls[1], 409, done) - }) - - it('Should quit friends of pod 2', function (done) { - async.series([ - // Pod 1 quit friends - function (next) { - utils.quitFriends(urls[1], next) - }, - // Pod 1 should not have friends anymore - function (next) { - utils.getFriendsList(urls[1], function (err, res) { - if (err) throw err - - var result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(0) - - next() - }) - }, - // Other pods shouldn't have pod 1 too - function (next) { - async.each([ urls[0], urls[2] ], function (url, callback) { - utils.getFriendsList(url, function (err, res) { - if (err) throw err - - var result = res.body - expect(result).to.be.an('array') - expect(result.length).to.equal(1) - expect(result[0].url).not.to.be.equal(urls[1]) - callback() - }) - }, next) - } - ], done) - }) - - it('Should allow pod 2 to make friend again', function (done) { - utils.makeFriends(urls[1], function () { - async.each(urls, function (url, callback) { - testMadeFriends(urls, url, callback) - }, done) - }) - }) - - after(function (done) { - apps.forEach(function (app) { - process.kill(-app.pid) - }) - - if (this.ok) { - utils.flushTests(done) - } else { - done() - } - }) - }) -})() diff --git a/test/api/index.js b/test/api/index.js deleted file mode 100644 index 3bdcdae2d..000000000 --- a/test/api/index.js +++ /dev/null @@ -1,10 +0,0 @@ -;(function () { - 'use strict' - - // Order of the tests we want to execute - require('./checkParams') - require('./friendsBasic') - require('./singlePod') - require('./multiplePods') - require('./friendsAdvanced') -})() diff --git a/test/api/multiplePods.js b/test/api/multiplePods.js deleted file mode 100644 index b579e5e32..000000000 --- a/test/api/multiplePods.js +++ /dev/null @@ -1,329 +0,0 @@ -;(function () { - 'use strict' - - var async = require('async') - var chai = require('chai') - var expect = chai.expect - - var utils = require('./utils') - var webtorrent = require(__dirname + '/../../src/webTorrentNode') - webtorrent.silent = true - - describe('Test multiple pods', function () { - var apps = [] - var urls = [] - var to_remove = [] - - before(function (done) { - this.timeout(30000) - - async.series([ - // Run servers - function (next) { - utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) { - apps = apps_run - urls = urls_run - next() - }) - }, - // The second pod make friend with the third - function (next) { - utils.makeFriends(urls[1], next) - }, - // Wait for the request between pods - function (next) { - setTimeout(next, 10000) - }, - // Pod 1 make friends too - function (next) { - utils.makeFriends(urls[0], next) - }, - function (next) { - webtorrent.create({ host: 'client', port: '1' }, next) - } - ], done) - }) - - it('Should not have videos for all pods', function (done) { - async.each(urls, function (url, callback) { - utils.getVideosList(url, function (err, res) { - if (err) throw err - - expect(res.body).to.be.an('array') - expect(res.body.length).to.equal(0) - - callback() - }) - }, done) - }) - - describe('Should upload the video and propagate on each pod', function () { - it('Should upload the video on pod 1 and propagate on each pod', function (done) { - this.timeout(15000) - - async.series([ - function (next) { - utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next) - }, - function (next) { - setTimeout(next, 11000) - }], - // All pods should have this video - function (err) { - if (err) throw err - - async.each(urls, function (url, callback) { - var base_magnet = null - - utils.getVideosList(url, function (err, res) { - if (err) throw err - - var videos = res.body - expect(videos).to.be.an('array') - expect(videos.length).to.equal(1) - var video = videos[0] - expect(video.name).to.equal('my super name for pod 1') - expect(video.description).to.equal('my super description for pod 1') - expect(video.podUrl).to.equal('http://localhost:9001') - expect(video.magnetUri).to.exist - - // All pods should have the same magnet Uri - if (base_magnet === null) { - base_magnet = video.magnetUri - } else { - expect(video.magnetUri).to.equal.magnetUri - } - - callback() - }) - }, done) - } - ) - }) - - it('Should upload the video on pod 2 and propagate on each pod', function (done) { - this.timeout(15000) - - async.series([ - function (next) { - utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next) - }, - function (next) { - setTimeout(next, 11000) - }], - // All pods should have this video - function (err) { - if (err) throw err - - async.each(urls, function (url, callback) { - var base_magnet = null - - utils.getVideosList(url, function (err, res) { - if (err) throw err - - var videos = res.body - expect(videos).to.be.an('array') - expect(videos.length).to.equal(2) - var video = videos[1] - expect(video.name).to.equal('my super name for pod 2') - expect(video.description).to.equal('my super description for pod 2') - expect(video.podUrl).to.equal('http://localhost:9002') - expect(video.magnetUri).to.exist - - // All pods should have the same magnet Uri - if (base_magnet === null) { - base_magnet = video.magnetUri - } else { - expect(video.magnetUri).to.equal.magnetUri - } - - callback() - }) - }, done) - } - ) - }) - - it('Should upload two videos on pod 3 and propagate on each pod', function (done) { - this.timeout(30000) - - async.series([ - function (next) { - utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next) - }, - function (next) { - utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next) - }, - function (next) { - setTimeout(next, 22000) - }], - function (err) { - if (err) throw err - - var base_magnet = null - // All pods should have this video - async.each(urls, function (url, callback) { - utils.getVideosList(url, function (err, res) { - if (err) throw err - - var videos = res.body - expect(videos).to.be.an('array') - expect(videos.length).to.equal(4) - var video = videos[2] - expect(video.name).to.equal('my super name for pod 3') - expect(video.description).to.equal('my super description for pod 3') - expect(video.podUrl).to.equal('http://localhost:9003') - expect(video.magnetUri).to.exist - - video = videos[3] - expect(video.name).to.equal('my super name for pod 3-2') - expect(video.description).to.equal('my super description for pod 3-2') - expect(video.podUrl).to.equal('http://localhost:9003') - expect(video.magnetUri).to.exist - - // All pods should have the same magnet Uri - if (base_magnet === null) { - base_magnet = video.magnetUri - } else { - expect(video.magnetUri).to.equal.magnetUri - } - - callback() - }) - }, done) - } - ) - }) - }) - - describe('Should seed the uploaded video', function () { - it('Should add the file 1 by asking pod 3', function (done) { - // Yes, this could be long - this.timeout(200000) - - utils.getVideosList(urls[2], function (err, res) { - if (err) throw err - - var video = res.body[0] - to_remove.push(res.body[2]._id) - to_remove.push(res.body[3]._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('') - - done() - }) - }) - }) - - it('Should add the file 2 by asking pod 1', function (done) { - // Yes, this could be long - this.timeout(200000) - - utils.getVideosList(urls[0], function (err, res) { - if (err) throw err - - var video = res.body[1] - - 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() - }) - }) - }) - - it('Should add the file 3 by asking pod 2', function (done) { - // Yes, this could be long - this.timeout(200000) - - utils.getVideosList(urls[1], function (err, res) { - if (err) throw err - - var video = res.body[2] - - 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() - }) - }) - }) - - it('Should add the file 3-2 by asking pod 1', function (done) { - // Yes, this could be long - this.timeout(200000) - - utils.getVideosList(urls[0], function (err, res) { - if (err) throw err - - var video = res.body[3] - - 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() - }) - }) - }) - - it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { - this.timeout(15000) - - async.series([ - function (next) { - utils.removeVideo(urls[2], to_remove[0], next) - }, - function (next) { - utils.removeVideo(urls[2], to_remove[1], next) - }], - function (err) { - if (err) throw err - setTimeout(done, 11000) - } - ) - }) - - it('Should have videos 1 and 3 on each pod', function (done) { - async.each(urls, function (url, callback) { - utils.getVideosList(url, function (err, res) { - if (err) throw err - - var videos = res.body - expect(videos).to.be.an('array') - expect(videos.length).to.equal(2) - expect(videos[0]._id).not.to.equal(videos[1]._id) - expect(videos[0]._id).not.to.equal(to_remove[0]) - expect(videos[1]._id).not.to.equal(to_remove[0]) - expect(videos[0]._id).not.to.equal(to_remove[1]) - expect(videos[1]._id).not.to.equal(to_remove[1]) - - callback() - }) - }, done) - }) - }) - - after(function (done) { - apps.forEach(function (app) { - process.kill(-app.pid) - }) - process.kill(-webtorrent.app.pid) - - // Keep the logs if the test failed - if (this.ok) { - utils.flushTests(done) - } else { - done() - } - }) - }) -})() diff --git a/test/api/singlePod.js b/test/api/singlePod.js deleted file mode 100644 index a8ae43aee..000000000 --- a/test/api/singlePod.js +++ /dev/null @@ -1,147 +0,0 @@ -;(function () { - 'use strict' - - var async = require('async') - 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') - - describe('Test a single pod', function () { - var app = null - var url = '' - var video_id = -1 - - before(function (done) { - this.timeout(20000) - - async.series([ - function (next) { - utils.flushTests(next) - }, - function (next) { - utils.runServer(1, function (app1, url1) { - app = app1 - url = url1 - next() - }) - }, - function (next) { - webtorrent.create({ host: 'client', port: '1' }, next) - } - ], done) - }) - - it('Should not have videos', function (done) { - utils.getVideosList(url, function (err, res) { - if (err) throw err - - expect(res.body).to.be.an('array') - expect(res.body.length).to.equal(0) - - done() - }) - }) - - it('Should upload the video', function (done) { - this.timeout(5000) - 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) - - utils.getVideosList(url, function (err, res) { - if (err) throw err - - 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 - - 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('') - - done() - }) - }) - }) - - it('Should search the video', function (done) { - 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) - - 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() - }) - }) - - it('Should not find a search', function (done) { - 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) - - done() - }) - }) - - it('Should remove the video', function (done) { - utils.removeVideo(url, video_id, function (err) { - if (err) throw err - - fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) { - if (err) throw err - - expect(files.length).to.equal(0) - done() - }) - }) - }) - - it('Should not have videos', function (done) { - utils.getVideosList(url, function (err, res) { - if (err) throw err - - expect(res.body).to.be.an('array') - expect(res.body.length).to.equal(0) - - done() - }) - }) - - after(function (done) { - process.kill(-app.pid) - process.kill(-webtorrent.app.pid) - - // Keep the logs if the test failed - if (this.ok) { - utils.flushTests(done) - } else { - done() - } - }) - }) -})() diff --git a/test/api/utils.js b/test/api/utils.js deleted file mode 100644 index afb0abb33..000000000 --- a/test/api/utils.js +++ /dev/null @@ -1,182 +0,0 @@ -;(function () { - 'use strict' - - var child_process = require('child_process') - var exec = child_process.exec - var fork = child_process.fork - var request = require('supertest') - - module.exports = { - flushTests: flushTests, - getFriendsList: getFriendsList, - getVideosList: getVideosList, - makeFriends: makeFriends, - quitFriends: quitFriends, - removeVideo: removeVideo, - flushAndRunMultipleServers: flushAndRunMultipleServers, - runServer: runServer, - searchVideo: searchVideo, - uploadVideo: uploadVideo - } - - // ---------------------- Export functions -------------------- - - function flushTests (callback) { - exec(__dirname + '/../../scripts/clean_test.sh', 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 makeFriends (url, expected_status, callback) { - if (!callback) { - callback = expected_status - expected_status = 204 - } - - var path = '/api/v1/pods/makefriends' - - // The first pod make friend with the third - request(url) - .get(path) - .set('Accept', 'application/json') - .expect(expected_status) - .end(function (err, res) { - if (err) throw err - - // Wait for the request between pods - setTimeout(callback, 1000) - }) - } - - function quitFriends (url, callback) { - var path = '/api/v1/pods/quitfriends' - - // 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(callback, 1000) - }) - } - - function removeVideo (url, id, end) { - var path = '/api/v1/videos' - - request(url) - .delete(path + '/' + id) - .set('Accept', 'application/json') - .expect(204) - .end(end) - } - - function flushAndRunMultipleServers (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) - } - - 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) - } -})() diff --git a/test/index.js b/test/index.js deleted file mode 100644 index ccebbfe51..000000000 --- a/test/index.js +++ /dev/null @@ -1,6 +0,0 @@ -;(function () { - 'use strict' - - // Order of the tests we want to execute - require('./api/') -})() -- cgit v1.2.3