]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/cli/create-import-video-file-job.ts
Merge branch 'release/4.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-import-video-file-job.ts
index bddcff5e70590ba3e1c549ad4fc2f948b3643e1f..c06b9550cb4d611216c657f9c15da7aa2978d850 100644 (file)
@@ -2,8 +2,19 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
-import { VideoFile } from '@shared/models'
+import {
+  areObjectStorageTestsDisabled,
+  cleanupTests,
+  createMultipleServers,
+  doubleFollow,
+  expectStartWith,
+  makeRawRequest,
+  ObjectStorageCommand,
+  PeerTubeServer,
+  setAccessTokensToServers,
+  waitJobs
+} from '@shared/extra-utils'
+import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } from '@shared/models'
 
 const expect = chai.expect
 
@@ -17,26 +28,39 @@ function assertVideoProperties (video: VideoFile, resolution: number, extname: s
   if (size) expect(video.size).to.equal(size)
 }
 
-describe('Test create import video jobs', function () {
-  this.timeout(60000)
+async function checkFiles (video: VideoDetails, objectStorage: boolean) {
+  for (const file of video.files) {
+    if (objectStorage) expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
 
-  let servers: PeerTubeServer[] = []
-  let video1UUID: string
+    await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
+  }
+}
+
+function runTests (objectStorage: boolean) {
+  let video1ShortId: string
   let video2UUID: string
 
+  let servers: PeerTubeServer[] = []
+
   before(async function () {
     this.timeout(90000)
 
+    const config = objectStorage
+      ? ObjectStorageCommand.getDefaultConfig()
+      : {}
+
     // Run server 2 to have transcoding enabled
-    servers = await createMultipleServers(2)
+    servers = await createMultipleServers(2, config)
     await setAccessTokensToServers(servers)
 
     await doubleFollow(servers[0], servers[1])
 
+    if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
+
     // Upload two videos for our needs
     {
-      const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
-      video1UUID = uuid
+      const { shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
+      video1ShortId = shortUUID
     }
 
     {
@@ -44,12 +68,15 @@ describe('Test create import video jobs', function () {
       video2UUID = uuid
     }
 
-    // Transcoding
     await waitJobs(servers)
+
+    for (const server of servers) {
+      await server.config.enableTranscoding()
+    }
   })
 
   it('Should run a import job on video 1 with a lower resolution', async function () {
-    const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`
+    const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short-480.webm`
     await servers[0].cli.execWithEnv(command)
 
     await waitJobs(servers)
@@ -58,13 +85,15 @@ describe('Test create import video jobs', function () {
       const { data: videos } = await server.videos.list()
       expect(videos).to.have.lengthOf(2)
 
-      const video = videos.find(({ uuid }) => uuid === video1UUID)
-      const videoDetails = await server.videos.get({ id: video.uuid })
+      const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
+      const videoDetails = await server.videos.get({ id: video.shortUUID })
 
       expect(videoDetails.files).to.have.lengthOf(2)
       const [ originalVideo, transcodedVideo ] = videoDetails.files
       assertVideoProperties(originalVideo, 720, 'webm', 218910)
       assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
+
+      await checkFiles(videoDetails, objectStorage)
     }
   })
 
@@ -75,7 +104,7 @@ describe('Test create import video jobs', function () {
     await waitJobs(servers)
 
     for (const server of servers) {
-      const { data: videos } = await server.videos.list()
+      const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE })
       expect(videos).to.have.lengthOf(2)
 
       const video = videos.find(({ uuid }) => uuid === video2UUID)
@@ -87,30 +116,52 @@ describe('Test create import video jobs', function () {
       assertVideoProperties(transcodedVideo420, 480, 'mp4')
       assertVideoProperties(transcodedVideo320, 360, 'mp4')
       assertVideoProperties(transcodedVideo240, 240, 'mp4')
+
+      await checkFiles(videoDetails, objectStorage)
     }
   })
 
   it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
-    const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`
+    const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short2.webm`
     await servers[0].cli.execWithEnv(command)
 
     await waitJobs(servers)
 
     for (const server of servers) {
-      const { data: videos } = await server.videos.list()
+      const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE })
       expect(videos).to.have.lengthOf(2)
 
-      const video = videos.find(({ uuid }) => uuid === video1UUID)
+      const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
       const videoDetails = await server.videos.get({ id: video.uuid })
 
       expect(videoDetails.files).to.have.lengthOf(2)
       const [ video720, video480 ] = videoDetails.files
       assertVideoProperties(video720, 720, 'webm', 942961)
       assertVideoProperties(video480, 480, 'webm', 69217)
+
+      await checkFiles(videoDetails, objectStorage)
     }
   })
 
+  it('Should not have run transcoding after an import job', async function () {
+    const { data } = await servers[0].jobs.list({ jobType: 'video-transcoding' })
+    expect(data).to.have.lengthOf(0)
+  })
+
   after(async function () {
     await cleanupTests(servers)
   })
+}
+
+describe('Test create import video jobs', function () {
+
+  describe('On filesystem', function () {
+    runTests(false)
+  })
+
+  describe('On object storage', function () {
+    if (areObjectStorageTestsDisabled()) return
+
+    runTests(true)
+  })
 })