/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
import { createFile, readdir } from 'fs-extra'
import { join } from 'path'
-import { buildUUID } from '@server/helpers/uuid'
+import { wait } from '@shared/core-utils'
+import { buildUUID } from '@shared/extra-utils'
+import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
import {
cleanupTests,
CLICommand,
PeerTubeServer,
setAccessTokensToServers,
setDefaultVideoChannel,
- wait,
waitJobs
-} from '@shared/extra-utils'
-import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
-
-const expect = chai.expect
+} from '@shared/server-commands'
async function countFiles (server: PeerTubeServer, directory: string) {
const files = await readdir(server.servers.buildDirectory(directory))
}
}
-async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: string) {
+async function assertCountAreOkay (servers: PeerTubeServer[]) {
for (const server of servers) {
const videosCount = await countFiles(server, 'videos')
expect(videosCount).to.equal(8)
expect(thumbnailsCount).to.equal(6)
const avatarsCount = await countFiles(server, 'avatars')
- expect(avatarsCount).to.equal(2)
- }
-
- // When we'll prune HLS directories too
- // const hlsRootCount = await countFiles(servers[1], 'streaming-playlists/hls/')
- // expect(hlsRootCount).to.equal(2)
+ expect(avatarsCount).to.equal(4)
- // const hlsCount = await countFiles(servers[1], 'streaming-playlists/hls/' + videoServer2UUID)
- // expect(hlsCount).to.equal(10)
+ const hlsRootCount = await countFiles(server, 'streaming-playlists/hls')
+ expect(hlsRootCount).to.equal(2)
+ }
}
describe('Test prune storage scripts', function () {
let servers: PeerTubeServer[]
const badNames: { [directory: string]: string[] } = {}
- let videoServer2UUID: string
-
before(async function () {
this.timeout(120000)
for (const server of servers) {
await server.videos.upload({ attributes: { name: 'video 1' } })
-
- const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } })
- if (server.serverNumber === 2) videoServer2UUID = uuid
+ await server.videos.upload({ attributes: { name: 'video 2' } })
await server.users.updateMyAvatar({ fixture: 'avatar.png' })
await doubleFollow(servers[0], servers[1])
- // Lazy load the remote avatar
+ // Lazy load the remote avatars
{
const account = await servers[0].accounts.get({ accountName: 'root@localhost:' + servers[1].port })
- await makeGetRequest({
- url: servers[0].url,
- path: account.avatar.path,
- expectedStatus: HttpStatusCode.OK_200
- })
+
+ for (const avatar of account.avatars) {
+ await makeGetRequest({
+ url: servers[0].url,
+ path: avatar.path,
+ expectedStatus: HttpStatusCode.OK_200
+ })
+ }
}
{
const account = await servers[1].accounts.get({ accountName: 'root@localhost:' + servers[0].port })
- await makeGetRequest({
- url: servers[1].url,
- path: account.avatar.path,
- expectedStatus: HttpStatusCode.OK_200
- })
+ for (const avatar of account.avatars) {
+ await makeGetRequest({
+ url: servers[1].url,
+ path: avatar.path,
+ expectedStatus: HttpStatusCode.OK_200
+ })
+ }
}
await wait(1000)
})
it('Should have the files on the disk', async function () {
- await assertCountAreOkay(servers, videoServer2UUID)
+ await assertCountAreOkay(servers)
})
it('Should create some dirty files', async function () {
badNames['avatars'] = [ n1, n2 ]
}
- // When we'll prune HLS directories too
- // {
- // const directory = join('streaming-playlists', 'hls')
- // const base = servers[1].servers.buildDirectory(directory)
-
- // const n1 = buildUUID()
- // await createFile(join(base, n1))
- // badNames[directory] = [ n1 ]
- // }
-
- // {
- // const directory = join('streaming-playlists', 'hls', videoServer2UUID)
- // const base = servers[1].servers.buildDirectory(directory)
- // const n1 = buildUUID() + '-240-fragmented-.mp4'
- // const n2 = buildUUID() + '-master.m3u8'
-
- // await createFile(join(base, n1))
- // await createFile(join(base, n2))
+ {
+ const directory = join('streaming-playlists', 'hls')
+ const base = servers[0].servers.buildDirectory(directory)
- // badNames[directory] = [ n1, n2 ]
- // }
+ const n1 = buildUUID()
+ await createFile(join(base, n1))
+ badNames[directory] = [ n1 ]
+ }
}
})
})
it('Should have removed files', async function () {
- await assertCountAreOkay(servers, videoServer2UUID)
+ await assertCountAreOkay(servers)
for (const directory of Object.keys(badNames)) {
for (const name of badNames[directory]) {