]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Prevent object storage mock conflicts
authorChocobozzz <me@florianbigard.com>
Tue, 23 May 2023 08:49:45 +0000 (10:49 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 23 May 2023 08:49:45 +0000 (10:49 +0200)
When running tests in parallel

20 files changed:
server/tests/api/live/live-fast-restream.ts
server/tests/api/live/live.ts
server/tests/api/object-storage/live.ts
server/tests/api/object-storage/video-imports.ts
server/tests/api/object-storage/videos.ts
server/tests/api/server/follows.ts
server/tests/api/server/proxy.ts
server/tests/api/transcoding/create-transcoding.ts
server/tests/api/transcoding/hls.ts
server/tests/api/transcoding/update-while-transcoding.ts
server/tests/api/transcoding/video-studio.ts
server/tests/cli/create-import-video-file-job.ts
server/tests/cli/create-move-video-storage-job.ts
server/tests/peertube-runner/live-transcoding.ts
server/tests/peertube-runner/studio-transcoding.ts
server/tests/peertube-runner/vod-transcoding.ts
server/tests/shared/live.ts
shared/server-commands/server/object-storage-command.ts
shared/server-commands/server/server.ts
shared/server-commands/videos/live-command.ts

index 2169393c27fc0931caf8229d7726bd0af2e37083..d7085a957c5c95a5a929e418acbcab491ce0503f 100644 (file)
@@ -65,8 +65,7 @@ describe('Fast restream in live', function () {
       server,
       videoUUID: liveVideoUUID,
       segment: 1,
-      playlistNumber: 0,
-      objectStorage: false
+      playlistNumber: 0
     })
 
     return { ffmpegCommand, liveVideoUUID }
index 65ebbc5f7b371e2213231d6d809c205101e969ae..7ab67b126d14a802a7a039eb17b06e1a5a579897 100644 (file)
@@ -423,7 +423,6 @@ describe('Test live', function () {
         servers,
         liveVideoId,
         resolutions: [ 720 ],
-        objectStorage: false,
         transcoded: true
       })
 
@@ -459,7 +458,6 @@ describe('Test live', function () {
         servers,
         liveVideoId,
         resolutions: resolutions.concat([ 720 ]),
-        objectStorage: false,
         transcoded: true
       })
 
@@ -512,7 +510,6 @@ describe('Test live', function () {
         servers,
         liveVideoId,
         resolutions,
-        objectStorage: false,
         transcoded: true
       })
 
@@ -609,7 +606,6 @@ describe('Test live', function () {
         servers,
         liveVideoId,
         resolutions,
-        objectStorage: false,
         transcoded: true
       })
 
@@ -646,7 +642,6 @@ describe('Test live', function () {
         servers,
         liveVideoId,
         resolutions: [ 720 ],
-        objectStorage: false,
         transcoded: true
       })
 
@@ -720,8 +715,7 @@ describe('Test live', function () {
           server: servers[0],
           videoUUID,
           playlistNumber: 0,
-          segment: 2,
-          objectStorage: false
+          segment: 2
         })
       }
 
index 7f8db40e5e65fdf25801bb09ce3ac6e84b0280a7..07ff4763b9e604abf211f2427bac766470de307e 100644 (file)
@@ -36,7 +36,14 @@ async function createLive (server: PeerTubeServer, permanent: boolean) {
   return uuid
 }
 
-async function checkFilesExist (servers: PeerTubeServer[], videoUUID: string, numberOfFiles: number) {
+async function checkFilesExist (options: {
+  servers: PeerTubeServer[]
+  videoUUID: string
+  numberOfFiles: number
+  objectStorage: ObjectStorageCommand
+}) {
+  const { servers, videoUUID, numberOfFiles, objectStorage } = options
+
   for (const server of servers) {
     const video = await server.videos.get({ id: videoUUID })
 
@@ -47,14 +54,21 @@ async function checkFilesExist (servers: PeerTubeServer[], videoUUID: string, nu
     expect(files).to.have.lengthOf(numberOfFiles)
 
     for (const file of files) {
-      expectStartWith(file.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
+      expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl())
 
       await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
     }
   }
 }
 
-async function checkFilesCleanup (server: PeerTubeServer, videoUUID: string, resolutions: number[]) {
+async function checkFilesCleanup (options: {
+  server: PeerTubeServer
+  videoUUID: string
+  resolutions: number[]
+  objectStorage: ObjectStorageCommand
+}) {
+  const { server, videoUUID, resolutions, objectStorage } = options
+
   const resolutionFiles = resolutions.map((_value, i) => `${i}.m3u8`)
 
   for (const playlistName of [ 'master.m3u8' ].concat(resolutionFiles)) {
@@ -62,7 +76,7 @@ async function checkFilesCleanup (server: PeerTubeServer, videoUUID: string, res
       videoUUID,
       playlistName,
       expectedStatus: HttpStatusCode.NOT_FOUND_404,
-      objectStorage: true
+      objectStorage
     })
   }
 
@@ -70,7 +84,7 @@ async function checkFilesCleanup (server: PeerTubeServer, videoUUID: string, res
     videoUUID,
     playlistNumber: 0,
     segment: 0,
-    objectStorage: true,
+    objectStorage,
     expectedStatus: HttpStatusCode.NOT_FOUND_404
   })
 }
@@ -80,13 +94,13 @@ describe('Object storage for lives', function () {
 
   let servers: PeerTubeServer[]
   let sqlCommandServer1: SQLCommand
+  const objectStorage = new ObjectStorageCommand()
 
   before(async function () {
     this.timeout(120000)
 
-    await ObjectStorageCommand.prepareDefaultMockBuckets()
-
-    servers = await createMultipleServers(2, ObjectStorageCommand.getDefaultMockConfig())
+    await objectStorage.prepareDefaultMockBuckets()
+    servers = await createMultipleServers(2, objectStorage.getDefaultMockConfig())
 
     await setAccessTokensToServers(servers)
     await setDefaultVideoChannel(servers)
@@ -119,7 +133,7 @@ describe('Object storage for lives', function () {
         liveVideoId: videoUUID,
         resolutions: [ 720 ],
         transcoded: false,
-        objectStorage: true
+        objectStorage
       })
 
       await stopFfmpeg(ffmpegCommand)
@@ -131,11 +145,11 @@ describe('Object storage for lives', function () {
       await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUID)
       await waitJobs(servers)
 
-      await checkFilesExist(servers, videoUUID, 1)
+      await checkFilesExist({ servers, videoUUID, numberOfFiles: 1, objectStorage })
     })
 
     it('Should have cleaned up live files from object storage', async function () {
-      await checkFilesCleanup(servers[0], videoUUID, [ 720 ])
+      await checkFilesCleanup({ server: servers[0], videoUUID, resolutions: [ 720 ], objectStorage })
     })
   })
 
@@ -166,7 +180,7 @@ describe('Object storage for lives', function () {
           liveVideoId: videoUUIDNonPermanent,
           resolutions,
           transcoded: true,
-          objectStorage: true
+          objectStorage
         })
 
         await stopFfmpeg(ffmpegCommand)
@@ -178,11 +192,11 @@ describe('Object storage for lives', function () {
         await waitUntilLiveReplacedByReplayOnAllServers(servers, videoUUIDNonPermanent)
         await waitJobs(servers)
 
-        await checkFilesExist(servers, videoUUIDNonPermanent, 5)
+        await checkFilesExist({ servers, videoUUID: videoUUIDNonPermanent, numberOfFiles: 5, objectStorage })
       })
 
       it('Should have cleaned up live files from object storage', async function () {
-        await checkFilesCleanup(servers[0], videoUUIDNonPermanent, resolutions)
+        await checkFilesCleanup({ server: servers[0], videoUUID: videoUUIDNonPermanent, resolutions, objectStorage })
       })
     })
 
