X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fplugins%2Fplugin-storage.ts;h=5745914a53b280e920f2ff402513be75ca630838;hb=08642a765ea514a00f159db898edf14c376fbe6c;hp=356692eb9ff42b457a70fbcb18a719f9211bc371;hpb=610d0be13b3d01f653ef269271dd667a57c85ef2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index 356692eb9..5745914a5 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts @@ -1,27 +1,88 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' +import { expect } from 'chai' +import { pathExists, readdir, readFile } from 'fs-extra' +import { join } from 'path' +import { HttpStatusCode } from '@shared/core-utils' +import { + cleanupTests, + createSingleServer, + makeGetRequest, + PeerTubeServer, + PluginsCommand, + setAccessTokensToServers +} from '@shared/extra-utils' describe('Test plugin storage', function () { - let server: ServerInfo + let server: PeerTubeServer before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-six') + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) + }) + + describe('DB storage', function () { + + it('Should correctly store a subkey', async function () { + await server.servers.waitUntilLog('superkey stored value is toto') }) }) - it('Should correctly store a subkey', async function () { - await waitUntilLog(server, 'superkey stored value is toto') + describe('Disk storage', function () { + let dataPath: string + let pluginDataPath: string + + async function getFileContent () { + const files = await readdir(pluginDataPath) + expect(files).to.have.lengthOf(1) + + return readFile(join(pluginDataPath, files[0]), 'utf8') + } + + before(function () { + dataPath = server.servers.buildDirectory('plugins/data') + pluginDataPath = join(dataPath, 'peertube-plugin-test-six') + }) + + it('Should have created the directory on install', async function () { + const dataPath = server.servers.buildDirectory('plugins/data') + const pluginDataPath = join(dataPath, 'peertube-plugin-test-six') + + expect(await pathExists(dataPath)).to.be.true + expect(await pathExists(pluginDataPath)).to.be.true + expect(await readdir(pluginDataPath)).to.have.lengthOf(0) + }) + + it('Should have created a file', async function () { + await makeGetRequest({ + url: server.url, + token: server.accessToken, + path: '/plugins/test-six/router/create-file', + statusCodeExpected: HttpStatusCode.OK_200 + }) + + const content = await getFileContent() + expect(content).to.equal('Prince Ali') + }) + + it('Should still have the file after an uninstallation', async function () { + await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' }) + + const content = await getFileContent() + expect(content).to.equal('Prince Ali') + }) + + it('Should still have the file after the reinstallation', async function () { + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) + + const content = await getFileContent() + expect(content).to.equal('Prince Ali') + }) }) after(async function () {