2020-05-04 09:44:00 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
2021-04-22 10:55:28 +02:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { pathExists, readdir, readFile } from 'fs-extra'
|
|
|
|
import { join } from 'path'
|
2021-07-16 09:47:51 +02:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createSingleServer,
|
|
|
|
makeGetRequest,
|
|
|
|
PeerTubeServer,
|
|
|
|
PluginsCommand,
|
|
|
|
setAccessTokensToServers
|
2021-12-17 09:29:23 +01:00
|
|
|
} from '@shared/server-commands'
|
2021-07-16 14:27:30 +02:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2020-05-04 09:44:00 +02:00
|
|
|
|
|
|
|
describe('Test plugin storage', function () {
|
2021-07-16 09:47:51 +02:00
|
|
|
let server: PeerTubeServer
|
2020-05-04 09:44:00 +02:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
server = await createSingleServer(1)
|
2020-05-04 09:44:00 +02:00
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
|
2020-05-04 09:44:00 +02:00
|
|
|
})
|
|
|
|
|
2021-04-22 10:55:28 +02:00
|
|
|
describe('DB storage', function () {
|
|
|
|
it('Should correctly store a subkey', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.servers.waitUntilLog('superkey stored value is toto')
|
2021-04-22 10:55:28 +02:00
|
|
|
})
|
2021-12-15 09:35:17 +01:00
|
|
|
|
|
|
|
it('Should correctly retrieve an array as array from the storage.', async function () {
|
2021-12-16 10:15:27 +01:00
|
|
|
await server.servers.waitUntilLog('storedArrayKey isArray is true')
|
2021-12-15 09:35:17 +01:00
|
|
|
await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2')
|
|
|
|
})
|
2021-04-22 10:55:28 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
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 () {
|
2021-07-16 09:04:35 +02:00
|
|
|
dataPath = server.servers.buildDirectory('plugins/data')
|
2021-04-22 10:55:28 +02:00
|
|
|
pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have created the directory on install', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
const dataPath = server.servers.buildDirectory('plugins/data')
|
2021-04-22 10:55:28 +02:00
|
|
|
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',
|
2021-07-16 10:42:24 +02:00
|
|
|
expectedStatus: HttpStatusCode.OK_200
|
2021-04-22 10:55:28 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const content = await getFileContent()
|
|
|
|
expect(content).to.equal('Prince Ali')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should still have the file after an uninstallation', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
|
2021-04-22 10:55:28 +02:00
|
|
|
|
|
|
|
const content = await getFileContent()
|
|
|
|
expect(content).to.equal('Prince Ali')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should still have the file after the reinstallation', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
|
2021-04-22 10:55:28 +02:00
|
|
|
|
|
|
|
const content = await getFileContent()
|
|
|
|
expect(content).to.equal('Prince Ali')
|
|
|
|
})
|
2020-05-04 09:44:00 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|