aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorJohn Livingston <git@john-livingston.fr>2021-04-08 17:19:12 +0200
committerChocobozzz <me@florianbigard.com>2021-04-09 09:32:16 +0200
commit41137192096590b171563bc3161ede6f5c1d15db (patch)
treece1eec2f632ef1f8286b1b55e12d89154930ec84 /server
parentdc48fdbe68e9dd3a3a6028181e61d8595d98e654 (diff)
downloadPeerTube-41137192096590b171563bc3161ede6f5c1d15db.tar.gz
PeerTube-41137192096590b171563bc3161ede6f5c1d15db.tar.zst
PeerTube-41137192096590b171563bc3161ede6f5c1d15db.zip
Tests that show the bug.
Diffstat (limited to 'server')
-rw-r--r--server/tests/fixtures/peertube-plugin-test-unloading/lib.js2
-rw-r--r--server/tests/fixtures/peertube-plugin-test-unloading/main.js14
-rw-r--r--server/tests/fixtures/peertube-plugin-test-unloading/package.json20
-rw-r--r--server/tests/plugins/index.ts1
-rw-r--r--server/tests/plugins/plugin-unloading.ts89
5 files changed, 126 insertions, 0 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-unloading/lib.js b/server/tests/fixtures/peertube-plugin-test-unloading/lib.js
new file mode 100644
index 000000000..f57e7cb01
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-unloading/lib.js
@@ -0,0 +1,2 @@
1const d = new Date()
2exports.value = d.getTime()
diff --git a/server/tests/fixtures/peertube-plugin-test-unloading/main.js b/server/tests/fixtures/peertube-plugin-test-unloading/main.js
new file mode 100644
index 000000000..5c8457cef
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-unloading/main.js
@@ -0,0 +1,14 @@
1const lib = require('./lib')
2
3async function register ({ getRouter }) {
4 const router = getRouter()
5 router.get('/get', (req, res) => res.json({ message: lib.value }))
6}
7
8async function unregister () {
9}
10
11module.exports = {
12 register,
13 unregister
14}
diff --git a/server/tests/fixtures/peertube-plugin-test-unloading/package.json b/server/tests/fixtures/peertube-plugin-test-unloading/package.json
new file mode 100644
index 000000000..7076d4b6f
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-unloading/package.json
@@ -0,0 +1,20 @@
1{
2 "name": "peertube-plugin-test-unloading",
3 "version": "0.0.1",
4 "description": "Plugin test (modules unloading)",
5 "engine": {
6 "peertube": ">=1.3.0"
7 },
8 "keywords": [
9 "peertube",
10 "plugin"
11 ],
12 "homepage": "https://github.com/Chocobozzz/PeerTube",
13 "author": "Chocobozzz",
14 "bugs": "https://github.com/Chocobozzz/PeerTube/issues",
15 "library": "./main.js",
16 "staticDirs": {},
17 "css": [],
18 "clientScripts": [],
19 "translations": {}
20}
diff --git a/server/tests/plugins/index.ts b/server/tests/plugins/index.ts
index fd7116efd..4534120fd 100644
--- a/server/tests/plugins/index.ts
+++ b/server/tests/plugins/index.ts
@@ -7,5 +7,6 @@ import './plugin-helpers'
7import './plugin-router' 7import './plugin-router'
8import './plugin-storage' 8import './plugin-storage'
9import './plugin-transcoding' 9import './plugin-transcoding'
10import './plugin-unloading'
10import './translations' 11import './translations'
11import './video-constants' 12import './video-constants'
diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts
new file mode 100644
index 000000000..74ca82e2f
--- /dev/null
+++ b/server/tests/plugins/plugin-unloading.ts
@@ -0,0 +1,89 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import {
5 cleanupTests,
6 flushAndRunServer,
7 getPluginTestPath,
8 makeGetRequest,
9 installPlugin,
10 uninstallPlugin,
11 ServerInfo,
12 setAccessTokensToServers
13} from '../../../shared/extra-utils'
14import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
15import { expect } from 'chai'
16
17describe('Test plugins module unloading', function () {
18 let server: ServerInfo = null
19 const requestPath = '/plugins/test-unloading/router/get'
20 let value: string = null
21
22 before(async function () {
23 this.timeout(30000)
24
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
27
28 await installPlugin({
29 url: server.url,
30 accessToken: server.accessToken,
31 path: getPluginTestPath('-unloading')
32 })
33 })
34
35 it('Should return a numeric value', async function () {
36 const res = await makeGetRequest({
37 url: server.url,
38 path: requestPath,
39 statusCodeExpected: HttpStatusCode.OK_200
40 })
41
42 expect(res.body.message).to.match(/^\d+$/)
43 value = res.body.message
44 })
45
46 it('Should return the same value the second time', async function () {
47 const res = await makeGetRequest({
48 url: server.url,
49 path: requestPath,
50 statusCodeExpected: HttpStatusCode.OK_200
51 })
52
53 expect(res.body.message).to.be.equal(value)
54 })
55
56 it('Should uninstall the plugin and free the route', async function () {
57 await uninstallPlugin({
58 url: server.url,
59 accessToken: server.accessToken,
60 npmName: 'peertube-plugin-test-unloading'
61 })
62
63 await makeGetRequest({
64 url: server.url,
65 path: requestPath,
66 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
67 })
68 })
69
70 it('Should return a different numeric value', async function () {
71 await installPlugin({
72 url: server.url,
73 accessToken: server.accessToken,
74 path: getPluginTestPath('-unloading')
75 })
76 const res = await makeGetRequest({
77 url: server.url,
78 path: requestPath,
79 statusCodeExpected: HttpStatusCode.OK_200
80 })
81
82 expect(res.body.message).to.match(/^\d+$/)
83 expect(res.body.message).to.be.not.equal(value)
84 })
85
86 after(async function () {
87 await cleanupTests([ server ])
88 })
89})