]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/create-move-video-storage-job.ts
4927e0309b6e0bb35b1ff6a8e08ad729fed7d56a
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-move-video-storage-job.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { join } from 'path'
4 import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
5 import { HttpStatusCode, VideoDetails } from '@shared/models'
6 import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 makeRawRequest,
11 ObjectStorageCommand,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 waitJobs
15 } from '@shared/server-commands'
16 import { checkDirectoryIsEmpty, expectStartWith } from '../shared'
17
18 async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) {
19 for (const file of video.files) {
20 const start = inObjectStorage
21 ? ObjectStorageCommand.getMockWebTorrentBaseUrl()
22 : origin.url
23
24 expectStartWith(file.fileUrl, start)
25
26 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
27 }
28
29 const start = inObjectStorage
30 ? ObjectStorageCommand.getMockPlaylistBaseUrl()
31 : origin.url
32
33 const hls = video.streamingPlaylists[0]
34 expectStartWith(hls.playlistUrl, start)
35 expectStartWith(hls.segmentsSha256Url, start)
36
37 for (const file of hls.files) {
38 expectStartWith(file.fileUrl, start)
39
40 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
41 }
42 }
43
44 describe('Test create move video storage job', function () {
45 if (areMockObjectStorageTestsDisabled()) return
46
47 let servers: PeerTubeServer[] = []
48 const uuids: string[] = []
49
50 before(async function () {
51 this.timeout(360000)
52
53 // Run server 2 to have transcoding enabled
54 servers = await createMultipleServers(2)
55 await setAccessTokensToServers(servers)
56
57 await doubleFollow(servers[0], servers[1])
58
59 await ObjectStorageCommand.prepareDefaultMockBuckets()
60
61 await servers[0].config.enableTranscoding()
62
63 for (let i = 0; i < 3; i++) {
64 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
65 uuids.push(uuid)
66 }
67
68 await waitJobs(servers)
69
70 await servers[0].kill()
71 await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
72 })
73
74 it('Should move only one file', async function () {
75 this.timeout(120000)
76
77 const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}`
78 await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig())
79 await waitJobs(servers)
80
81 for (const server of servers) {
82 const video = await server.videos.get({ id: uuids[1] })
83
84 await checkFiles(servers[0], video, true)
85
86 for (const id of [ uuids[0], uuids[2] ]) {
87 const video = await server.videos.get({ id })
88
89 await checkFiles(servers[0], video, false)
90 }
91 }
92 })
93
94 it('Should move all files', async function () {
95 this.timeout(120000)
96
97 const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos`
98 await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig())
99 await waitJobs(servers)
100
101 for (const server of servers) {
102 for (const id of [ uuids[0], uuids[2] ]) {
103 const video = await server.videos.get({ id })
104
105 await checkFiles(servers[0], video, true)
106 }
107 }
108 })
109
110 it('Should not have files on disk anymore', async function () {
111 await checkDirectoryIsEmpty(servers[0], 'videos', [ 'private' ])
112 await checkDirectoryIsEmpty(servers[0], join('videos', 'private'))
113
114 await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls'), [ 'private' ])
115 await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls', 'private'))
116 })
117
118 after(async function () {
119 await cleanupTests(servers)
120 })
121 })