]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/cli/prune-storage.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / cli / prune-storage.ts
index 95f573e504fdc4c86b97b23d7a6c61f314effa31..5bf86462b4f71d7fb517d44f3d3c3ff5d3efeced 100644 (file)
@@ -7,19 +7,15 @@ import { join } from 'path'
 import { buildUUID } from '@server/helpers/uuid'
 import { HttpStatusCode } from '@shared/core-utils'
 import {
-  buildServerDirectory,
   cleanupTests,
   CLICommand,
-  createVideoPlaylist,
   doubleFollow,
-  flushAndRunMultipleServers,
+  createMultipleServers,
   killallServers,
   makeGetRequest,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
-  updateMyAvatar,
-  uploadVideo,
   wait,
   waitJobs
 } from '@shared/extra-utils'
@@ -27,63 +23,61 @@ import { VideoPlaylistPrivacy } from '@shared/models'
 
 const expect = chai.expect
 
-async function countFiles (internalServerNumber: number, directory: string) {
-  const files = await readdir(buildServerDirectory({ internalServerNumber }, directory))
+async function countFiles (server: PeerTubeServer, directory: string) {
+  const files = await readdir(server.servers.buildDirectory(directory))
 
   return files.length
 }
 
-async function assertNotExists (internalServerNumber: number, directory: string, substring: string) {
-  const files = await readdir(buildServerDirectory({ internalServerNumber }, 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.internalServerNumber, 'videos')
+    const videosCount = await countFiles(server, 'videos')
     expect(videosCount).to.equal(8)
 
-    const torrentsCount = await countFiles(server.internalServerNumber, 'torrents')
+    const torrentsCount = await countFiles(server, 'torrents')
     expect(torrentsCount).to.equal(16)
 
-    const previewsCount = await countFiles(server.internalServerNumber, 'previews')
+    const previewsCount = await countFiles(server, 'previews')
     expect(previewsCount).to.equal(2)
 
-    const thumbnailsCount = await countFiles(server.internalServerNumber, 'thumbnails')
+    const thumbnailsCount = await countFiles(server, 'thumbnails')
     expect(thumbnailsCount).to.equal(6)
 
-    const avatarsCount = await countFiles(server.internalServerNumber, 'avatars')
+    const avatarsCount = await countFiles(server, 'avatars')
     expect(avatarsCount).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 updateMyAvatar({ url: server.url, accessToken: server.accessToken, fixture: 'avatar.png' })
+      await server.users.updateMyAvatar({ fixture: 'avatar.png' })
 
-      await createVideoPlaylist({
-        url: server.url,
-        token: server.accessToken,
-        playlistAttrs: {
+      await server.playlists.create({
+        attributes: {
           displayName: 'playlist',
           privacy: VideoPlaylistPrivacy.PUBLIC,
-          videoChannelId: server.videoChannel.id,
+          videoChannelId: server.store.channel.id,
           thumbnailfile: 'thumbnail.jpg'
         }
       })
@@ -93,7 +87,7 @@ describe('Test prune storage scripts', function () {
 
     // Lazy load the remote avatar
     {
-      const account = await servers[0].accountsCommand.get({ accountName: 'root@localhost:' + servers[1].port })
+      const account = await servers[0].accounts.get({ accountName: 'root@localhost:' + servers[1].port })
       await makeGetRequest({
         url: servers[0].url,
         path: account.avatar.path,
@@ -102,7 +96,7 @@ describe('Test prune storage scripts', function () {
     }
 
     {
-      const account = await servers[1].accountsCommand.get({ accountName: 'root@localhost:' + servers[0].port })
+      const account = await servers[1].accounts.get({ accountName: 'root@localhost:' + servers[0].port })
       await makeGetRequest({
         url: servers[1].url,
         path: account.avatar.path,
@@ -113,7 +107,7 @@ describe('Test prune storage scripts', function () {
     await wait(1000)
 
     await waitJobs(servers)
-    killallServers(servers)
+    await killallServers(servers)
 
     await wait(1000)
   })
@@ -125,7 +119,7 @@ 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], 'videos')
+        const base = servers[0].servers.buildDirectory('videos')
 
         const n1 = buildUUID() + '.mp4'
         const n2 = buildUUID() + '.webm'
@@ -137,7 +131,7 @@ describe('Test prune storage scripts', function () {
       }
 
       {
-        const base = buildServerDirectory(servers[0], 'torrents')
+        const base = servers[0].servers.buildDirectory('torrents')
 
         const n1 = buildUUID() + '-240.torrent'
         const n2 = buildUUID() + '-480.torrent'
@@ -149,7 +143,7 @@ describe('Test prune storage scripts', function () {
       }
 
       {
-        const base = buildServerDirectory(servers[0], 'thumbnails')
+        const base = servers[0].servers.buildDirectory('thumbnails')
 
         const n1 = buildUUID() + '.jpg'
         const n2 = buildUUID() + '.jpg'
@@ -161,7 +155,7 @@ describe('Test prune storage scripts', function () {
       }
 
       {
-        const base = buildServerDirectory(servers[0], 'previews')
+        const base = servers[0].servers.buildDirectory('previews')
 
         const n1 = buildUUID() + '.jpg'
         const n2 = buildUUID() + '.jpg'
@@ -173,7 +167,7 @@ describe('Test prune storage scripts', function () {
       }
 
       {
-        const base = buildServerDirectory(servers[0], 'avatars')
+        const base = servers[0].servers.buildDirectory('avatars')
 
         const n1 = buildUUID() + '.png'
         const n2 = buildUUID() + '.jpg'
@@ -189,7 +183,7 @@ describe('Test prune storage scripts', function () {
   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`)
   })
 
@@ -198,7 +192,7 @@ describe('Test prune storage scripts', function () {
 
     for (const directory of Object.keys(badNames)) {
       for (const name of badNames[directory]) {
-        await assertNotExists(servers[0].internalServerNumber, directory, name)
+        await assertNotExists(servers[0], directory, name)
       }
     }
   })