]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/create-move-video-storage-job.ts
feat: show contained playlists under My videos (#5125)
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-move-video-storage-job.ts
CommitLineData
e1ab52d7 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
c55e3d72
C
3import { areObjectStorageTestsDisabled } from '@shared/core-utils'
4import { HttpStatusCode, VideoDetails } from '@shared/models'
e1ab52d7 5import {
e1ab52d7 6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
e1ab52d7 9 makeRawRequest,
10 ObjectStorageCommand,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 waitJobs
bf54587a 14} from '@shared/server-commands'
c55e3d72 15import { expectStartWith } from '../shared'
e1ab52d7 16
17async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) {
18 for (const file of video.files) {
19 const start = inObjectStorage
20 ? ObjectStorageCommand.getWebTorrentBaseUrl()
21 : origin.url
22
23 expectStartWith(file.fileUrl, start)
24
25 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
26 }
27
28 const start = inObjectStorage
29 ? ObjectStorageCommand.getPlaylistBaseUrl()
30 : origin.url
31
32 const hls = video.streamingPlaylists[0]
33 expectStartWith(hls.playlistUrl, start)
34 expectStartWith(hls.segmentsSha256Url, start)
35
36 for (const file of hls.files) {
37 expectStartWith(file.fileUrl, start)
38
39 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
40 }
41}
42
43describe('Test create move video storage job', function () {
44 if (areObjectStorageTestsDisabled()) return
45
46 let servers: PeerTubeServer[] = []
47 const uuids: string[] = []
48
49 before(async function () {
50 this.timeout(360000)
51
52 // Run server 2 to have transcoding enabled
53 servers = await createMultipleServers(2)
54 await setAccessTokensToServers(servers)
55
56 await doubleFollow(servers[0], servers[1])
57
58 await ObjectStorageCommand.prepareDefaultBuckets()
59
60 await servers[0].config.enableTranscoding()
61
62 for (let i = 0; i < 3; i++) {
63 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
64 uuids.push(uuid)
65 }
66
67 await waitJobs(servers)
68
69 await servers[0].kill()
70 await servers[0].run(ObjectStorageCommand.getDefaultConfig())
71 })
72
73 it('Should move only one file', async function () {
74 this.timeout(120000)
75
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)
79
80 for (const server of servers) {
81 const video = await server.videos.get({ id: uuids[1] })
82
83 await checkFiles(servers[0], video, true)
84
85 for (const id of [ uuids[0], uuids[2] ]) {
86 const video = await server.videos.get({ id })
87
88 await checkFiles(servers[0], video, false)
89 }
90 }
91 })
92
93 it('Should move all files', async function () {
94 this.timeout(120000)
95
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)
99
100 for (const server of servers) {
101 for (const id of [ uuids[0], uuids[2] ]) {
102 const video = await server.videos.get({ id })
103
104 await checkFiles(servers[0], video, true)
105 }
106 }
107 })
108
109 after(async function () {
110 await cleanupTests(servers)
111 })
112})