diff options
Diffstat (limited to 'server/tests/utils')
-rw-r--r-- | server/tests/utils/cli.ts | 24 | ||||
-rw-r--r-- | server/tests/utils/index.ts | 1 | ||||
-rw-r--r-- | server/tests/utils/servers.ts | 9 | ||||
-rw-r--r-- | server/tests/utils/videos.ts | 17 |
4 files changed, 49 insertions, 2 deletions
diff --git a/server/tests/utils/cli.ts b/server/tests/utils/cli.ts new file mode 100644 index 000000000..5f07a832e --- /dev/null +++ b/server/tests/utils/cli.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { exec } from 'child_process' | ||
2 | |||
3 | import { ServerInfo } from './servers' | ||
4 | |||
5 | function getEnvCli (server?: ServerInfo) { | ||
6 | return `NODE_ENV=test NODE_APP_INSTANCE=${server.serverNumber}` | ||
7 | } | ||
8 | |||
9 | async function execCLI (command: string) { | ||
10 | return new Promise((res, rej) => { | ||
11 | exec(command, (err, stdout, stderr) => { | ||
12 | if (err) return rej(err) | ||
13 | |||
14 | return res(stdout) | ||
15 | }) | ||
16 | }) | ||
17 | } | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | export { | ||
22 | execCLI, | ||
23 | getEnvCli | ||
24 | } | ||
diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts index 9077b0568..0fa28f2af 100644 --- a/server/tests/utils/index.ts +++ b/server/tests/utils/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './cli' | ||
1 | export * from './clients' | 2 | export * from './clients' |
2 | export * from './config' | 3 | export * from './config' |
3 | export * from './login' | 4 | export * from './login' |
diff --git a/server/tests/utils/servers.ts b/server/tests/utils/servers.ts index 272a8935e..88027f74e 100644 --- a/server/tests/utils/servers.ts +++ b/server/tests/utils/servers.ts | |||
@@ -5,6 +5,7 @@ interface ServerInfo { | |||
5 | app: ChildProcess, | 5 | app: ChildProcess, |
6 | url: string | 6 | url: string |
7 | host: string | 7 | host: string |
8 | serverNumber: number | ||
8 | 9 | ||
9 | client: { | 10 | client: { |
10 | id: string, | 11 | id: string, |
@@ -65,9 +66,10 @@ function flushTests () { | |||
65 | }) | 66 | }) |
66 | } | 67 | } |
67 | 68 | ||
68 | function runServer (serverNumber: number) { | 69 | function runServer (serverNumber: number, configOverride?: Object) { |
69 | const server: ServerInfo = { | 70 | const server: ServerInfo = { |
70 | app: null, | 71 | app: null, |
72 | serverNumber: serverNumber, | ||
71 | url: `http://localhost:${9000 + serverNumber}`, | 73 | url: `http://localhost:${9000 + serverNumber}`, |
72 | host: `localhost:${9000 + serverNumber}`, | 74 | host: `localhost:${9000 + serverNumber}`, |
73 | client: { | 75 | client: { |
@@ -98,6 +100,11 @@ function runServer (serverNumber: number) { | |||
98 | const env = Object.create(process.env) | 100 | const env = Object.create(process.env) |
99 | env['NODE_ENV'] = 'test' | 101 | env['NODE_ENV'] = 'test' |
100 | env['NODE_APP_INSTANCE'] = serverNumber.toString() | 102 | env['NODE_APP_INSTANCE'] = serverNumber.toString() |
103 | |||
104 | if (configOverride !== undefined) { | ||
105 | env['NODE_CONFIG'] = JSON.stringify(configOverride) | ||
106 | } | ||
107 | |||
101 | const options = { | 108 | const options = { |
102 | silent: true, | 109 | silent: true, |
103 | env: env, | 110 | env: env, |
diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index 42b7dd05a..509a2430a 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts | |||
@@ -1,8 +1,11 @@ | |||
1 | import { readFile } from 'fs' | ||
1 | import * as request from 'supertest' | 2 | import * as request from 'supertest' |
2 | import { join, isAbsolute } from 'path' | 3 | import { join, isAbsolute } from 'path' |
4 | import * as parseTorrent from 'parse-torrent' | ||
3 | 5 | ||
4 | import { makeGetRequest } from './requests' | 6 | import { makeGetRequest } from './requests' |
5 | import { readFilePromise } from './miscs' | 7 | import { readFilePromise } from './miscs' |
8 | import { ServerInfo } from './servers' | ||
6 | 9 | ||
7 | type VideoAttributes = { | 10 | type VideoAttributes = { |
8 | name?: string | 11 | name?: string |
@@ -232,6 +235,17 @@ function rateVideo (url: string, accessToken: string, id: number, rating: string | |||
232 | .expect(specialStatus) | 235 | .expect(specialStatus) |
233 | } | 236 | } |
234 | 237 | ||
238 | function parseTorrentVideo (server: ServerInfo, videoUUID: string) { | ||
239 | return new Promise<any>((res, rej) => { | ||
240 | const torrentPath = join(__dirname, '..', '..', '..', 'test' + server.serverNumber, 'torrents', videoUUID + '.torrent') | ||
241 | readFile(torrentPath, (err, data) => { | ||
242 | if (err) return rej(err) | ||
243 | |||
244 | return res(parseTorrent(data)) | ||
245 | }) | ||
246 | }) | ||
247 | } | ||
248 | |||
235 | // --------------------------------------------------------------------------- | 249 | // --------------------------------------------------------------------------- |
236 | 250 | ||
237 | export { | 251 | export { |
@@ -250,5 +264,6 @@ export { | |||
250 | testVideoImage, | 264 | testVideoImage, |
251 | uploadVideo, | 265 | uploadVideo, |
252 | updateVideo, | 266 | updateVideo, |
253 | rateVideo | 267 | rateVideo, |
268 | parseTorrentVideo | ||
254 | } | 269 | } |