]>
Commit | Line | Data |
---|---|---|
97b65ce5 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
302eba0d C |
4 | import { expect } from 'chai' |
5 | import { pathExists, readdir, readFile } from 'fs-extra' | |
6 | import { join } from 'path' | |
7 | import { HttpStatusCode } from '@shared/core-utils' | |
8 | import { | |
9 | buildServerDirectory, | |
ae2abfd3 C |
10 | cleanupTests, |
11 | flushAndRunServer, | |
302eba0d | 12 | makeGetRequest, |
ae2abfd3 C |
13 | PluginsCommand, |
14 | ServerInfo, | |
302eba0d | 15 | setAccessTokensToServers, |
ae2abfd3 C |
16 | waitUntilLog |
17 | } from '@shared/extra-utils' | |
97b65ce5 C |
18 | |
19 | describe('Test plugin storage', function () { | |
20 | let server: ServerInfo | |
21 | ||
22 | before(async function () { | |
23 | this.timeout(30000) | |
24 | ||
25 | server = await flushAndRunServer(1) | |
26 | await setAccessTokensToServers([ server ]) | |
27 | ||
ae2abfd3 | 28 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') }) |
97b65ce5 C |
29 | }) |
30 | ||
302eba0d C |
31 | describe('DB storage', function () { |
32 | ||
33 | it('Should correctly store a subkey', async function () { | |
34 | await waitUntilLog(server, 'superkey stored value is toto') | |
35 | }) | |
36 | }) | |
37 | ||
38 | describe('Disk storage', function () { | |
39 | let dataPath: string | |
40 | let pluginDataPath: string | |
41 | ||
42 | async function getFileContent () { | |
43 | const files = await readdir(pluginDataPath) | |
44 | expect(files).to.have.lengthOf(1) | |
45 | ||
46 | return readFile(join(pluginDataPath, files[0]), 'utf8') | |
47 | } | |
48 | ||
49 | before(function () { | |
50 | dataPath = buildServerDirectory(server, 'plugins/data') | |
51 | pluginDataPath = join(dataPath, 'peertube-plugin-test-six') | |
52 | }) | |
53 | ||
54 | it('Should have created the directory on install', async function () { | |
55 | const dataPath = buildServerDirectory(server, 'plugins/data') | |
56 | const pluginDataPath = join(dataPath, 'peertube-plugin-test-six') | |
57 | ||
58 | expect(await pathExists(dataPath)).to.be.true | |
59 | expect(await pathExists(pluginDataPath)).to.be.true | |
60 | expect(await readdir(pluginDataPath)).to.have.lengthOf(0) | |
61 | }) | |
62 | ||
63 | it('Should have created a file', async function () { | |
64 | await makeGetRequest({ | |
65 | url: server.url, | |
66 | token: server.accessToken, | |
67 | path: '/plugins/test-six/router/create-file', | |
68 | statusCodeExpected: HttpStatusCode.OK_200 | |
69 | }) | |
70 | ||
71 | const content = await getFileContent() | |
72 | expect(content).to.equal('Prince Ali') | |
73 | }) | |
74 | ||
75 | it('Should still have the file after an uninstallation', async function () { | |
ae2abfd3 | 76 | await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-six' }) |
302eba0d C |
77 | |
78 | const content = await getFileContent() | |
79 | expect(content).to.equal('Prince Ali') | |
80 | }) | |
81 | ||
82 | it('Should still have the file after the reinstallation', async function () { | |
ae2abfd3 | 83 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') }) |
302eba0d C |
84 | |
85 | const content = await getFileContent() | |
86 | expect(content).to.equal('Prince Ali') | |
87 | }) | |
97b65ce5 C |
88 | }) |
89 | ||
90 | after(async function () { | |
91 | await cleanupTests([ server ]) | |
92 | }) | |
93 | }) |