1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { join } from 'path'
4 import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
5 import { HttpStatusCode, VideoDetails } from '@shared/models'
13 setAccessTokensToServers,
15 } from '@shared/server-commands'
16 import { checkDirectoryIsEmpty, expectStartWith } from '../shared'
18 async function checkFiles (origin: PeerTubeServer, video: VideoDetails, objectStorage?: ObjectStorageCommand) {
19 for (const file of video.files) {
20 const start = objectStorage
21 ? objectStorage.getMockWebVideosBaseUrl()
24 expectStartWith(file.fileUrl, start)
26 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
29 const start = objectStorage
30 ? objectStorage.getMockPlaylistBaseUrl()
33 const hls = video.streamingPlaylists[0]
34 expectStartWith(hls.playlistUrl, start)
35 expectStartWith(hls.segmentsSha256Url, start)
37 for (const file of hls.files) {
38 expectStartWith(file.fileUrl, start)
40 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
44 describe('Test create move video storage job', function () {
45 if (areMockObjectStorageTestsDisabled()) return
47 let servers: PeerTubeServer[] = []
48 const uuids: string[] = []
49 const objectStorage = new ObjectStorageCommand()
51 before(async function () {
54 // Run server 2 to have transcoding enabled
55 servers = await createMultipleServers(2)
56 await setAccessTokensToServers(servers)
58 await doubleFollow(servers[0], servers[1])
60 await objectStorage.prepareDefaultMockBuckets()
62 await servers[0].config.enableTranscoding()
64 for (let i = 0; i < 3; i++) {
65 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
69 await waitJobs(servers)
71 await servers[0].kill()
72 await servers[0].run(objectStorage.getDefaultMockConfig())
75 it('Should move only one file', async function () {
78 const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}`
79 await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig())
80 await waitJobs(servers)
82 for (const server of servers) {
83 const video = await server.videos.get({ id: uuids[1] })
85 await checkFiles(servers[0], video, objectStorage)
87 for (const id of [ uuids[0], uuids[2] ]) {
88 const video = await server.videos.get({ id })
90 await checkFiles(servers[0], video)
95 it('Should move all files', async function () {
98 const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos`
99 await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig())
100 await waitJobs(servers)
102 for (const server of servers) {
103 for (const id of [ uuids[0], uuids[2] ]) {
104 const video = await server.videos.get({ id })
106 await checkFiles(servers[0], video, objectStorage)
111 it('Should not have files on disk anymore', async function () {
112 await checkDirectoryIsEmpty(servers[0], 'videos', [ 'private' ])
113 await checkDirectoryIsEmpty(servers[0], join('videos', 'private'))
115 await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls'), [ 'private' ])
116 await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls', 'private'))
119 after(async function () {
120 await objectStorage.cleanupMock()
122 await cleanupTests(servers)