video-imports.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import { expect } from 'chai'
  3. import { expectStartWith, FIXTURE_URLS } from '@server/tests/shared'
  4. import { areObjectStorageTestsDisabled } from '@shared/core-utils'
  5. import { HttpStatusCode, VideoPrivacy } from '@shared/models'
  6. import {
  7. createSingleServer,
  8. killallServers,
  9. makeRawRequest,
  10. ObjectStorageCommand,
  11. PeerTubeServer,
  12. setAccessTokensToServers,
  13. setDefaultVideoChannel,
  14. waitJobs
  15. } from '@shared/server-commands'
  16. async function importVideo (server: PeerTubeServer) {
  17. const attributes = {
  18. name: 'import 2',
  19. privacy: VideoPrivacy.PUBLIC,
  20. channelId: server.store.channel.id,
  21. targetUrl: FIXTURE_URLS.goodVideo720
  22. }
  23. const { video: { uuid } } = await server.imports.importVideo({ attributes })
  24. return uuid
  25. }
  26. describe('Object storage for video import', function () {
  27. if (areObjectStorageTestsDisabled()) return
  28. let server: PeerTubeServer
  29. before(async function () {
  30. this.timeout(120000)
  31. await ObjectStorageCommand.prepareDefaultBuckets()
  32. server = await createSingleServer(1, ObjectStorageCommand.getDefaultConfig())
  33. await setAccessTokensToServers([ server ])
  34. await setDefaultVideoChannel([ server ])
  35. await server.config.enableImports()
  36. })
  37. describe('Without transcoding', async function () {
  38. before(async function () {
  39. await server.config.disableTranscoding()
  40. })
  41. it('Should import a video and have sent it to object storage', async function () {
  42. this.timeout(120000)
  43. const uuid = await importVideo(server)
  44. await waitJobs(server)
  45. const video = await server.videos.get({ id: uuid })
  46. expect(video.files).to.have.lengthOf(1)
  47. expect(video.streamingPlaylists).to.have.lengthOf(0)
  48. const fileUrl = video.files[0].fileUrl
  49. expectStartWith(fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
  50. await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.OK_200 })
  51. })
  52. })
  53. describe('With transcoding', async function () {
  54. before(async function () {
  55. await server.config.enableTranscoding()
  56. })
  57. it('Should import a video and have sent it to object storage', async function () {
  58. this.timeout(120000)
  59. const uuid = await importVideo(server)
  60. await waitJobs(server)
  61. const video = await server.videos.get({ id: uuid })
  62. expect(video.files).to.have.lengthOf(5)
  63. expect(video.streamingPlaylists).to.have.lengthOf(1)
  64. expect(video.streamingPlaylists[0].files).to.have.lengthOf(5)
  65. for (const file of video.files) {
  66. expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
  67. await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
  68. }
  69. for (const file of video.streamingPlaylists[0].files) {
  70. expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
  71. await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
  72. }
  73. })
  74. })
  75. after(async function () {
  76. await killallServers([ server ])
  77. })
  78. })