X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fcli%2Fprune-storage.ts;h=d4dbee682e00d64b08073ce33bd82711c82f3da4;hb=9293139fde7091e9badcafa9b570b83cea9a10ad;hp=67a5c564e2570cdefd596bc7bf7f5ce440de707d;hpb=e2600d8b261994abbbeb1ff921edaefd267fc122;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index 67a5c564e..d4dbee682 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts @@ -1,39 +1,39 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' import * as chai from 'chai' -import { waitJobs } from '../../../shared/extra-utils/server/jobs' +import { createFile, readdir } from 'fs-extra' +import { join } from 'path' +import { buildUUID } from '@server/helpers/uuid' +import { HttpStatusCode } from '@shared/core-utils' import { buildServerDirectory, cleanupTests, - createVideoPlaylist, + CLICommand, doubleFollow, - execCLI, flushAndRunMultipleServers, - getAccount, - getEnvCli, + killallServers, + makeGetRequest, ServerInfo, - setAccessTokensToServers, setDefaultVideoChannel, + setAccessTokensToServers, + setDefaultVideoChannel, updateMyAvatar, uploadVideo, - wait -} from '../../../shared/extra-utils' -import { Account, VideoPlaylistPrivacy } from '../../../shared/models' -import { createFile, readdir } from 'fs-extra' -import * as uuidv4 from 'uuid/v4' -import { join } from 'path' -import * as request from 'supertest' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect async function countFiles (internalServerNumber: number, directory: string) { - const files = await readdir(buildServerDirectory(internalServerNumber, directory)) + const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) return files.length } async function assertNotExists (internalServerNumber: number, directory: string, substring: string) { - const files = await readdir(buildServerDirectory(internalServerNumber, directory)) + const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) for (const f of files) { expect(f).to.not.contain(substring) @@ -46,7 +46,7 @@ async function assertCountAreOkay (servers: ServerInfo[]) { expect(videosCount).to.equal(8) const torrentsCount = await countFiles(server.internalServerNumber, 'torrents') - expect(torrentsCount).to.equal(8) + expect(torrentsCount).to.equal(16) const previewsCount = await countFiles(server.internalServerNumber, 'previews') expect(previewsCount).to.equal(2) @@ -61,7 +61,7 @@ async function assertCountAreOkay (servers: ServerInfo[]) { describe('Test prune storage scripts', function () { let servers: ServerInfo[] - const badNames: { [ directory: string ]: string[] } = {} + const badNames: { [directory: string]: string[] } = {} before(async function () { this.timeout(120000) @@ -76,10 +76,8 @@ describe('Test prune storage scripts', function () { await updateMyAvatar({ url: server.url, accessToken: server.accessToken, fixture: 'avatar.png' }) - await createVideoPlaylist({ - url: server.url, - token: server.accessToken, - playlistAttrs: { + await server.playlistsCommand.create({ + attributes: { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: server.videoChannel.id, @@ -92,20 +90,29 @@ describe('Test prune storage scripts', function () { // Lazy load the remote avatar { - const res = await getAccount(servers[ 0 ].url, 'root@localhost:' + servers[ 1 ].port) - const account: Account = res.body - await request('http://localhost:' + servers[ 0 ].port).get(account.avatar.path).expect(200) + const account = await servers[0].accountsCommand.get({ accountName: 'root@localhost:' + servers[1].port }) + await makeGetRequest({ + url: servers[0].url, + path: account.avatar.path, + statusCodeExpected: HttpStatusCode.OK_200 + }) } { - const res = await getAccount(servers[ 1 ].url, 'root@localhost:' + servers[ 0 ].port) - const account: Account = res.body - await request('http://localhost:' + servers[ 1 ].port).get(account.avatar.path).expect(200) + const account = await servers[1].accountsCommand.get({ accountName: 'root@localhost:' + servers[0].port }) + await makeGetRequest({ + url: servers[1].url, + path: account.avatar.path, + statusCodeExpected: HttpStatusCode.OK_200 + }) } await wait(1000) await waitJobs(servers) + await killallServers(servers) + + await wait(1000) }) it('Should have the files on the disk', async function () { @@ -115,10 +122,10 @@ describe('Test prune storage scripts', function () { it('Should create some dirty files', async function () { for (let i = 0; i < 2; i++) { { - const base = buildServerDirectory(servers[0].internalServerNumber, 'videos') + const base = buildServerDirectory(servers[0], 'videos') - const n1 = uuidv4() + '.mp4' - const n2 = uuidv4() + '.webm' + const n1 = buildUUID() + '.mp4' + const n2 = buildUUID() + '.webm' await createFile(join(base, n1)) await createFile(join(base, n2)) @@ -127,10 +134,10 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0].internalServerNumber, 'torrents') + const base = buildServerDirectory(servers[0], 'torrents') - const n1 = uuidv4() + '-240.torrent' - const n2 = uuidv4() + '-480.torrent' + const n1 = buildUUID() + '-240.torrent' + const n2 = buildUUID() + '-480.torrent' await createFile(join(base, n1)) await createFile(join(base, n2)) @@ -139,10 +146,10 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0].internalServerNumber, 'thumbnails') + const base = buildServerDirectory(servers[0], 'thumbnails') - const n1 = uuidv4() + '.jpg' - const n2 = uuidv4() + '.jpg' + const n1 = buildUUID() + '.jpg' + const n2 = buildUUID() + '.jpg' await createFile(join(base, n1)) await createFile(join(base, n2)) @@ -151,10 +158,10 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0].internalServerNumber, 'previews') + const base = buildServerDirectory(servers[0], 'previews') - const n1 = uuidv4() + '.jpg' - const n2 = uuidv4() + '.jpg' + const n1 = buildUUID() + '.jpg' + const n2 = buildUUID() + '.jpg' await createFile(join(base, n1)) await createFile(join(base, n2)) @@ -163,10 +170,10 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0].internalServerNumber, 'avatars') + const base = buildServerDirectory(servers[0], 'avatars') - const n1 = uuidv4() + '.png' - const n2 = uuidv4() + '.jpg' + const n1 = buildUUID() + '.png' + const n2 = buildUUID() + '.jpg' await createFile(join(base, n1)) await createFile(join(base, n2)) @@ -179,8 +186,8 @@ describe('Test prune storage scripts', function () { it('Should run prune storage', async function () { this.timeout(30000) - const env = getEnvCli(servers[0]) - await execCLI(`echo y | ${env} npm run prune-storage`) + const env = servers[0].cliCommand.getEnv() + await CLICommand.exec(`echo y | ${env} npm run prune-storage`) }) it('Should have removed files', async function () {