]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/shared/live.ts
Add runner server tests
[github/Chocobozzz/PeerTube.git] / server / tests / shared / live.ts
index 78e29f575cb1a9347e8bcb4b88a01f6863da7533..31f92ef19a568b5c5396d58d31eba97784b9924a 100644 (file)
@@ -3,14 +3,31 @@
 import { expect } from 'chai'
 import { pathExists, readdir } from 'fs-extra'
 import { join } from 'path'
+import { sha1 } from '@shared/extra-utils'
 import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models'
 import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands'
+import { SQLCommand } from './sql-command'
 import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists'
 
-async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) {
+async function checkLiveCleanup (options: {
+  server: PeerTubeServer
+  videoUUID: string
+  permanent: boolean
+  savedResolutions?: number[]
+}) {
+  const { server, videoUUID, permanent, savedResolutions = [] } = options
+
   const basePath = server.servers.buildDirectory('streaming-playlists')
   const hlsPath = join(basePath, 'hls', videoUUID)
 
+  if (permanent) {
+    if (!await pathExists(hlsPath)) return
+
+    const files = await readdir(hlsPath)
+    expect(files).to.have.lengthOf(0)
+    return
+  }
+
   if (savedResolutions.length === 0) {
     return checkUnsavedLiveCleanup(server, videoUUID, hlsPath)
   }
@@ -20,15 +37,28 @@ async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, save
 
 // ---------------------------------------------------------------------------
 
-async function testVideoResolutions (options: {
+async function testLiveVideoResolutions (options: {
+  sqlCommand: SQLCommand
   originServer: PeerTubeServer
+
   servers: PeerTubeServer[]
   liveVideoId: string
   resolutions: number[]
   transcoded: boolean
+
   objectStorage: boolean
+  objectStorageBaseUrl?: string
 }) {
-  const { originServer, servers, liveVideoId, resolutions, transcoded, objectStorage } = options
+  const {
+    originServer,
+    sqlCommand,
+    servers,
+    liveVideoId,
+    resolutions,
+    transcoded,
+    objectStorage,
+    objectStorageBaseUrl = ObjectStorageCommand.getMockPlaylistBaseUrl()
+  } = options
 
   for (const server of servers) {
     const { data } = await server.videos.list()
@@ -50,7 +80,7 @@ async function testVideoResolutions (options: {
     })
 
     if (objectStorage) {
-      expect(hlsPlaylist.playlistUrl).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl())
+      expect(hlsPlaylist.playlistUrl).to.contain(objectStorageBaseUrl)
     }
 
     for (let i = 0; i < resolutions.length; i++) {
@@ -61,15 +91,16 @@ async function testVideoResolutions (options: {
         videoUUID: video.uuid,
         playlistNumber: i,
         segment: segmentNum,
-        objectStorage
+        objectStorage,
+        objectStorageBaseUrl
       })
 
       const baseUrl = objectStorage
-        ? ObjectStorageCommand.getMockPlaylistBaseUrl() + 'hls'
+        ? join(objectStorageBaseUrl, 'hls')
         : originServer.url + '/static/streaming-playlists/hls'
 
       if (objectStorage) {
-        expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl())
+        expect(hlsPlaylist.segmentsSha256Url).to.contain(objectStorageBaseUrl)
       }
 
       const subPlaylist = await originServer.streamingPlaylists.get({
@@ -86,6 +117,13 @@ async function testVideoResolutions (options: {
         segmentName,
         hlsPlaylist
       })
+
+      if (originServer.internalServerNumber === server.internalServerNumber) {
+        const infohash = sha1(`${2 + hlsPlaylist.playlistUrl}+V${i}`)
+        const dbInfohashes = await sqlCommand.getPlaylistInfohash(hlsPlaylist.id)
+
+        expect(dbInfohashes).to.include(infohash)
+      }
     }
   }
 }
@@ -94,7 +132,7 @@ async function testVideoResolutions (options: {
 
 export {
   checkLiveCleanup,
-  testVideoResolutions
+  testLiveVideoResolutions
 }
 
 // ---------------------------------------------------------------------------