aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/server')
-rw-r--r--shared/extra-utils/server/plugins.ts125
-rw-r--r--shared/extra-utils/server/servers.ts14
2 files changed, 133 insertions, 6 deletions
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts
new file mode 100644
index 000000000..6cd7cd17a
--- /dev/null
+++ b/shared/extra-utils/server/plugins.ts
@@ -0,0 +1,125 @@
1import { makeGetRequest, makePostBodyRequest } from '../requests/requests'
2import { PluginType } from '../../models/plugins/plugin.type'
3
4function listPlugins (parameters: {
5 url: string,
6 accessToken: string,
7 start?: number,
8 count?: number,
9 sort?: string,
10 type?: PluginType,
11 expectedStatus?: number
12}) {
13 const { url, accessToken, start, count, sort, type, expectedStatus = 200 } = parameters
14 const path = '/api/v1/plugins'
15
16 return makeGetRequest({
17 url,
18 path,
19 token: accessToken,
20 query: {
21 start,
22 count,
23 sort,
24 type
25 },
26 statusCodeExpected: expectedStatus
27 })
28}
29
30function getPlugin (parameters: {
31 url: string,
32 accessToken: string,
33 npmName: string,
34 expectedStatus?: number
35}) {
36 const { url, accessToken, npmName, expectedStatus = 200 } = parameters
37 const path = '/api/v1/plugins/' + npmName
38
39 return makeGetRequest({
40 url,
41 path,
42 token: accessToken,
43 statusCodeExpected: expectedStatus
44 })
45}
46
47function getPluginSettings (parameters: {
48 url: string,
49 accessToken: string,
50 npmName: string,
51 expectedStatus?: number
52}) {
53 const { url, accessToken, npmName, expectedStatus = 200 } = parameters
54 const path = '/api/v1/plugins/' + npmName + '/settings'
55
56 return makeGetRequest({
57 url,
58 path,
59 token: accessToken,
60 statusCodeExpected: expectedStatus
61 })
62}
63
64function getPluginRegisteredSettings (parameters: {
65 url: string,
66 accessToken: string,
67 npmName: string,
68 expectedStatus?: number
69}) {
70 const { url, accessToken, npmName, expectedStatus = 200 } = parameters
71 const path = '/api/v1/plugins/' + npmName + '/registered-settings'
72
73 return makeGetRequest({
74 url,
75 path,
76 token: accessToken,
77 statusCodeExpected: expectedStatus
78 })
79}
80
81function installPlugin (parameters: {
82 url: string,
83 accessToken: string,
84 path?: string,
85 npmName?: string
86 expectedStatus?: number
87}) {
88 const { url, accessToken, npmName, path, expectedStatus = 204 } = parameters
89 const apiPath = '/api/v1/plugins/install'
90
91 return makePostBodyRequest({
92 url,
93 path: apiPath,
94 token: accessToken,
95 fields: { npmName, path },
96 statusCodeExpected: expectedStatus
97 })
98}
99
100function uninstallPlugin (parameters: {
101 url: string,
102 accessToken: string,
103 npmName: string
104 expectedStatus?: number
105}) {
106 const { url, accessToken, npmName, expectedStatus = 204 } = parameters
107 const apiPath = '/api/v1/plugins/uninstall'
108
109 return makePostBodyRequest({
110 url,
111 path: apiPath,
112 token: accessToken,
113 fields: { npmName },
114 statusCodeExpected: expectedStatus
115 })
116}
117
118export {
119 listPlugins,
120 installPlugin,
121 getPlugin,
122 uninstallPlugin,
123 getPluginSettings,
124 getPluginRegisteredSettings
125}
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 4c7d6862a..9167ebe5b 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -3,7 +3,7 @@
3import { ChildProcess, exec, fork } from 'child_process' 3import { ChildProcess, exec, fork } from 'child_process'
4import { join } from 'path' 4import { join } from 'path'
5import { root, wait } from '../miscs/miscs' 5import { root, wait } from '../miscs/miscs'
6import { copy, readdir, readFile, remove } from 'fs-extra' 6import { copy, pathExists, readdir, readFile, remove } from 'fs-extra'
7import { existsSync } from 'fs' 7import { existsSync } from 'fs'
8import { expect } from 'chai' 8import { expect } from 'chai'
9import { VideoChannel } from '../../models/videos' 9import { VideoChannel } from '../../models/videos'
@@ -241,20 +241,22 @@ async function reRunServer (server: ServerInfo, configOverride?: any) {
241 return server 241 return server
242} 242}
243 243
244async function checkTmpIsEmpty (server: ServerInfo) { 244function checkTmpIsEmpty (server: ServerInfo) {
245 return checkDirectoryIsEmpty(server, 'tmp') 245 return checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css' ])
246} 246}
247 247
248async function checkDirectoryIsEmpty (server: ServerInfo, directory: string) { 248async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exceptions: string[] = []) {
249 const testDirectory = 'test' + server.internalServerNumber 249 const testDirectory = 'test' + server.internalServerNumber
250 250
251 const directoryPath = join(root(), testDirectory, directory) 251 const directoryPath = join(root(), testDirectory, directory)
252 252
253 const directoryExists = existsSync(directoryPath) 253 const directoryExists = await pathExists(directoryPath)
254 expect(directoryExists).to.be.true 254 expect(directoryExists).to.be.true
255 255
256 const files = await readdir(directoryPath) 256 const files = await readdir(directoryPath)
257 expect(files).to.have.lengthOf(0) 257 const filtered = files.filter(f => exceptions.includes(f) === false)
258
259 expect(filtered).to.have.lengthOf(0)
258} 260}
259 261
260function killallServers (servers: ServerInfo[]) { 262function killallServers (servers: ServerInfo[]) {