aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/shared/peertube-runner-process.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-21 15:00:01 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commitd102de1b38f2877463529c3b27bd35ffef4fd8bf (patch)
tree31fa0bdf26ad7a2ee46d600d804a6f03260266c8 /server/tests/shared/peertube-runner-process.ts
parent2fe978744e5b74eb824e4d79c1bb9b840169f125 (diff)
downloadPeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.gz
PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.zst
PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.zip
Add runner server tests
Diffstat (limited to 'server/tests/shared/peertube-runner-process.ts')
-rw-r--r--server/tests/shared/peertube-runner-process.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/server/tests/shared/peertube-runner-process.ts b/server/tests/shared/peertube-runner-process.ts
new file mode 100644
index 000000000..84e2dc6df
--- /dev/null
+++ b/server/tests/shared/peertube-runner-process.ts
@@ -0,0 +1,87 @@
1import { ChildProcess, fork } from 'child_process'
2import execa from 'execa'
3import { join } from 'path'
4import { root } from '@shared/core-utils'
5import { PeerTubeServer } from '@shared/server-commands'
6
7export class PeerTubeRunnerProcess {
8 private app?: ChildProcess
9
10 runServer (options: {
11 hideLogs?: boolean // default true
12 } = {}) {
13 const { hideLogs = true } = options
14
15 return new Promise<void>((res, rej) => {
16 const args = [ 'server', '--verbose', '--id', 'test' ]
17
18 const forkOptions = {
19 detached: false,
20 silent: true
21 }
22 this.app = fork(this.getRunnerPath(), args, forkOptions)
23
24 this.app.stdout.on('data', data => {
25 const str = data.toString() as string
26
27 if (!hideLogs) {
28 console.log(str)
29 }
30 })
31
32 res()
33 })
34 }
35
36 registerPeerTubeInstance (options: {
37 server: PeerTubeServer
38 registrationToken: string
39 runnerName: string
40 runnerDescription?: string
41 }) {
42 const { server, registrationToken, runnerName, runnerDescription } = options
43
44 const args = [
45 'register',
46 '--url', server.url,
47 '--registration-token', registrationToken,
48 '--runner-name', runnerName,
49 '--id', 'test'
50 ]
51
52 if (runnerDescription) {
53 args.push('--runner-description')
54 args.push(runnerDescription)
55 }
56
57 return execa.node(this.getRunnerPath(), args)
58 }
59
60 unregisterPeerTubeInstance (options: {
61 server: PeerTubeServer
62 }) {
63 const { server } = options
64
65 const args = [ 'unregister', '--url', server.url, '--id', 'test' ]
66 return execa.node(this.getRunnerPath(), args)
67 }
68
69 async listRegisteredPeerTubeInstances () {
70 const args = [ 'list-registered', '--id', 'test' ]
71 const { stdout } = await execa.node(this.getRunnerPath(), args)
72
73 return stdout
74 }
75
76 kill () {
77 if (!this.app) return
78
79 process.kill(this.app.pid)
80
81 this.app = null
82 }
83
84 private getRunnerPath () {
85 return join(root(), 'packages', 'peertube-runner', 'dist', 'peertube-runner.js')
86 }
87}