aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/cli/create-move-video-storage-job.ts
diff options
context:
space:
mode:
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>2021-11-09 11:05:35 +0100
committerGitHub <noreply@github.com>2021-11-09 11:05:35 +0100
commite1ab52d7ec7370a6f9f5937192d6003206af1ac0 (patch)
treeaecc8b696b0021e073fd205dd6e126fb4f178e8f /server/tests/cli/create-move-video-storage-job.ts
parentc49c366ac320fe5ac3dc08f5891fe5898c1b34e3 (diff)
downloadPeerTube-e1ab52d7ec7370a6f9f5937192d6003206af1ac0.tar.gz
PeerTube-e1ab52d7ec7370a6f9f5937192d6003206af1ac0.tar.zst
PeerTube-e1ab52d7ec7370a6f9f5937192d6003206af1ac0.zip
Add migrate-to-object-storage script (#4481)
* add migrate-to-object-storage-script closes #4467 * add migrate-to-unique-playlist-filenames script * fix(migrate-to-unique-playlist-filenames): update master/segments256 run updateMasterHLSPlaylist and updateSha256VODSegments after file rename. * Improve move to object storage scripts * PR remarks Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'server/tests/cli/create-move-video-storage-job.ts')
-rw-r--r--server/tests/cli/create-move-video-storage-job.ts114
1 files changed, 114 insertions, 0 deletions
diff --git a/server/tests/cli/create-move-video-storage-job.ts b/server/tests/cli/create-move-video-storage-job.ts
new file mode 100644
index 000000000..b598c8359
--- /dev/null
+++ b/server/tests/cli/create-move-video-storage-job.ts
@@ -0,0 +1,114 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4
5import {
6 areObjectStorageTestsDisabled,
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 expectStartWith,
11 makeRawRequest,
12 ObjectStorageCommand,
13 PeerTubeServer,
14 setAccessTokensToServers,
15 waitJobs
16} from '@shared/extra-utils'
17import { HttpStatusCode, VideoDetails } from '@shared/models'
18
19async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) {
20 for (const file of video.files) {
21 const start = inObjectStorage
22 ? ObjectStorageCommand.getWebTorrentBaseUrl()
23 : origin.url
24
25 expectStartWith(file.fileUrl, start)
26
27 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
28 }
29
30 const start = inObjectStorage
31 ? ObjectStorageCommand.getPlaylistBaseUrl()
32 : origin.url
33
34 const hls = video.streamingPlaylists[0]
35 expectStartWith(hls.playlistUrl, start)
36 expectStartWith(hls.segmentsSha256Url, start)
37
38 for (const file of hls.files) {
39 expectStartWith(file.fileUrl, start)
40
41 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
42 }
43}
44
45describe('Test create move video storage job', function () {
46 if (areObjectStorageTestsDisabled()) return
47
48 let servers: PeerTubeServer[] = []
49 const uuids: string[] = []
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 ObjectStorageCommand.prepareDefaultBuckets()
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(ObjectStorageCommand.getDefaultConfig())
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, ObjectStorageCommand.getDefaultConfig())
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, true)
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, false)
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, ObjectStorageCommand.getDefaultConfig())
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, true)
107 }
108 }
109 })
110
111 after(async function () {
112 await cleanupTests(servers)
113 })
114})