]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/create-move-video-storage-job.ts
Fix s3 mock cleanup
[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
b52f5048 3import { join } from 'path'
9ab330b9 4import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
c55e3d72 5import { HttpStatusCode, VideoDetails } from '@shared/models'
e1ab52d7 6import {
e1ab52d7 7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
e1ab52d7 10 makeRawRequest,
11 ObjectStorageCommand,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 waitJobs
bf54587a 15} from '@shared/server-commands'
b52f5048 16import { checkDirectoryIsEmpty, expectStartWith } from '../shared'
e1ab52d7 17
f8918990 18async function checkFiles (origin: PeerTubeServer, video: VideoDetails, objectStorage?: ObjectStorageCommand) {
e1ab52d7 19 for (const file of video.files) {
f8918990
C
20 const start = objectStorage
21 ? objectStorage.getMockWebVideosBaseUrl()
e1ab52d7 22 : origin.url
23
24 expectStartWith(file.fileUrl, start)
25
3545e72c 26 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
e1ab52d7 27 }
28
f8918990
C
29 const start = objectStorage
30 ? objectStorage.getMockPlaylistBaseUrl()
e1ab52d7 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
3545e72c 40 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
e1ab52d7 41 }
42}
43
44describe('Test create move video storage job', function () {
9ab330b9 45 if (areMockObjectStorageTestsDisabled()) return
e1ab52d7 46
47 let servers: PeerTubeServer[] = []
48 const uuids: string[] = []
f8918990 49 const objectStorage = new ObjectStorageCommand()
e1ab52d7 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
f8918990 60 await objectStorage.prepareDefaultMockBuckets()
e1ab52d7 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()
f8918990 72 await servers[0].run(objectStorage.getDefaultMockConfig())
e1ab52d7 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]}`
f8918990 79 await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig())
e1ab52d7 80 await waitJobs(servers)
81
82 for (const server of servers) {
83 const video = await server.videos.get({ id: uuids[1] })
84
f8918990 85 await checkFiles(servers[0], video, objectStorage)
e1ab52d7 86
87 for (const id of [ uuids[0], uuids[2] ]) {
88 const video = await server.videos.get({ id })
89
f8918990 90 await checkFiles(servers[0], video)
e1ab52d7 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`
f8918990 99 await servers[0].cli.execWithEnv(command, objectStorage.getDefaultMockConfig())
e1ab52d7 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
f8918990 106 await checkFiles(servers[0], video, objectStorage)
e1ab52d7 107 }
108 }
109 })
110
b52f5048
C
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
e1ab52d7 119 after(async function () {
cffef253
C
120 await objectStorage.cleanupMock()
121
e1ab52d7 122 await cleanupTests(servers)
123 })
124})