diff options
Diffstat (limited to 'server/tests/cli/create-import-video-file-job.ts')
-rw-r--r-- | server/tests/cli/create-import-video-file-job.ts | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts deleted file mode 100644 index edd727967..000000000 --- a/server/tests/cli/create-import-video-file-job.ts +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' | ||
5 | import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } 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 { expectStartWith } from '../shared' | ||
17 | |||
18 | function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) { | ||
19 | expect(video).to.have.nested.property('resolution.id', resolution) | ||
20 | expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`) | ||
21 | expect(video).to.have.property('fileUrl').that.includes(`.${extname}`) | ||
22 | expect(video).to.have.property('magnetUri').that.includes(`.${extname}`) | ||
23 | expect(video).to.have.property('size').that.is.above(0) | ||
24 | |||
25 | if (size) expect(video.size).to.equal(size) | ||
26 | } | ||
27 | |||
28 | async function checkFiles (video: VideoDetails, objectStorage: ObjectStorageCommand) { | ||
29 | for (const file of video.files) { | ||
30 | if (objectStorage) expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl()) | ||
31 | |||
32 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | ||
33 | } | ||
34 | } | ||
35 | |||
36 | function runTests (enableObjectStorage: boolean) { | ||
37 | let video1ShortId: string | ||
38 | let video2UUID: string | ||
39 | |||
40 | let servers: PeerTubeServer[] = [] | ||
41 | |||
42 | const objectStorage = new ObjectStorageCommand() | ||
43 | |||
44 | before(async function () { | ||
45 | this.timeout(90000) | ||
46 | |||
47 | const config = enableObjectStorage | ||
48 | ? objectStorage.getDefaultMockConfig() | ||
49 | : {} | ||
50 | |||
51 | // Run server 2 to have transcoding enabled | ||
52 | servers = await createMultipleServers(2, config) | ||
53 | await setAccessTokensToServers(servers) | ||
54 | |||
55 | await doubleFollow(servers[0], servers[1]) | ||
56 | |||
57 | if (enableObjectStorage) await objectStorage.prepareDefaultMockBuckets() | ||
58 | |||
59 | // Upload two videos for our needs | ||
60 | { | ||
61 | const { shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video1' } }) | ||
62 | video1ShortId = shortUUID | ||
63 | } | ||
64 | |||
65 | { | ||
66 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } }) | ||
67 | video2UUID = uuid | ||
68 | } | ||
69 | |||
70 | await waitJobs(servers) | ||
71 | |||
72 | for (const server of servers) { | ||
73 | await server.config.enableTranscoding() | ||
74 | } | ||
75 | }) | ||
76 | |||
77 | it('Should run a import job on video 1 with a lower resolution', async function () { | ||
78 | const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short_480.webm` | ||
79 | await servers[0].cli.execWithEnv(command) | ||
80 | |||
81 | await waitJobs(servers) | ||
82 | |||
83 | for (const server of servers) { | ||
84 | const { data: videos } = await server.videos.list() | ||
85 | expect(videos).to.have.lengthOf(2) | ||
86 | |||
87 | const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId) | ||
88 | const videoDetails = await server.videos.get({ id: video.shortUUID }) | ||
89 | |||
90 | expect(videoDetails.files).to.have.lengthOf(2) | ||
91 | const [ originalVideo, transcodedVideo ] = videoDetails.files | ||
92 | assertVideoProperties(originalVideo, 720, 'webm', 218910) | ||
93 | assertVideoProperties(transcodedVideo, 480, 'webm', 69217) | ||
94 | |||
95 | await checkFiles(videoDetails, enableObjectStorage && objectStorage) | ||
96 | } | ||
97 | }) | ||
98 | |||
99 | it('Should run a import job on video 2 with the same resolution and a different extension', async function () { | ||
100 | const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv` | ||
101 | await servers[1].cli.execWithEnv(command) | ||
102 | |||
103 | await waitJobs(servers) | ||
104 | |||
105 | for (const server of servers) { | ||
106 | const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE }) | ||
107 | expect(videos).to.have.lengthOf(2) | ||
108 | |||
109 | const video = videos.find(({ uuid }) => uuid === video2UUID) | ||
110 | const videoDetails = await server.videos.get({ id: video.uuid }) | ||
111 | |||
112 | expect(videoDetails.files).to.have.lengthOf(4) | ||
113 | const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files | ||
114 | assertVideoProperties(originalVideo, 720, 'ogv', 140849) | ||
115 | assertVideoProperties(transcodedVideo420, 480, 'mp4') | ||
116 | assertVideoProperties(transcodedVideo320, 360, 'mp4') | ||
117 | assertVideoProperties(transcodedVideo240, 240, 'mp4') | ||
118 | |||
119 | await checkFiles(videoDetails, enableObjectStorage && objectStorage) | ||
120 | } | ||
121 | }) | ||
122 | |||
123 | it('Should run a import job on video 2 with the same resolution and the same extension', async function () { | ||
124 | const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short2.webm` | ||
125 | await servers[0].cli.execWithEnv(command) | ||
126 | |||
127 | await waitJobs(servers) | ||
128 | |||
129 | for (const server of servers) { | ||
130 | const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE }) | ||
131 | expect(videos).to.have.lengthOf(2) | ||
132 | |||
133 | const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId) | ||
134 | const videoDetails = await server.videos.get({ id: video.uuid }) | ||
135 | |||
136 | expect(videoDetails.files).to.have.lengthOf(2) | ||
137 | const [ video720, video480 ] = videoDetails.files | ||
138 | assertVideoProperties(video720, 720, 'webm', 942961) | ||
139 | assertVideoProperties(video480, 480, 'webm', 69217) | ||
140 | |||
141 | await checkFiles(videoDetails, enableObjectStorage && objectStorage) | ||
142 | } | ||
143 | }) | ||
144 | |||
145 | it('Should not have run transcoding after an import job', async function () { | ||
146 | const { data } = await servers[0].jobs.list({ jobType: 'video-transcoding' }) | ||
147 | expect(data).to.have.lengthOf(0) | ||
148 | }) | ||
149 | |||
150 | after(async function () { | ||
151 | await objectStorage.cleanupMock() | ||
152 | |||
153 | await cleanupTests(servers) | ||
154 | }) | ||
155 | } | ||
156 | |||
157 | describe('Test create import video jobs', function () { | ||
158 | |||
159 | describe('On filesystem', function () { | ||
160 | runTests(false) | ||
161 | }) | ||
162 | |||
163 | describe('On object storage', function () { | ||
164 | if (areMockObjectStorageTestsDisabled()) return | ||
165 | |||
166 | runTests(true) | ||
167 | }) | ||
168 | }) | ||