aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/tests/external-plugins/auto-block-videos.ts5
-rw-r--r--server/tests/external-plugins/auto-mute.ts5
-rw-r--r--shared/extra-utils/plugins/mock-blocklist.ts6
3 files changed, 10 insertions, 6 deletions
diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.ts
index 1b91d141e..18ea17d78 100644
--- a/server/tests/external-plugins/auto-block-videos.ts
+++ b/server/tests/external-plugins/auto-block-videos.ts
@@ -40,6 +40,7 @@ describe('Official plugin auto-block videos', function () {
40 let blocklistServer: MockBlocklist 40 let blocklistServer: MockBlocklist
41 let server1Videos: Video[] = [] 41 let server1Videos: Video[] = []
42 let server2Videos: Video[] = [] 42 let server2Videos: Video[] = []
43 let port: number
43 44
44 before(async function () { 45 before(async function () {
45 this.timeout(60000) 46 this.timeout(60000)
@@ -56,7 +57,7 @@ describe('Official plugin auto-block videos', function () {
56 } 57 }
57 58
58 blocklistServer = new MockBlocklist() 59 blocklistServer = new MockBlocklist()
59 await blocklistServer.initialize() 60 port = await blocklistServer.initialize()
60 61
61 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) 62 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
62 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) 63 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
@@ -82,7 +83,7 @@ describe('Official plugin auto-block videos', function () {
82 accessToken: servers[0].accessToken, 83 accessToken: servers[0].accessToken,
83 npmName: 'peertube-plugin-auto-block-videos', 84 npmName: 'peertube-plugin-auto-block-videos',
84 settings: { 85 settings: {
85 'blocklist-urls': 'http://localhost:42100/blocklist', 86 'blocklist-urls': `http://localhost:${port}/blocklist`,
86 'check-seconds-interval': 1 87 'check-seconds-interval': 1
87 } 88 }
88 }) 89 })
diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts
index 687f56e98..09355d932 100644
--- a/server/tests/external-plugins/auto-mute.ts
+++ b/server/tests/external-plugins/auto-mute.ts
@@ -31,6 +31,7 @@ describe('Official plugin auto-mute', function () {
31 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' 31 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
32 let servers: ServerInfo[] 32 let servers: ServerInfo[]
33 let blocklistServer: MockBlocklist 33 let blocklistServer: MockBlocklist
34 let port: number
34 35
35 before(async function () { 36 before(async function () {
36 this.timeout(30000) 37 this.timeout(30000)
@@ -47,7 +48,7 @@ describe('Official plugin auto-mute', function () {
47 } 48 }
48 49
49 blocklistServer = new MockBlocklist() 50 blocklistServer = new MockBlocklist()
50 await blocklistServer.initialize() 51 port = await blocklistServer.initialize()
51 52
52 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) 53 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
53 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) 54 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
@@ -61,7 +62,7 @@ describe('Official plugin auto-mute', function () {
61 accessToken: servers[0].accessToken, 62 accessToken: servers[0].accessToken,
62 npmName: 'peertube-plugin-auto-mute', 63 npmName: 'peertube-plugin-auto-mute',
63 settings: { 64 settings: {
64 'blocklist-urls': 'http://localhost:42100/blocklist', 65 'blocklist-urls': `http://localhost:${port}/blocklist`,
65 'check-seconds-interval': 1 66 'check-seconds-interval': 1
66 } 67 }
67 }) 68 })
diff --git a/shared/extra-utils/plugins/mock-blocklist.ts b/shared/extra-utils/plugins/mock-blocklist.ts
index 50e2289f1..d18f8224f 100644
--- a/shared/extra-utils/plugins/mock-blocklist.ts
+++ b/shared/extra-utils/plugins/mock-blocklist.ts
@@ -1,5 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { Server } from 'http' 2import { Server } from 'http'
3import { randomInt } from '@shared/core-utils'
3 4
4type BlocklistResponse = { 5type BlocklistResponse = {
5 data: { 6 data: {
@@ -14,14 +15,15 @@ export class MockBlocklist {
14 private server: Server 15 private server: Server
15 16
16 initialize () { 17 initialize () {
17 return new Promise<void>(res => { 18 return new Promise<number>(res => {
18 const app = express() 19 const app = express()
19 20
20 app.get('/blocklist', (req: express.Request, res: express.Response) => { 21 app.get('/blocklist', (req: express.Request, res: express.Response) => {
21 return res.json(this.body) 22 return res.json(this.body)
22 }) 23 })
23 24
24 this.server = app.listen(42100, () => res()) 25 const port = 42201 + randomInt(1, 100)
26 this.server = app.listen(port, () => res(port))
25 }) 27 })
26 } 28 }
27 29