]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/cli/prune-storage.ts
Relax bitrate/fps test
[github/Chocobozzz/PeerTube.git] / server / tests / cli / prune-storage.ts
index b45049964078fa9b959bbc2f78f2c80bf7f3b173..a89e17e3c3a3f139f24965f9a26539bdeea83df0 100644 (file)
@@ -1,44 +1,39 @@
 /* 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 { HttpStatusCode } from '@shared/core-utils'
+import { wait } from '@shared/core-utils'
+import { buildUUID } from '@shared/extra-utils'
+import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
 import {
   cleanupTests,
   CLICommand,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
   killallServers,
   makeGetRequest,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
-  uploadVideo,
-  wait,
   waitJobs
-} from '@shared/extra-utils'
-import { VideoPlaylistPrivacy } from '@shared/models'
+} from '@shared/server-commands'
 
-const expect = chai.expect
-
-async function countFiles (server: ServerInfo, directory: string) {
-  const files = await readdir(server.serversCommand.buildDirectory(directory))
+async function countFiles (server: PeerTubeServer, directory: string) {
+  const files = await readdir(server.servers.buildDirectory(directory))
 
   return files.length
 }
 
-async function assertNotExists (server: ServerInfo, directory: string, substring: string) {
-  const files = await readdir(server.serversCommand.buildDirectory(directory))
+async function assertNotExists (server: PeerTubeServer, directory: string, substring: string) {
+  const files = await readdir(server.servers.buildDirectory(directory))
 
   for (const f of files) {
     expect(f).to.not.contain(substring)
   }
 }
 
-async function assertCountAreOkay (servers: ServerInfo[]) {
+async function assertCountAreOkay (servers: PeerTubeServer[]) {
   for (const server of servers) {
     const videosCount = await countFiles(server, 'videos')
     expect(videosCount).to.equal(8)
@@ -53,32 +48,35 @@ async function assertCountAreOkay (servers: ServerInfo[]) {
     expect(thumbnailsCount).to.equal(6)
 
     const avatarsCount = await countFiles(server, 'avatars')
-    expect(avatarsCount).to.equal(2)
+    expect(avatarsCount).to.equal(4)
+
+    const hlsRootCount = await countFiles(server, 'streaming-playlists/hls')
+    expect(hlsRootCount).to.equal(2)
   }
 }
 
 describe('Test prune storage scripts', function () {
-  let servers: ServerInfo[]
+  let servers: PeerTubeServer[]
   const badNames: { [directory: string]: string[] } = {}
 
   before(async function () {
     this.timeout(120000)
 
-    servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: true } })
+    servers = await createMultipleServers(2, { transcoding: { enabled: true } })
     await setAccessTokensToServers(servers)
     await setDefaultVideoChannel(servers)
 
     for (const server of servers) {
-      await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
-      await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
+      await server.videos.upload({ attributes: { name: 'video 1' } })
+      await server.videos.upload({ attributes: { name: 'video 2' } })
 
-      await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })
+      await server.users.updateMyAvatar({ fixture: 'avatar.png' })
 
-      await server.playlistsCommand.create({
+      await server.playlists.create({
         attributes: {
           displayName: 'playlist',
           privacy: VideoPlaylistPrivacy.PUBLIC,
-          videoChannelId: server.videoChannel.id,
+          videoChannelId: server.store.channel.id,
           thumbnailfile: 'thumbnail.jpg'
         }
       })
@@ -86,23 +84,28 @@ describe('Test prune storage scripts', function () {
 
     await doubleFollow(servers[0], servers[1])
 
-    // Lazy load the remote avatar
+    // Lazy load the remote avatars
     {
-      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 account = await servers[0].accounts.get({ accountName: 'root@localhost:' + servers[1].port })
+
+      for (const avatar of account.avatars) {
+        await makeGetRequest({
+          url: servers[0].url,
+          path: avatar.path,
+          expectedStatus: HttpStatusCode.OK_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
-      })
+      const account = await servers[1].accounts.get({ accountName: 'root@localhost:' + servers[0].port })
+      for (const avatar of account.avatars) {
+        await makeGetRequest({
+          url: servers[1].url,
+          path: avatar.path,
+          expectedStatus: HttpStatusCode.OK_200
+        })
+      }
     }
 
     await wait(1000)
@@ -120,7 +123,7 @@ describe('Test prune storage scripts', function () {
   it('Should create some dirty files', async function () {
     for (let i = 0; i < 2; i++) {
       {
-        const base = servers[0].serversCommand.buildDirectory('videos')
+        const base = servers[0].servers.buildDirectory('videos')
 
         const n1 = buildUUID() + '.mp4'
         const n2 = buildUUID() + '.webm'
@@ -132,7 +135,7 @@ describe('Test prune storage scripts', function () {
       }
 
       {
-        const base = servers[0].serversCommand.buildDirectory('torrents')
+        const base = servers[0].servers.buildDirectory('torrents')
 
         const n1 = buildUUID() + '-240.torrent'
         const n2 = buildUUID() + '-480.torrent'
@@ -144,7 +147,7 @@ describe('Test prune storage scripts', function () {
       }
 
       {
-        const base = servers[0].serversCommand.buildDirectory('thumbnails')
+        const base = servers[0].servers.buildDirectory('thumbnails')
 
         const n1 = buildUUID() + '.jpg'
         const n2 = buildUUID() + '.jpg'
@@ -156,7 +159,7 @@ describe('Test prune storage scripts', function () {
       }
 
       {
-        const base = servers[0].serversCommand.buildDirectory('previews')
+        const base = servers[0].servers.buildDirectory('previews')
 
         const n1 = buildUUID() + '.jpg'
         const n2 = buildUUID() + '.jpg'
@@ -168,7 +171,7 @@ describe('Test prune storage scripts', function () {
       }
 
       {
-        const base = servers[0].serversCommand.buildDirectory('avatars')
+        const base = servers[0].servers.buildDirectory('avatars')
 
         const n1 = buildUUID() + '.png'
         const n2 = buildUUID() + '.jpg'
@@ -178,13 +181,22 @@ describe('Test prune storage scripts', function () {
 
         badNames['avatars'] = [ n1, n2 ]
       }
+
+      {
+        const directory = join('streaming-playlists', 'hls')
+        const base = servers[0].servers.buildDirectory(directory)
+
+        const n1 = buildUUID()
+        await createFile(join(base, n1))
+        badNames[directory] = [ n1 ]
+      }
     }
   })
 
   it('Should run prune storage', async function () {
     this.timeout(30000)
 
-    const env = servers[0].cliCommand.getEnv()
+    const env = servers[0].cli.getEnv()
     await CLICommand.exec(`echo y | ${env} npm run prune-storage`)
   })