]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/cli/create-move-video-storage-job.ts
Fix s3 mock cleanup
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-move-video-storage-job.ts
index c357f501b4e622facc7fbdc63dc004ed99117a0b..253fc983e5bd277be2dcd2d3d88acb4beb50aa13 100644 (file)
@@ -1,5 +1,6 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
+import { join } from 'path'
 import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
 import { HttpStatusCode, VideoDetails } from '@shared/models'
 import {
@@ -12,12 +13,12 @@ import {
   setAccessTokensToServers,
   waitJobs
 } from '@shared/server-commands'
-import { expectStartWith } from '../shared'
+import { checkDirectoryIsEmpty, expectStartWith } from '../shared'
 
-async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) {
+async function checkFiles (origin: PeerTubeServer, video: VideoDetails, objectStorage?: ObjectStorageCommand) {
   for (const file of video.files) {
-    const start = inObjectStorage
-      ? ObjectStorageCommand.getMockWebTorrentBaseUrl()
+    const start = objectStorage
+      ? objectStorage.getMockWebVideosBaseUrl()
       : origin.url
 
     expectStartWith(file.fileUrl, start)
@@ -25,8 +26,8 @@ async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObject
     await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
   }
 
-  const start = inObjectStorage
-    ? ObjectStorageCommand.getMockPlaylistBaseUrl()
+  const start = objectStorage
+    ? objectStorage.getMockPlaylistBaseUrl()
     : origin.url
 
   const hls = video.streamingPlaylists[0]
@@ -45,6 +46,7 @@ describe('Test create move video storage job', function () {
 
   let servers: PeerTubeServer[] = []
   const uuids: string[] = []
+  const objectStorage = new ObjectStorageCommand()
 
   before(async function () {
     this.timeout(360000)
@@ -55,7 +57,7 @@ describe('Test create move video storage job', function () {
 
     await doubleFollow(servers[0], servers[1])
 
-    await ObjectStorageCommand.prepareDefaultMockBuckets()
+    await objectStorage.prepareDefaultMockBuckets()
 
     await servers[0].config.enableTranscoding()
 
@@ -67,25 +69,25 @@ describe('Test create move video storage job', function () {
     await waitJobs(servers)
 
     await servers[0].kill()
-    await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
+    await servers[0].run(objectStorage.getDefaultMockConfig())
   })
 
   it('Should move only one file', async function () {
     this.timeout(120000)
 
     const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}`
-    await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig())
+    await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig())
     await waitJobs(servers)
 
     for (const server of servers) {
       const video = await server.videos.get({ id: uuids[1] })
 
-      await checkFiles(servers[0], video, true)
+      await checkFiles(servers[0], video, objectStorage)
 
       for (const id of [ uuids[0], uuids[2] ]) {
         const video = await server.videos.get({ id })
 
-        await checkFiles(servers[0], video, false)
+        await checkFiles(servers[0], video)
       }
     }
   })
@@ -94,19 +96,29 @@ describe('Test create move video storage job', function () {
     this.timeout(120000)
 
     const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos`
-    await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig())
+    await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig())
     await waitJobs(servers)
 
     for (const server of servers) {
       for (const id of [ uuids[0], uuids[2] ]) {
         const video = await server.videos.get({ id })
 
-        await checkFiles(servers[0], video, true)
+        await checkFiles(servers[0], video, objectStorage)
       }
     }
   })
 
+  it('Should not have files on disk anymore', async function () {
+    await checkDirectoryIsEmpty(servers[0], 'videos', [ 'private' ])
+    await checkDirectoryIsEmpty(servers[0], join('videos', 'private'))
+
+    await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls'), [ 'private' ])
+    await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls', 'private'))
+  })
+
   after(async function () {
+    await objectStorage.cleanupMock()
+
     await cleanupTests(servers)
   })
 })