1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { areObjectStorageTestsDisabled } from '@shared/core-utils'
4 import { HttpStatusCode, VideoDetails } from '@shared/models'
12 setAccessTokensToServers,
14 } from '@shared/server-commands'
15 import { expectStartWith } from '../shared'
17 async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) {
18 for (const file of video.files) {
19 const start = inObjectStorage
20 ? ObjectStorageCommand.getWebTorrentBaseUrl()
23 expectStartWith(file.fileUrl, start)
25 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
28 const start = inObjectStorage
29 ? ObjectStorageCommand.getPlaylistBaseUrl()
32 const hls = video.streamingPlaylists[0]
33 expectStartWith(hls.playlistUrl, start)
34 expectStartWith(hls.segmentsSha256Url, start)
36 for (const file of hls.files) {
37 expectStartWith(file.fileUrl, start)
39 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
43 describe('Test create move video storage job', function () {
44 if (areObjectStorageTestsDisabled()) return
46 let servers: PeerTubeServer[] = []
47 const uuids: string[] = []
49 before(async function () {
52 // Run server 2 to have transcoding enabled
53 servers = await createMultipleServers(2)
54 await setAccessTokensToServers(servers)
56 await doubleFollow(servers[0], servers[1])
58 await ObjectStorageCommand.prepareDefaultBuckets()
60 await servers[0].config.enableTranscoding()
62 for (let i = 0; i < 3; i++) {
63 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
67 await waitJobs(servers)
69 await servers[0].kill()
70 await servers[0].run(ObjectStorageCommand.getDefaultConfig())
73 it('Should move only one file', async function () {
76 const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}`
77 await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultConfig())
78 await waitJobs(servers)
80 for (const server of servers) {
81 const video = await server.videos.get({ id: uuids[1] })
83 await checkFiles(servers[0], video, true)
85 for (const id of [ uuids[0], uuids[2] ]) {
86 const video = await server.videos.get({ id })
88 await checkFiles(servers[0], video, false)
93 it('Should move all files', async function () {
96 const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos`
97 await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultConfig())
98 await waitJobs(servers)
100 for (const server of servers) {
101 for (const id of [ uuids[0], uuids[2] ]) {
102 const video = await server.videos.get({ id })
104 await checkFiles(servers[0], video, true)
109 after(async function () {
110 await cleanupTests(servers)