@@ -206,7 +220,7 @@ describe('Object storage for lives', function () {
           liveVideoId: videoUUIDPermanent,
           resolutions,
           transcoded: true,
-          objectStorage: true
+          objectStorage
         })
 
         await stopFfmpeg(ffmpegCommand)
@@ -221,11 +235,11 @@ describe('Object storage for lives', function () {
         const videoLiveDetails = await servers[0].videos.get({ id: videoUUIDPermanent })
         const replay = await findExternalSavedVideo(servers[0], videoLiveDetails)
 
-        await checkFilesExist(servers, replay.uuid, 5)
+        await checkFilesExist({ servers, videoUUID: replay.uuid, numberOfFiles: 5, objectStorage })
       })
 
       it('Should have cleaned up live files from object storage', async function () {
-        await checkFilesCleanup(servers[0], videoUUIDPermanent, resolutions)
+        await checkFilesCleanup({ server: servers[0], videoUUID: videoUUIDPermanent, resolutions, objectStorage })
       })
     })
   })
@@ -238,9 +252,10 @@ describe('Object storage for lives', function () {
       this.timeout(120000)
 
       const port = await mockObjectStorageProxy.initialize()
-      baseMockUrl = `http://127.0.0.1:${port}/streaming-playlists`
+      const bucketName = objectStorage.getMockStreamingPlaylistsBucketName()
+      baseMockUrl = `http://127.0.0.1:${port}/${bucketName}`
 
-      await ObjectStorageCommand.createMockBucket('streaming-playlists')
+      await objectStorage.prepareDefaultMockBuckets()
 
       const config = {
         object_storage: {
@@ -251,7 +266,7 @@ describe('Object storage for lives', function () {
           credentials: ObjectStorageCommand.getMockCredentialsConfig(),
 
           streaming_playlists: {
-            bucket_name: 'streaming-playlists',
+            bucket_name: bucketName,
             prefix: '',
             base_url: baseMockUrl
           }
@@ -279,7 +294,7 @@ describe('Object storage for lives', function () {
         liveVideoId: videoUUIDPermanent,
         resolutions: [ 720 ],
         transcoded: true,
-        objectStorage: true,
+        objectStorage,
         objectStorageBaseUrl: baseMockUrl
       })
 
@@ -289,6 +304,7 @@ describe('Object storage for lives', function () {
 
   after(async function () {
     await sqlCommandServer1.cleanup()
+    await objectStorage.cleanupMock()
 
     await cleanupTests(servers)
   })
index d5fd91b6ad137f381c16e3d50fab10d2151c820b..57150e5a6cc0d39ac241794be8e0c9133a1d7476 100644 (file)
@@ -32,13 +32,14 @@ describe('Object storage for video import', function () {
   if (areMockObjectStorageTestsDisabled()) return
 
   let server: PeerTubeServer
+  const objectStorage = new ObjectStorageCommand()
 
   before(async function () {
     this.timeout(120000)
 
-    await ObjectStorageCommand.prepareDefaultMockBuckets()
+    await objectStorage.prepareDefaultMockBuckets()
 
-    server = await createSingleServer(1, ObjectStorageCommand.getDefaultMockConfig())
+    server = await createSingleServer(1, objectStorage.getDefaultMockConfig())
 
     await setAccessTokensToServers([ server ])
     await setDefaultVideoChannel([ server ])
@@ -64,7 +65,7 @@ describe('Object storage for video import', function () {
       expect(video.streamingPlaylists).to.have.lengthOf(0)
 
       const fileUrl = video.files[0].fileUrl
-      expectStartWith(fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+      expectStartWith(fileUrl, objectStorage.getMockWebVideosBaseUrl())
 
       await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.OK_200 })
     })
@@ -89,13 +90,13 @@ describe('Object storage for video import', function () {
       expect(video.streamingPlaylists[0].files).to.have.lengthOf(5)
 
       for (const file of video.files) {
-        expectStartWith(file.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+        expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl())
 
         await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
       }
 
       for (const file of video.streamingPlaylists[0].files) {
-        expectStartWith(file.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
+        expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl())
 
         await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
       }
@@ -103,6 +104,8 @@ describe('Object storage for video import', function () {
   })
 
   after(async function () {
+    await objectStorage.cleanupMock()
+
     await cleanupTests([ server ])
   })
 })
index 77ed78ae11a9cba845f49737a81d1bae2d36eeb4..f837d9966fed9cd814381a4dee461509f092b469 100644 (file)
@@ -145,6 +145,7 @@ function runTestSuite (options: {
 
   let servers: PeerTubeServer[]
   let sqlCommands: SQLCommand[] = []
+  const objectStorage = new ObjectStorageCommand()
 
   let keptUrls: string[] = []
 
@@ -159,8 +160,8 @@ function runTestSuite (options: {
       ? `http://127.0.0.1:${port}`
       : undefined
 
-    await ObjectStorageCommand.createMockBucket(options.playlistBucket)
-    await ObjectStorageCommand.createMockBucket(options.webtorrentBucket)
+    await objectStorage.createMockBucket(options.playlistBucket)
+    await objectStorage.createMockBucket(options.webtorrentBucket)
 
     const config = {
       object_storage: {
@@ -275,6 +276,7 @@ function runTestSuite (options: {
 
   after(async function () {
     await mockObjectStorageProxy.terminate()
+    await objectStorage.cleanupMock()
 
     for (const sqlCommand of sqlCommands) {
       await sqlCommand.cleanup()
@@ -287,26 +289,12 @@ function runTestSuite (options: {
 describe('Object storage for videos', function () {
   if (areMockObjectStorageTestsDisabled()) return
 
+  const objectStorage = new ObjectStorageCommand()
+
   describe('Test config', function () {
     let server: PeerTubeServer
 
-    const baseConfig = {
-      object_storage: {
-        enabled: true,
-        endpoint: 'http://' + ObjectStorageCommand.getMockEndpointHost(),
-        region: ObjectStorageCommand.getMockRegion(),
-
-        credentials: ObjectStorageCommand.getMockCredentialsConfig(),
-
-        streaming_playlists: {
-          bucket_name: ObjectStorageCommand.DEFAULT_PLAYLIST_MOCK_BUCKET
-        },
-
-        videos: {
-          bucket_name: ObjectStorageCommand.DEFAULT_WEBTORRENT_MOCK_BUCKET
-        }
-      }
-    }
+    const baseConfig = objectStorage.getDefaultMockConfig()
 
     const badCredentials = {
       access_key_id: 'AKIAIOSFODNN7EXAMPLE',
@@ -334,7 +322,7 @@ describe('Object storage for videos', function () {
     it('Should fail with bad credentials', async function () {
       this.timeout(60000)
 
-      await ObjectStorageCommand.prepareDefaultMockBuckets()
+      await objectStorage.prepareDefaultMockBuckets()
 
       const config = merge({}, baseConfig, {
         object_storage: {
@@ -358,7 +346,7 @@ describe('Object storage for videos', function () {
     it('Should succeed with credentials from env', async function () {
       this.timeout(60000)
 
-      await ObjectStorageCommand.prepareDefaultMockBuckets()
+      await objectStorage.prepareDefaultMockBuckets()
 
       const config = merge({}, baseConfig, {
         object_storage: {
@@ -385,25 +373,27 @@ describe('Object storage for videos', function () {
       await waitJobs([ server ], { skipDelayed: true })
       const video = await server.videos.get({ id: uuid })
 
-      expectStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+      expectStartWith(video.files[0].fileUrl, objectStorage.getMockWebVideosBaseUrl())
     })
 
     after(async function () {
+      await objectStorage.cleanupMock()
+
       await cleanupTests([ server ])
     })
   })
 
   describe('Test simple object storage', function () {
     runTestSuite({
-      playlistBucket: 'streaming-playlists',
-      webtorrentBucket: 'videos'
+      playlistBucket: objectStorage.getMockBucketName('streaming-playlists'),
+      webtorrentBucket: objectStorage.getMockBucketName('videos')
     })
   })
 
   describe('Test object storage with prefix', function () {
     runTestSuite({
-      playlistBucket: 'mybucket',
-      webtorrentBucket: 'mybucket',
+      playlistBucket: objectStorage.getMockBucketName('mybucket'),
+      webtorrentBucket: objectStorage.getMockBucketName('mybucket'),
 
       playlistPrefix: 'streaming-playlists_',
       webtorrentPrefix: 'webtorrent_'
@@ -412,8 +402,8 @@ describe('Object storage for videos', function () {
 
   describe('Test object storage with prefix and base URL', function () {
     runTestSuite({
-      playlistBucket: 'mybucket',
-      webtorrentBucket: 'mybucket',
+      playlistBucket: objectStorage.getMockBucketName('mybucket'),
+      webtorrentBucket: objectStorage.getMockBucketName('mybucket'),
 
       playlistPrefix: 'streaming-playlists/',
       webtorrentPrefix: 'webtorrent/',
@@ -440,8 +430,8 @@ describe('Object storage for videos', function () {
 
     runTestSuite({
       maxUploadPart,
-      playlistBucket: 'streaming-playlists',
-      webtorrentBucket: 'videos',
+      playlistBucket: objectStorage.getMockBucketName('streaming-playlists'),
+      webtorrentBucket: objectStorage.getMockBucketName('videos'),
       fixture
     })
   })
index dba9e107c3c227878c38785232fedd70e24063b2..2a5fff82b046bc4eb42c635dd10e3e737f9cb86f 100644 (file)
@@ -279,7 +279,7 @@ describe('Test follows', function () {
     })
 
     it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () {
-      this.timeout(120000)
+      this.timeout(160000)
 
       await servers[1].videos.upload({ attributes: { name: 'server2' } })
       await servers[2].videos.upload({ attributes: { name: 'server3' } })
index 4bf89410eb831f9280bfcb8a0c06428df73ae44a..9337468d586da4134a1b351610424119ea547d21 100644 (file)
@@ -122,38 +122,44 @@ describe('Test proxy', function () {
   describe('Object storage', function () {
     if (areMockObjectStorageTestsDisabled()) return
 
+    const objectStorage = new ObjectStorageCommand()
+
     before(async function () {
       this.timeout(30000)
 
-      await ObjectStorageCommand.prepareDefaultMockBuckets()
+      await objectStorage.prepareDefaultMockBuckets()
     })
 
     it('Should succeed to upload to object storage with the appropriate proxy config', async function () {
       this.timeout(120000)
 
       await servers[0].kill()
-      await servers[0].run(ObjectStorageCommand.getDefaultMockConfig(), { env: goodEnv })
+      await servers[0].run(objectStorage.getDefaultMockConfig(), { env: goodEnv })
 
       const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
       await waitJobs(servers)
 
       const video = await servers[0].videos.get({ id: uuid })
 
-      expectStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+      expectStartWith(video.files[0].fileUrl, objectStorage.getMockWebVideosBaseUrl())
     })
 
     it('Should fail to upload to object storage with a wrong proxy config', async function () {
       this.timeout(120000)
 
       await servers[0].kill()
-      await servers[0].run(ObjectStorageCommand.getDefaultMockConfig(), { env: badEnv })
+      await servers[0].run(objectStorage.getDefaultMockConfig(), { env: badEnv })
 
       const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
       await waitJobs(servers, { skipDelayed: true })
 
       const video = await servers[0].videos.get({ id: uuid })
 
-      expectNotStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+      expectNotStartWith(video.files[0].fileUrl, objectStorage.getMockWebVideosBaseUrl())
+    })
+
+    after(async function () {
+      await objectStorage.cleanupMock()
     })
   })
 
index 5483c8dba6deb6ce704126a820bb2059cf9ce2af..d6f5b01dce1b8c94e395ac64d153c091261d9789 100644 (file)
@@ -17,9 +17,9 @@ import {
   waitJobs
 } from '@shared/server-commands'
 
-async function checkFilesInObjectStorage (video: VideoDetails) {
+async function checkFilesInObjectStorage (objectStorage: ObjectStorageCommand, video: VideoDetails) {
   for (const file of video.files) {
-    expectStartWith(file.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+    expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl())
     await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
   }
 
@@ -27,29 +27,30 @@ async function checkFilesInObjectStorage (video: VideoDetails) {
 
   const hlsPlaylist = video.streamingPlaylists[0]
   for (const file of hlsPlaylist.files) {
-    expectStartWith(file.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
+    expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl())
     await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
   }
 
-  expectStartWith(hlsPlaylist.playlistUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
+  expectStartWith(hlsPlaylist.playlistUrl, objectStorage.getMockPlaylistBaseUrl())
   await makeRawRequest({ url: hlsPlaylist.playlistUrl, expectedStatus: HttpStatusCode.OK_200 })
 
-  expectStartWith(hlsPlaylist.segmentsSha256Url, ObjectStorageCommand.getMockPlaylistBaseUrl())
+  expectStartWith(hlsPlaylist.segmentsSha256Url, objectStorage.getMockPlaylistBaseUrl())
   await makeRawRequest({ url: hlsPlaylist.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 })
 }
 
-function runTests (objectStorage: boolean) {
+function runTests (enableObjectStorage: boolean) {
   let servers: PeerTubeServer[] = []
   let videoUUID: string
   let publishedAt: string
 
   let shouldBeDeleted: string[]
+  const objectStorage = new ObjectStorageCommand()
 
   before(async function () {
     this.timeout(120000)
 
-    const config = objectStorage
-      ? ObjectStorageCommand.getDefaultMockConfig()
+    const config = enableObjectStorage
+      ? objectStorage.getDefaultMockConfig()
       : {}
 
     // Run server 2 to have transcoding enabled
@@ -60,7 +61,7 @@ function runTests (objectStorage: boolean) {
 
     await doubleFollow(servers[0], servers[1])
 
-    if (objectStorage) await ObjectStorageCommand.prepareDefaultMockBuckets()
+    if (enableObjectStorage) await objectStorage.prepareDefaultMockBuckets()
 
     const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' })
     videoUUID = shortUUID
@@ -91,7 +92,7 @@ function runTests (objectStorage: boolean) {
       expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
       expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
 
-      if (objectStorage) await checkFilesInObjectStorage(videoDetails)
+      if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
     }
   })
 
@@ -112,7 +113,7 @@ function runTests (objectStorage: boolean) {
       expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
       expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
 
-      if (objectStorage) await checkFilesInObjectStorage(videoDetails)
+      if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
     }
   })
 
@@ -132,7 +133,7 @@ function runTests (objectStorage: boolean) {
       expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
       expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
 
-      if (objectStorage) await checkFilesInObjectStorage(videoDetails)
+      if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
     }
   })
 
@@ -151,7 +152,7 @@ function runTests (objectStorage: boolean) {
       expect(videoDetails.files).to.have.lengthOf(5)
       expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
 
-      if (objectStorage) await checkFilesInObjectStorage(videoDetails)
+      if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
     }
   })
 
@@ -185,7 +186,7 @@ function runTests (objectStorage: boolean) {
       expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
       expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(1)
 
-      if (objectStorage) await checkFilesInObjectStorage(videoDetails)
+      if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails)
 
       shouldBeDeleted = [
         videoDetails.streamingPlaylists[0].files[0].fileUrl,
@@ -219,8 +220,8 @@ function runTests (objectStorage: boolean) {
       expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
       expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
 
-      if (objectStorage) {
-        await checkFilesInObjectStorage(videoDetails)
+      if (enableObjectStorage) {
+        await checkFilesInObjectStorage(objectStorage, videoDetails)
 
         const hlsPlaylist = videoDetails.streamingPlaylists[0]
         const resolutions = hlsPlaylist.files.map(f => f.resolution.id)
@@ -245,6 +246,8 @@ function runTests (objectStorage: boolean) {
   })
 
   after(async function () {
+    if (objectStorage) await objectStorage.cleanupMock()
+
     await cleanupTests(servers)
   })
 }
index b6e4fe8e5a52d7be4b58bec68b056ab75e137f4c..c668d7e0bca6210eb93444c179051c9dc0139935 100644 (file)
@@ -150,17 +150,23 @@ describe('Test HLS videos', function () {
   describe('With object storage enabled', function () {
     if (areMockObjectStorageTestsDisabled()) return
 
+    const objectStorage = new ObjectStorageCommand()
+
     before(async function () {
       this.timeout(120000)
 
-      const configOverride = ObjectStorageCommand.getDefaultMockConfig()
-      await ObjectStorageCommand.prepareDefaultMockBuckets()
+      const configOverride = objectStorage.getDefaultMockConfig()
+      await objectStorage.prepareDefaultMockBuckets()
 
       await servers[0].kill()
       await servers[0].run(configOverride)
     })
 
-    runTestSuite(true, ObjectStorageCommand.getMockPlaylistBaseUrl())
+    runTestSuite(true, objectStorage.getMockPlaylistBaseUrl())
+
+    after(async function () {
+      await objectStorage.cleanupMock()
+    })
   })
 
   after(async function () {
index f4d7281188664367568c905dd5d6d7751dc91b69..61655f102100dbb133d17cf9d72f6f06743ba1c9 100644 (file)
@@ -135,17 +135,23 @@ describe('Test update video privacy while transcoding', function () {
   describe('With object storage enabled', function () {
     if (areMockObjectStorageTestsDisabled()) return
 
+    const objectStorage = new ObjectStorageCommand()
+
     before(async function () {
       this.timeout(120000)
 
-      const configOverride = ObjectStorageCommand.getDefaultMockConfig()
-      await ObjectStorageCommand.prepareDefaultMockBuckets()
+      const configOverride = objectStorage.getDefaultMockConfig()
+      await objectStorage.prepareDefaultMockBuckets()
 
       await servers[0].kill()
       await servers[0].run(configOverride)
     })
 
-    runTestSuite(true, ObjectStorageCommand.getMockPlaylistBaseUrl())
+    runTestSuite(true, objectStorage.getMockPlaylistBaseUrl())
+
+    after(async function () {
+      await objectStorage.cleanupMock()
+    })
   })
 
   after(async function () {
index 35efc3d4976745968707b8e8210cda49789dc498..d1298caf7d06db6a70c4a731a88db26c1891cf7a 100644 (file)
@@ -326,11 +326,13 @@ describe('Test video studio', function () {
   describe('Object storage studio edition', function () {
     if (areMockObjectStorageTestsDisabled()) return
 
+    const objectStorage = new ObjectStorageCommand()
+
     before(async function () {
-      await ObjectStorageCommand.prepareDefaultMockBuckets()
+      await objectStorage.prepareDefaultMockBuckets()
 
       await servers[0].kill()
-      await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
+      await servers[0].run(objectStorage.getDefaultMockConfig())
 
       await servers[0].config.enableMinimumTranscoding()
     })
@@ -353,16 +355,20 @@ describe('Test video studio', function () {
         }
 
         for (const webtorrentFile of video.files) {
-          expectStartWith(webtorrentFile.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+          expectStartWith(webtorrentFile.fileUrl, objectStorage.getMockWebVideosBaseUrl())
         }
 
         for (const hlsFile of video.streamingPlaylists[0].files) {
-          expectStartWith(hlsFile.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
+          expectStartWith(hlsFile.fileUrl, objectStorage.getMockPlaylistBaseUrl())
         }
 
         await checkVideoDuration(server, videoUUID, 9)
       }
     })
+
+    after(async function () {
+      await objectStorage.cleanupMock()
+    })
   })
 
   after(async function () {
index 3ece4f2ec293ef75932c9833ebb58078f6737597..edd727967c7818f1d290de2e88f79324e21bf221 100644 (file)
@@ -25,25 +25,27 @@ function assertVideoProperties (video: VideoFile, resolution: number, extname: s
   if (size) expect(video.size).to.equal(size)
 }
 
-async function checkFiles (video: VideoDetails, objectStorage: boolean) {
+async function checkFiles (video: VideoDetails, objectStorage: ObjectStorageCommand) {
   for (const file of video.files) {
-    if (objectStorage) expectStartWith(file.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+    if (objectStorage) expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl())
 
     await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
   }
 }
 
-function runTests (objectStorage: boolean) {
+function runTests (enableObjectStorage: boolean) {
   let video1ShortId: string
   let video2UUID: string
 
   let servers: PeerTubeServer[] = []
 
+  const objectStorage = new ObjectStorageCommand()
+
   before(async function () {
     this.timeout(90000)
 
-    const config = objectStorage
-      ? ObjectStorageCommand.getDefaultMockConfig()
+    const config = enableObjectStorage
+      ? objectStorage.getDefaultMockConfig()
       : {}
 
     // Run server 2 to have transcoding enabled
@@ -52,7 +54,7 @@ function runTests (objectStorage: boolean) {
 
     await doubleFollow(servers[0], servers[1])
 
-    if (objectStorage) await ObjectStorageCommand.prepareDefaultMockBuckets()
+    if (enableObjectStorage) await objectStorage.prepareDefaultMockBuckets()
 
     // Upload two videos for our needs
     {
@@ -90,7 +92,7 @@ function runTests (objectStorage: boolean) {
       assertVideoProperties(originalVideo, 720, 'webm', 218910)
       assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
 
-      await checkFiles(videoDetails, objectStorage)
+      await checkFiles(videoDetails, enableObjectStorage && objectStorage)
     }
   })
 
@@ -114,7 +116,7 @@ function runTests (objectStorage: boolean) {
       assertVideoProperties(transcodedVideo320, 360, 'mp4')
       assertVideoProperties(transcodedVideo240, 240, 'mp4')
 
-      await checkFiles(videoDetails, objectStorage)
+      await checkFiles(videoDetails, enableObjectStorage && objectStorage)
     }
   })
 
@@ -136,7 +138,7 @@ function runTests (objectStorage: boolean) {
       assertVideoProperties(video720, 720, 'webm', 942961)
       assertVideoProperties(video480, 480, 'webm', 69217)
 
-      await checkFiles(videoDetails, objectStorage)
+      await checkFiles(videoDetails, enableObjectStorage && objectStorage)
     }
   })
 
@@ -146,6 +148,8 @@ function runTests (objectStorage: boolean) {
   })
 
   after(async function () {
+    await objectStorage.cleanupMock()
+
     await cleanupTests(servers)
   })
 }
index 4927e0309b6e0bb35b1ff6a8e08ad729fed7d56a..33a8cb9f9929df9fb4a34ae9547bc67168cbd122 100644 (file)
@@ -15,10 +15,10 @@ import {
 } from '@shared/server-commands'
 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)
@@ -26,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]
@@ -46,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)
@@ -56,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()
 
@@ -68,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)
       }
     }
   })
@@ -95,14 +96,14 @@ 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)
       }
     }
   })
index e7ef941c642b5a6a8c9343e92913515f3688e234..c2ca1de96edbf3950153b300ef3dab2ee86af250 100644 (file)
@@ -31,8 +31,8 @@ describe('Test Live transcoding in peertube-runner program', function () {
   let sqlCommandServer1: SQLCommand
 
   function runSuite (options: {
-    objectStorage: boolean
-  }) {
+    objectStorage?: ObjectStorageCommand
+  } = {}) {
     const { objectStorage } = options
 
     it('Should enable transcoding without additional resolutions', async function () {
@@ -117,7 +117,7 @@ describe('Test Live transcoding in peertube-runner program', function () {
 
         for (const file of files) {
           if (objectStorage) {
-            expectStartWith(file.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
+            expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl())
           }
 
           await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
@@ -155,24 +155,30 @@ describe('Test Live transcoding in peertube-runner program', function () {
       await servers[0].config.enableTranscoding(true, false, true)
     })
 
-    runSuite({ objectStorage: false })
+    runSuite()
   })
 
   describe('With lives on object storage', function () {
     if (areMockObjectStorageTestsDisabled()) return
 
+    const objectStorage = new ObjectStorageCommand()
+
     before(async function () {
-      await ObjectStorageCommand.prepareDefaultMockBuckets()
+      await objectStorage.prepareDefaultMockBuckets()
 
       await servers[0].kill()
 
-      await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
+      await servers[0].run(objectStorage.getDefaultMockConfig())
 
       // Wait for peertube runner socket reconnection
       await wait(1500)
     })
 
-    runSuite({ objectStorage: true })
+    runSuite({ objectStorage })
+
+    after(async function () {
+      await objectStorage.cleanupMock()
+    })
   })
 
   describe('Check cleanup', function () {
index 400203eb33b2a3f6be827648a0bc2def22814698..69b38a53641776a6e6197540324e6edb13710eab 100644 (file)
@@ -19,8 +19,8 @@ describe('Test studio transcoding in peertube-runner program', function () {
   let peertubeRunner: PeerTubeRunnerProcess
 
   function runSuite (options: {
-    objectStorage: boolean
-  }) {
+    objectStorage?: ObjectStorageCommand
+  } = {}) {
     const { objectStorage } = options
 
     it('Should run a complex studio transcoding', async function () {
@@ -45,11 +45,11 @@ describe('Test studio transcoding in peertube-runner program', function () {
 
         if (objectStorage) {
           for (const webtorrentFile of video.files) {
-            expectStartWith(webtorrentFile.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+            expectStartWith(webtorrentFile.fileUrl, objectStorage.getMockWebVideosBaseUrl())
           }
 
           for (const hlsFile of video.streamingPlaylists[0].files) {
-            expectStartWith(hlsFile.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
+            expectStartWith(hlsFile.fileUrl, objectStorage.getMockPlaylistBaseUrl())
           }
         }
 
@@ -80,24 +80,30 @@ describe('Test studio transcoding in peertube-runner program', function () {
   })
 
   describe('With videos on local filesystem storage', function () {
-    runSuite({ objectStorage: false })
+    runSuite()
   })
 
   describe('With videos on object storage', function () {
     if (areMockObjectStorageTestsDisabled()) return
 
+    const objectStorage = new ObjectStorageCommand()
+
     before(async function () {
-      await ObjectStorageCommand.prepareDefaultMockBuckets()
+      await objectStorage.prepareDefaultMockBuckets()
 
       await servers[0].kill()
 
-      await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
+      await servers[0].run(objectStorage.getDefaultMockConfig())
 
       // Wait for peertube runner socket reconnection
       await wait(1500)
     })
 
-    runSuite({ objectStorage: true })
+    runSuite({ objectStorage })
+
+    after(async function () {
+      await objectStorage.cleanupMock()
+    })
   })
 
   describe('Check cleanup', function () {
index dc505baab38c07318027de787bf9f56615e80f7e..aefec394d4e2d02b434a7891a17e6586d83b59e3 100644 (file)
@@ -26,16 +26,16 @@ describe('Test VOD transcoding in peertube-runner program', function () {
   function runSuite (options: {
     webtorrentEnabled: boolean
     hlsEnabled: boolean
-    objectStorage: boolean
+    objectStorage?: ObjectStorageCommand
   }) {
     const { webtorrentEnabled, hlsEnabled, objectStorage } = options
 
     const objectStorageBaseUrlWebTorrent = objectStorage
-      ? ObjectStorageCommand.getMockWebTorrentBaseUrl()
+      ? objectStorage.getMockWebVideosBaseUrl()
       : undefined
 
     const objectStorageBaseUrlHLS = objectStorage
-      ? ObjectStorageCommand.getMockPlaylistBaseUrl()
+      ? objectStorage.getMockPlaylistBaseUrl()
       : undefined
 
     it('Should upload a classic video mp4 and transcode it', async function () {
@@ -262,7 +262,7 @@ describe('Test VOD transcoding in peertube-runner program', function () {
         await servers[0].config.enableTranscoding(true, false, true)
       })
 
-      runSuite({ webtorrentEnabled: true, hlsEnabled: false, objectStorage: false })
+      runSuite({ webtorrentEnabled: true, hlsEnabled: false })
     })
 
     describe('HLS videos only enabled', function () {
@@ -271,7 +271,7 @@ describe('Test VOD transcoding in peertube-runner program', function () {
         await servers[0].config.enableTranscoding(false, true, true)
       })
 
-      runSuite({ webtorrentEnabled: false, hlsEnabled: true, objectStorage: false })
+      runSuite({ webtorrentEnabled: false, hlsEnabled: true })
     })
 
     describe('Web video & HLS enabled', function () {
@@ -280,19 +280,21 @@ describe('Test VOD transcoding in peertube-runner program', function () {
         await servers[0].config.enableTranscoding(true, true, true)
       })
 
-      runSuite({ webtorrentEnabled: true, hlsEnabled: true, objectStorage: false })
+      runSuite({ webtorrentEnabled: true, hlsEnabled: true })
     })
   })
 
   describe('With videos on object storage', function () {
     if (areMockObjectStorageTestsDisabled()) return
 
+    const objectStorage = new ObjectStorageCommand()
+
     before(async function () {
-      await ObjectStorageCommand.prepareDefaultMockBuckets()
+      await objectStorage.prepareDefaultMockBuckets()
 
       await servers[0].kill()
 
-      await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
+      await servers[0].run(objectStorage.getDefaultMockConfig())
 
       // Wait for peertube runner socket reconnection
       await wait(1500)
@@ -304,7 +306,7 @@ describe('Test VOD transcoding in peertube-runner program', function () {
         await servers[0].config.enableTranscoding(true, false, true)
       })
 
-      runSuite({ webtorrentEnabled: true, hlsEnabled: false, objectStorage: true })
+      runSuite({ webtorrentEnabled: true, hlsEnabled: false, objectStorage })
     })
 
     describe('HLS videos only enabled', function () {
@@ -313,7 +315,7 @@ describe('Test VOD transcoding in peertube-runner program', function () {
         await servers[0].config.enableTranscoding(false, true, true)
       })
 
-      runSuite({ webtorrentEnabled: false, hlsEnabled: true, objectStorage: true })
+      runSuite({ webtorrentEnabled: false, hlsEnabled: true, objectStorage })
     })
 
     describe('Web video & HLS enabled', function () {
@@ -322,7 +324,11 @@ describe('Test VOD transcoding in peertube-runner program', function () {
         await servers[0].config.enableTranscoding(true, true, true)
       })
 
-      runSuite({ webtorrentEnabled: true, hlsEnabled: true, objectStorage: true })
+      runSuite({ webtorrentEnabled: true, hlsEnabled: true, objectStorage })
+    })
+
+    after(async function () {
+      await objectStorage.cleanupMock()
     })
   })
 
index 8f837c97a41995f9a870fa0ba93bfa9f6c1eecfd..9d8c1d941890d58f8678f5f4ec8687815a1bda94 100644 (file)
@@ -46,7 +46,7 @@ async function testLiveVideoResolutions (options: {
   resolutions: number[]
   transcoded: boolean
 
-  objectStorage: boolean
+  objectStorage?: ObjectStorageCommand
   objectStorageBaseUrl?: string
 }) {
   const {
@@ -57,7 +57,7 @@ async function testLiveVideoResolutions (options: {
     resolutions,
     transcoded,
     objectStorage,
-    objectStorageBaseUrl = ObjectStorageCommand.getMockPlaylistBaseUrl()
+    objectStorageBaseUrl = objectStorage?.getMockPlaylistBaseUrl()
   } = options
 
   for (const server of servers) {
@@ -76,7 +76,7 @@ async function testLiveVideoResolutions (options: {
       playlistUrl: hlsPlaylist.playlistUrl,
       resolutions,
       transcoded,
-      withRetry: objectStorage
+      withRetry: !!objectStorage
     })
 
     if (objectStorage) {
@@ -105,7 +105,7 @@ async function testLiveVideoResolutions (options: {
 
       const subPlaylist = await originServer.streamingPlaylists.get({
         url: `${baseUrl}/${video.uuid}/${i}.m3u8`,
-        withRetry: objectStorage // With object storage, the request may fail because of inconsistent data in S3
+        withRetry: !!objectStorage // With object storage, the request may fail because of inconsistent data in S3
       })
 
       expect(subPlaylist).to.contain(segmentName)
@@ -116,7 +116,7 @@ async function testLiveVideoResolutions (options: {
         videoUUID: video.uuid,
         segmentName,
         hlsPlaylist,
-        withRetry: objectStorage // With object storage, the request may fail because of inconsistent data in S3
+        withRetry: !!objectStorage // With object storage, the request may fail because of inconsistent data in S3
       })
 
       if (originServer.internalServerNumber === server.internalServerNumber) {
index a1fe4f0f7670f33574967c8e72d4ec77d2e3d49c..7d8ec93cd8a31a52eb1f4519c0bfcdcfc26df16f 100644 (file)
@@ -1,34 +1,17 @@
-
+import { randomInt } from 'crypto'
 import { HttpStatusCode } from '@shared/models'
 import { makePostBodyRequest } from '../requests'
-import { AbstractCommand } from '../shared'
-
-export class ObjectStorageCommand extends AbstractCommand {
-  static readonly DEFAULT_PLAYLIST_MOCK_BUCKET = 'streaming-playlists'
-  static readonly DEFAULT_WEBTORRENT_MOCK_BUCKET = 'videos'
 
+export class ObjectStorageCommand {
   static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test'
 
-  // ---------------------------------------------------------------------------
-
-  static getDefaultMockConfig () {
-    return {
-      object_storage: {
-        enabled: true,
-        endpoint: 'http://' + this.getMockEndpointHost(),
-        region: this.getMockRegion(),
-
-        credentials: this.getMockCredentialsConfig(),
+  private readonly bucketsCreated: string[] = []
+  private readonly seed: number
 
-        streaming_playlists: {
-          bucket_name: this.DEFAULT_PLAYLIST_MOCK_BUCKET
-        },
+  // ---------------------------------------------------------------------------
 
-        videos: {
-          bucket_name: this.DEFAULT_WEBTORRENT_MOCK_BUCKET
-        }
-      }
-    }
+  constructor () {
+    this.seed = randomInt(0, 10000)
   }
 
   static getMockCredentialsConfig () {
@@ -46,35 +29,79 @@ export class ObjectStorageCommand extends AbstractCommand {
     return 'us-east-1'
   }
 
-  static getMockWebTorrentBaseUrl () {
-    return `http://${this.DEFAULT_WEBTORRENT_MOCK_BUCKET}.${this.getMockEndpointHost()}/`
+  getDefaultMockConfig () {
+    return {
+      object_storage: {
+        enabled: true,
+        endpoint: 'http://' + ObjectStorageCommand.getMockEndpointHost(),
+        region: ObjectStorageCommand.getMockRegion(),
+
+        credentials: ObjectStorageCommand.getMockCredentialsConfig(),
+
+        streaming_playlists: {
+          bucket_name: this.getMockStreamingPlaylistsBucketName()
+        },
+
+        videos: {
+          bucket_name: this.getMockWebVideosBucketName()
+        }
+      }
+    }
   }
 
-  static getMockPlaylistBaseUrl () {
-    return `http://${this.DEFAULT_PLAYLIST_MOCK_BUCKET}.${this.getMockEndpointHost()}/`
+  getMockWebVideosBaseUrl () {
+    return `http://${this.getMockWebVideosBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/`
   }
 
-  static async prepareDefaultMockBuckets () {
-    await this.createMockBucket(this.DEFAULT_PLAYLIST_MOCK_BUCKET)
-    await this.createMockBucket(this.DEFAULT_WEBTORRENT_MOCK_BUCKET)
+  getMockPlaylistBaseUrl () {
+    return `http://${this.getMockStreamingPlaylistsBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/`
   }
 
-  static async createMockBucket (name: string) {
+  async prepareDefaultMockBuckets () {
+    await this.createMockBucket(this.getMockStreamingPlaylistsBucketName())
+    await this.createMockBucket(this.getMockWebVideosBucketName())
+  }
+
+  async createMockBucket (name: string) {
+    this.bucketsCreated.push(name)
+
+    await this.deleteMockBucket(name)
+
     await makePostBodyRequest({
-      url: this.getMockEndpointHost(),
-      path: '/ui/' + name + '?delete',
+      url: ObjectStorageCommand.getMockEndpointHost(),
+      path: '/ui/' + name + '?create',
       expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
     })
 
     await makePostBodyRequest({
-      url: this.getMockEndpointHost(),
-      path: '/ui/' + name + '?create',
+      url: ObjectStorageCommand.getMockEndpointHost(),
+      path: '/ui/' + name + '?make-public',
       expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
     })
+  }
 
+  async cleanupMock () {
+    for (const name of this.bucketsCreated) {
+      await this.deleteMockBucket(name)
+    }
+  }
+
+  getMockStreamingPlaylistsBucketName (name = 'streaming-playlists') {
+    return this.getMockBucketName(name)
+  }
+
+  getMockWebVideosBucketName (name = 'web-videos') {
+    return this.getMockBucketName(name)
+  }
+
+  getMockBucketName (name: string) {
+    return `${this.seed}-${name}`
+  }
+
+  private async deleteMockBucket (name: string) {
     await makePostBodyRequest({
-      url: this.getMockEndpointHost(),
-      path: '/ui/' + name + '?make-public',
+      url: ObjectStorageCommand.getMockEndpointHost(),
+      path: '/ui/' + name + '?delete',
       expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
     })
   }
index 66b7ff09d2702733423583fcdcbdca6cbf716612..70f7a3ee21e339252244a0fbd5f4f87f39f36db2 100644 (file)
@@ -48,7 +48,6 @@ import { DebugCommand } from './debug-command'
 import { FollowsCommand } from './follows-command'
 import { JobsCommand } from './jobs-command'
 import { MetricsCommand } from './metrics-command'
-import { ObjectStorageCommand } from './object-storage-command'
 import { PluginsCommand } from './plugins-command'
 import { RedundancyCommand } from './redundancy-command'
 import { ServersCommand } from './servers-command'
@@ -140,7 +139,6 @@ export class PeerTubeServer {
   servers?: ServersCommand
   login?: LoginCommand
   users?: UsersCommand
-  objectStorage?: ObjectStorageCommand
   videoStudio?: VideoStudioCommand
   videos?: VideosCommand
   videoStats?: VideoStatsCommand
@@ -429,7 +427,6 @@ export class PeerTubeServer {
     this.login = new LoginCommand(this)
     this.users = new UsersCommand(this)
     this.videos = new VideosCommand(this)
-    this.objectStorage = new ObjectStorageCommand(this)
     this.videoStudio = new VideoStudioCommand(this)
     this.videoStats = new VideoStatsCommand(this)
     this.views = new ViewsCommand(this)
index 73f4eefd331a94086c625b55b41c1898d0f6aeff..44d625970010d26a9d365fd40736de99365cf021 100644 (file)
@@ -192,7 +192,7 @@ export class LiveCommand extends AbstractCommand {
     videoUUID: string
     playlistNumber: number
     segment: number
-    objectStorage: boolean
+    objectStorage?: ObjectStorageCommand
     objectStorageBaseUrl?: string
   }) {
     const {
@@ -201,12 +201,12 @@ export class LiveCommand extends AbstractCommand {
       playlistNumber,
       segment,
       videoUUID,
-      objectStorageBaseUrl = ObjectStorageCommand.getMockPlaylistBaseUrl()
+      objectStorageBaseUrl
     } = options
 
     const segmentName = `${playlistNumber}-00000${segment}.ts`
     const baseUrl = objectStorage
-      ? join(objectStorageBaseUrl, 'hls')
+      ? join(objectStorageBaseUrl || objectStorage.getMockPlaylistBaseUrl(), 'hls')
       : server.url + '/static/streaming-playlists/hls'
 
     let error = true
@@ -226,7 +226,7 @@ export class LiveCommand extends AbstractCommand {
         const hlsPlaylist = video.streamingPlaylists[0]
 
         // Check SHA generation
-        const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: objectStorage })
+        const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: !!objectStorage })
         if (!shaBody[segmentName]) {
           throw new Error('Segment SHA does not exist')
         }
@@ -261,13 +261,13 @@ export class LiveCommand extends AbstractCommand {
     videoUUID: string
     playlistNumber: number
     segment: number
-    objectStorage?: boolean // default false
+    objectStorage?: ObjectStorageCommand
   }) {
-    const { playlistNumber, segment, videoUUID, objectStorage = false } = options
+    const { playlistNumber, segment, videoUUID, objectStorage } = options
 
     const segmentName = `${playlistNumber}-00000${segment}.ts`
     const baseUrl = objectStorage
-      ? ObjectStorageCommand.getMockPlaylistBaseUrl()
+      ? objectStorage.getMockPlaylistBaseUrl()
       : `${this.server.url}/static/streaming-playlists/hls`
 
     const url = `${baseUrl}/${videoUUID}/${segmentName}`
@@ -284,12 +284,12 @@ export class LiveCommand extends AbstractCommand {
   getPlaylistFile (options: OverrideCommandOptions & {
     videoUUID: string
     playlistName: string
-    objectStorage?: boolean // default false
+    objectStorage?: ObjectStorageCommand
   }) {
-    const { playlistName, videoUUID, objectStorage = false } = options
+    const { playlistName, videoUUID, objectStorage } = options
 
     const baseUrl = objectStorage
-      ? ObjectStorageCommand.getMockPlaylistBaseUrl()
+      ? objectStorage.getMockPlaylistBaseUrl()
       : `${this.server.url}/static/streaming-playlists/hls`
 
     const url = `${baseUrl}/${videoUUID}/${playlistName}`