]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/object-storage/videos.ts
Merge branch 'release/5.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / object-storage / videos.ts
index d1875febb941053651677e1fd3483ab25c5893d2..6aaf32c345a35fee83be6ee4498903f34fde98da 100644 (file)
@@ -9,7 +9,7 @@ import {
   expectLogDoesNotContain,
   expectStartWith,
   generateHighBitrateVideo,
-  MockObjectStorage
+  MockObjectStorageProxy
 } from '@server/tests/shared'
 import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
 import { HttpStatusCode, VideoDetails } from '@shared/models'
@@ -26,8 +26,12 @@ import {
   waitJobs,
   webtorrentAdd
 } from '@shared/server-commands'
+import { sha1 } from '@shared/extra-utils'
 
 async function checkFiles (options: {
+  server: PeerTubeServer
+  originServer: PeerTubeServer
+
   video: VideoDetails
 
   baseMockUrl?: string
@@ -39,6 +43,8 @@ async function checkFiles (options: {
   webtorrentPrefix?: string
 }) {
   const {
+    server,
+    originServer,
     video,
     playlistBucket,
     webtorrentBucket,
@@ -86,6 +92,7 @@ async function checkFiles (options: {
     const resSha = await makeRawRequest({ url: hls.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 })
     expect(JSON.stringify(resSha.body)).to.not.throw
 
+    let i = 0
     for (const file of hls.files) {
       expectStartWith(file.fileUrl, start)
 
@@ -94,6 +101,15 @@ async function checkFiles (options: {
       expectStartWith(location, start)
 
       await makeRawRequest({ url: location, expectedStatus: HttpStatusCode.OK_200 })
+
+      if (originServer.internalServerNumber === server.internalServerNumber) {
+        const infohash = sha1(`${2 + hls.playlistUrl}+V${i}`)
+        const dbInfohashes = await originServer.sql.getPlaylistInfohash(hls.id)
+
+        expect(dbInfohashes).to.include(infohash)
+      }
+
+      i++
     }
   }
 
@@ -124,7 +140,7 @@ function runTestSuite (options: {
 
   useMockBaseUrl?: boolean
 }) {
-  const mockObjectStorage = new MockObjectStorage()
+  const mockObjectStorageProxy = new MockObjectStorageProxy()
   const { fixture } = options
   let baseMockUrl: string
 
@@ -138,8 +154,10 @@ function runTestSuite (options: {
   before(async function () {
     this.timeout(120000)
 
-    const port = await mockObjectStorage.initialize()
-    baseMockUrl = options.useMockBaseUrl ? `http://localhost:${port}` : undefined
+    const port = await mockObjectStorageProxy.initialize()
+    baseMockUrl = options.useMockBaseUrl
+      ? `http://127.0.0.1:${port}`
+      : undefined
 
     await ObjectStorageCommand.createMockBucket(options.playlistBucket)
     await ObjectStorageCommand.createMockBucket(options.webtorrentBucket)
@@ -196,7 +214,7 @@ function runTestSuite (options: {
 
     for (const server of servers) {
       const video = await server.videos.get({ id: uuid })
-      const files = await checkFiles({ ...options, video, baseMockUrl })
+      const files = await checkFiles({ ...options, server, originServer: servers[0], video, baseMockUrl })
 
       deletedUrls = deletedUrls.concat(files)
     }
@@ -212,7 +230,7 @@ function runTestSuite (options: {
 
     for (const server of servers) {
       const video = await server.videos.get({ id: uuid })
-      const files = await checkFiles({ ...options, video, baseMockUrl })
+      const files = await checkFiles({ ...options, server, originServer: servers[0], video, baseMockUrl })
 
       deletedUrls = deletedUrls.concat(files)
     }
@@ -254,7 +272,7 @@ function runTestSuite (options: {
   })
 
   after(async function () {
-    await mockObjectStorage.terminate()
+    await mockObjectStorageProxy.terminate()
 
     await cleanupTests(servers)
   })