aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/api/multiplePods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-12-06 17:09:07 +0100
committerChocobozzz <florian.bigard@gmail.com>2015-12-07 17:22:36 +0100
commit876d1bcfd07b14d47ba377474e3bb680872d1f7a (patch)
tree4400850a7e4e6b7140ef9cea289784eb21f972b3 /test/api/multiplePods.js
parent4d5f813870683c29af6b9959efa9fd4c4ea5e3b7 (diff)
downloadPeerTube-876d1bcfd07b14d47ba377474e3bb680872d1f7a.tar.gz
PeerTube-876d1bcfd07b14d47ba377474e3bb680872d1f7a.tar.zst
PeerTube-876d1bcfd07b14d47ba377474e3bb680872d1f7a.zip
Tests refractoring
Diffstat (limited to 'test/api/multiplePods.js')
-rw-r--r--test/api/multiplePods.js97
1 files changed, 29 insertions, 68 deletions
diff --git a/test/api/multiplePods.js b/test/api/multiplePods.js
index 3ce57afa8..dd666d73e 100644
--- a/test/api/multiplePods.js
+++ b/test/api/multiplePods.js
@@ -1,86 +1,47 @@
1;(function () { 1;(function () {
2 'use strict' 2 'use strict'
3 3
4 var request = require('supertest') 4 var async = require('async')
5 var chai = require('chai') 5 var chai = require('chai')
6 var expect = chai.expect 6 var expect = chai.expect
7 var async = require('async')
8 7
9 var utils = require('../utils') 8 var utils = require('./utils')
10 var webtorrent = require(__dirname + '/../../src/webTorrentNode') 9 var webtorrent = require(__dirname + '/../../src/webTorrentNode')
11 webtorrent.silent = true 10 webtorrent.silent = true
12 11
13 describe('Test multiple pods', function () { 12 describe('Test multiple pods', function () {
14 var path = '/api/v1/videos'
15 var apps = [] 13 var apps = []
16 var urls = [] 14 var urls = []
17 var to_remove = [] 15 var to_remove = []
18 16
19 function getVideosList (url, end) {
20 request(url)
21 .get(path)
22 .set('Accept', 'application/json')
23 .expect(200)
24 .expect('Content-Type', /json/)
25 .end(end)
26 }
27
28 function uploadVideo (url, name, description, fixture, end) {
29 request(url)
30 .post(path)
31 .set('Accept', 'application/json')
32 .field('name', name)
33 .field('description', description)
34 .attach('input_video', __dirname + '/../fixtures/' + fixture)
35 .expect(201)
36 .end(end)
37 }
38
39 function removeVideo (url, id, end) {
40 request(url)
41 .delete(path + '/' + id)
42 .set('Accept', 'application/json')
43 .expect(204)
44 .end(end)
45 }
46
47 before(function (done) { 17 before(function (done) {
48 this.timeout(30000) 18 this.timeout(30000)
49 var path_friends = '/api/v1/pods/makefriends'
50 19
51 utils.runMultipleServers(3, function (apps_run, urls_run) { 20 utils.runMultipleServers(3, function (apps_run, urls_run) {
52 apps = apps_run 21 apps = apps_run
53 urls = urls_run 22 urls = urls_run
54 23
55 // The second pod make friend with the third 24 // The second pod make friend with the third
56 request(urls[1]) 25 utils.makeFriend(urls[1], function (err, res) {
57 .get(path_friends) 26 if (err) throw err
58 .set('Accept', 'application/json')
59 .expect(204)
60 .end(function (err, res) {
61 if (err) throw err
62 27
63 // Wait for the request between pods 28 // Wait for the request between pods
64 setTimeout(function () { 29 setTimeout(function () {
65 request(urls[0]) 30 utils.makeFriend(urls[0], function (err, res) {
66 .get(path_friends) 31 if (err) throw err
67 .set('Accept', 'application/json')
68 .expect(204)
69 .end(function (err, res) {
70 if (err) throw err
71 32
72 webtorrent.create({ host: 'client', port: '1' }, function () { 33 webtorrent.create({ host: 'client', port: '1' }, function () {
73 done() 34 done()
74 }) 35 })
75 }) 36 })
76 }, 10000) 37 }, 10000)
77 }) 38 })
78 }) 39 })
79 }) 40 })
80 41
81 it('Should not have videos for all pods', function (done) { 42 it('Should not have videos for all pods', function (done) {
82 async.each(urls, function (url, callback) { 43 async.each(urls, function (url, callback) {
83 getVideosList(url, function (err, res) { 44 utils.getVideosList(url, function (err, res) {
84 if (err) throw err 45 if (err) throw err
85 46
86 expect(res.body).to.be.an('array') 47 expect(res.body).to.be.an('array')
@@ -99,7 +60,7 @@
99 it('Should upload the video on pod 1 and propagate on each pod', function (done) { 60 it('Should upload the video on pod 1 and propagate on each pod', function (done) {
100 this.timeout(15000) 61 this.timeout(15000)
101 62
102 uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err) { 63 utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', function (err) {
103 if (err) throw err 64 if (err) throw err
104 65
105 setTimeout(function () { 66 setTimeout(function () {
@@ -107,7 +68,7 @@
107 async.each(urls, function (url, callback) { 68 async.each(urls, function (url, callback) {
108 var base_magnet = null 69 var base_magnet = null
109 70
110 getVideosList(url, function (err, res) { 71 utils.getVideosList(url, function (err, res) {
111 if (err) throw err 72 if (err) throw err
112 73
113 var videos = res.body 74 var videos = res.body
@@ -140,7 +101,7 @@
140 it('Should upload the video on pod 2 and propagate on each pod', function (done) { 101 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
141 this.timeout(15000) 102 this.timeout(15000)
142 103
143 uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err) { 104 utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', function (err) {
144 if (err) throw err 105 if (err) throw err
145 106
146 setTimeout(function () { 107 setTimeout(function () {
@@ -148,7 +109,7 @@
148 async.each(urls, function (url, callback) { 109 async.each(urls, function (url, callback) {
149 var base_magnet = null 110 var base_magnet = null
150 111
151 getVideosList(url, function (err, res) { 112 utils.getVideosList(url, function (err, res) {
152 if (err) throw err 113 if (err) throw err
153 114
154 var videos = res.body 115 var videos = res.body
@@ -181,16 +142,16 @@
181 it('Should upload two videos on pod 3 and propagate on each pod', function (done) { 142 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
182 this.timeout(15000) 143 this.timeout(15000)
183 144
184 uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err) { 145 utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', function (err) {
185 if (err) throw err 146 if (err) throw err
186 uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', function (err) { 147 utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', function (err) {
187 if (err) throw err 148 if (err) throw err
188 149
189 setTimeout(function () { 150 setTimeout(function () {
190 var base_magnet = null 151 var base_magnet = null
191 // All pods should have this video 152 // All pods should have this video
192 async.each(urls, function (url, callback) { 153 async.each(urls, function (url, callback) {
193 getVideosList(url, function (err, res) { 154 utils.getVideosList(url, function (err, res) {
194 if (err) throw err 155 if (err) throw err
195 156
196 var videos = res.body 157 var videos = res.body
@@ -233,7 +194,7 @@
233 // Yes, this could be long 194 // Yes, this could be long
234 this.timeout(200000) 195 this.timeout(200000)
235 196
236 getVideosList(urls[2], function (err, res) { 197 utils.getVideosList(urls[2], function (err, res) {
237 if (err) throw err 198 if (err) throw err
238 199
239 var video = res.body[0] 200 var video = res.body[0]
@@ -254,7 +215,7 @@
254 // Yes, this could be long 215 // Yes, this could be long
255 this.timeout(200000) 216 this.timeout(200000)
256 217
257 getVideosList(urls[0], function (err, res) { 218 utils.getVideosList(urls[0], function (err, res) {
258 if (err) throw err 219 if (err) throw err
259 220
260 var video = res.body[1] 221 var video = res.body[1]
@@ -273,7 +234,7 @@
273 // Yes, this could be long 234 // Yes, this could be long
274 this.timeout(200000) 235 this.timeout(200000)
275 236
276 getVideosList(urls[1], function (err, res) { 237 utils.getVideosList(urls[1], function (err, res) {
277 if (err) throw err 238 if (err) throw err
278 239
279 var video = res.body[2] 240 var video = res.body[2]
@@ -292,7 +253,7 @@
292 // Yes, this could be long 253 // Yes, this could be long
293 this.timeout(200000) 254 this.timeout(200000)
294 255
295 getVideosList(urls[0], function (err, res) { 256 utils.getVideosList(urls[0], function (err, res) {
296 if (err) throw err 257 if (err) throw err
297 258
298 var video = res.body[3] 259 var video = res.body[3]
@@ -310,9 +271,9 @@
310 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { 271 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
311 this.timeout(15000) 272 this.timeout(15000)
312 273
313 removeVideo(urls[2], to_remove[0], function (err) { 274 utils.removeVideo(urls[2], to_remove[0], function (err) {
314 if (err) throw err 275 if (err) throw err
315 removeVideo(urls[2], to_remove[1], function (err) { 276 utils.removeVideo(urls[2], to_remove[1], function (err) {
316 if (err) throw err 277 if (err) throw err
317 278
318 // Wait the propagation to the other pods 279 // Wait the propagation to the other pods
@@ -325,7 +286,7 @@
325 286
326 it('Should have videos 1 and 3 on each pod', function (done) { 287 it('Should have videos 1 and 3 on each pod', function (done) {
327 async.each(urls, function (url, callback) { 288 async.each(urls, function (url, callback) {
328 getVideosList(url, function (err, res) { 289 utils.getVideosList(url, function (err, res) {
329 if (err) throw err 290 if (err) throw err
330 291
331 var videos = res.body 292 var videos = res.body