]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Tests that show the bug.
authorJohn Livingston <git@john-livingston.fr>
Thu, 8 Apr 2021 15:19:12 +0000 (17:19 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 9 Apr 2021 07:32:16 +0000 (09:32 +0200)
server/tests/fixtures/peertube-plugin-test-unloading/lib.js [new file with mode: 0644]
server/tests/fixtures/peertube-plugin-test-unloading/main.js [new file with mode: 0644]
server/tests/fixtures/peertube-plugin-test-unloading/package.json [new file with mode: 0644]
server/tests/plugins/index.ts
server/tests/plugins/plugin-unloading.ts [new file with mode: 0644]

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 (file)
index 0000000..f57e7cb
--- /dev/null
@@ -0,0 +1,2 @@
+const d = new Date()
+exports.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 (file)
index 0000000..5c8457c
--- /dev/null
@@ -0,0 +1,14 @@
+const lib = require('./lib')
+
+async function register ({ getRouter }) {
+  const router = getRouter()
+  router.get('/get', (req, res) => res.json({ message: lib.value }))
+}
+
+async function unregister () {
+}
+
+module.exports = {
+  register,
+  unregister
+}
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 (file)
index 0000000..7076d4b
--- /dev/null
@@ -0,0 +1,20 @@
+{
+  "name": "peertube-plugin-test-unloading",
+  "version": "0.0.1",
+  "description": "Plugin test (modules unloading)",
+  "engine": {
+    "peertube": ">=1.3.0"
+  },
+  "keywords": [
+    "peertube",
+    "plugin"
+  ],
+  "homepage": "https://github.com/Chocobozzz/PeerTube",
+  "author": "Chocobozzz",
+  "bugs": "https://github.com/Chocobozzz/PeerTube/issues",
+  "library": "./main.js",
+  "staticDirs": {},
+  "css": [],
+  "clientScripts": [],
+  "translations": {}
+}
index fd7116efdc180899f7baf3dc9fdf9a8914741597..4534120fd171d219f9c3b67efee1b9ccd1ba1f3b 100644 (file)
@@ -7,5 +7,6 @@ import './plugin-helpers'
 import './plugin-router'
 import './plugin-storage'
 import './plugin-transcoding'
+import './plugin-unloading'
 import './translations'
 import './video-constants'
diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts
new file mode 100644 (file)
index 0000000..74ca82e
--- /dev/null
@@ -0,0 +1,89 @@
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+
+import 'mocha'
+import {
+  cleanupTests,
+  flushAndRunServer,
+  getPluginTestPath,
+  makeGetRequest,
+  installPlugin,
+  uninstallPlugin,
+  ServerInfo,
+  setAccessTokensToServers
+} from '../../../shared/extra-utils'
+import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
+import { expect } from 'chai'
+
+describe('Test plugins module unloading', function () {
+  let server: ServerInfo = null
+  const requestPath = '/plugins/test-unloading/router/get'
+  let value: string = null
+
+  before(async function () {
+    this.timeout(30000)
+
+    server = await flushAndRunServer(1)
+    await setAccessTokensToServers([ server ])
+
+    await installPlugin({
+      url: server.url,
+      accessToken: server.accessToken,
+      path: getPluginTestPath('-unloading')
+    })
+  })
+
+  it('Should return a numeric value', async function () {
+    const res = await makeGetRequest({
+      url: server.url,
+      path: requestPath,
+      statusCodeExpected: HttpStatusCode.OK_200
+    })
+
+    expect(res.body.message).to.match(/^\d+$/)
+    value = res.body.message
+  })
+
+  it('Should return the same value the second time', async function () {
+    const res = await makeGetRequest({
+      url: server.url,
+      path: requestPath,
+      statusCodeExpected: HttpStatusCode.OK_200
+    })
+
+    expect(res.body.message).to.be.equal(value)
+  })
+
+  it('Should uninstall the plugin and free the route', async function () {
+    await uninstallPlugin({
+      url: server.url,
+      accessToken: server.accessToken,
+      npmName: 'peertube-plugin-test-unloading'
+    })
+
+    await makeGetRequest({
+      url: server.url,
+      path: requestPath,
+      statusCodeExpected: HttpStatusCode.NOT_FOUND_404
+    })
+  })
+
+  it('Should return a different numeric value', async function () {
+    await installPlugin({
+      url: server.url,
+      accessToken: server.accessToken,
+      path: getPluginTestPath('-unloading')
+    })
+    const res = await makeGetRequest({
+      url: server.url,
+      path: requestPath,
+      statusCodeExpected: HttpStatusCode.OK_200
+    })
+
+    expect(res.body.message).to.match(/^\d+$/)
+    expect(res.body.message).to.be.not.equal(value)
+  })
+
+  after(async function () {
+    await cleanupTests([ server ])
+  })
+})