]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/create-move-video-storage-job.ts
253fc983e5bd277be2dcd2d3d88acb4beb50aa13
[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, objectStorage?: ObjectStorageCommand) {
19 for (const file of video.files) {
20 const start = objectStorage
21 ? objectStorage.getMockWebVideosBaseUrl()
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 = objectStorage
30 ? objectStorage.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 const objectStorage = new ObjectStorageCommand()
50
51 before(async function () {
52 this.timeout(360000)
53
54 // Run server 2 to have transcoding enabled
55 servers = await createMultipleServers(2)
56 await setAccessTokensToServers(servers)
57
58 await doubleFollow(servers[0], servers[1])
59
60 await objectStorage.prepareDefaultMockBuckets()
61
62 await servers[0].config.enableTranscoding()
63
64 for (let i = 0; i < 3; i++) {
65 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
66 uuids.push(uuid)
67 }
68
69 await waitJobs(servers)
70
71 await servers[0].kill()
72 await servers[0].run(objectStorage.getDefaultMockConfig())
73 })
74
75 it('Should move only one file', async function () {
76 this.timeout(120000)
77
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)
81
82 for (const server of servers) {
83 const video = await server.videos.get({ id: uuids[1] })
84
85 await checkFiles(servers[0], video, objectStorage)
86
87 for (const id of [ uuids[0], uuids[2] ]) {
88 const video = await server.videos.get({ id })
89
90 await checkFiles(servers[0], video)
91 }
92 }
93 })
94
95 it('Should move all files', async function () {
96 this.timeout(120000)
97
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)
101
102 for (const server of servers) {
103 for (const id of [ uuids[0], uuids[2] ]) {
104 const video = await server.videos.get({ id })
105
106 await checkFiles(servers[0], video, objectStorage)
107 }
108 }
109 })
110
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'))
114
115 await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls'), [ 'private' ])
116 await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls', 'private'))
117 })
118
119 after(async function () {
120 await objectStorage.cleanupMock()
121
122 await cleanupTests(servers)
123 })
124 })