]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/cli/prune-storage.ts
Introduce CLI command
[github/Chocobozzz/PeerTube.git] / server / tests / cli / prune-storage.ts
index 304c8ca56b5b932209422a7b0c28f9c3760e8e7e..81f91105c72e3f0c9383fcd52f40378fae015d25 100644 (file)
@@ -2,16 +2,19 @@
 
 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/miscs/http-error-codes'
 import {
   buildServerDirectory,
   cleanupTests,
+  CLICommand,
   createVideoPlaylist,
   doubleFollow,
-  execCLI,
   flushAndRunMultipleServers,
   getAccount,
-  getEnvCli,
+  killallServers,
   makeGetRequest,
   ServerInfo,
   setAccessTokensToServers,
@@ -20,21 +23,19 @@ import {
   uploadVideo,
   wait
 } from '../../../shared/extra-utils'
+import { waitJobs } from '../../../shared/extra-utils/server/jobs'
 import { Account, VideoPlaylistPrivacy } from '../../../shared/models'
-import { createFile, readdir } from 'fs-extra'
-import * as uuidv4 from 'uuid/v4'
-import { join } from 'path'
 
 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)
@@ -98,7 +99,7 @@ describe('Test prune storage scripts', function () {
       await makeGetRequest({
         url: servers[0].url,
         path: account.avatar.path,
-        statusCodeExpected: 200
+        statusCodeExpected: HttpStatusCode.OK_200
       })
     }
 
@@ -108,13 +109,16 @@ describe('Test prune storage scripts', function () {
       await makeGetRequest({
         url: servers[1].url,
         path: account.avatar.path,
-        statusCodeExpected: 200
+        statusCodeExpected: HttpStatusCode.OK_200
       })
     }
 
     await wait(1000)
 
     await waitJobs(servers)
+    killallServers(servers)
+
+    await wait(1000)
   })
 
   it('Should have the files on the disk', async function () {
@@ -124,10 +128,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))
@@ -136,10 +140,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))
@@ -148,10 +152,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))
@@ -160,10 +164,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))
@@ -172,10 +176,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))
@@ -188,8 +192,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 () {