aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/cli
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 09:43:59 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit6c5065a011b099618681a37bd77eaa7bd3db752e (patch)
tree352252a00b25013c4b1902f6bcd9668aba295c7b /server/tests/cli
parent0d8ecb7592577f54012413a2b5a9b159cfc90399 (diff)
downloadPeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.tar.gz
PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.tar.zst
PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.zip
Introduce server commands
Diffstat (limited to 'server/tests/cli')
-rw-r--r--server/tests/cli/optimize-old-videos.ts3
-rw-r--r--server/tests/cli/prune-storage.ts31
-rw-r--r--server/tests/cli/regenerate-thumbnails.ts5
3 files changed, 18 insertions, 21 deletions
diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts
index bd15012fe..e369a3305 100644
--- a/server/tests/cli/optimize-old-videos.ts
+++ b/server/tests/cli/optimize-old-videos.ts
@@ -4,7 +4,6 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import { 6import {
7 buildServerDirectory,
8 cleanupTests, 7 cleanupTests,
9 doubleFollow, 8 doubleFollow,
10 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -96,7 +95,7 @@ describe('Test optimize old videos', function () {
96 95
97 expect(file.size).to.be.below(8000000) 96 expect(file.size).to.be.below(8000000)
98 97
99 const path = buildServerDirectory(servers[0], join('videos', video.uuid + '-' + file.resolution.id + '.mp4')) 98 const path = servers[0].serversCommand.buildDirectory(join('videos', video.uuid + '-' + file.resolution.id + '.mp4'))
100 const bitrate = await getVideoFileBitrate(path) 99 const bitrate = await getVideoFileBitrate(path)
101 const fps = await getVideoFileFPS(path) 100 const fps = await getVideoFileFPS(path)
102 const resolution = await getVideoFileResolution(path) 101 const resolution = await getVideoFileResolution(path)
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index d4dbee682..68a59a41d 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -7,7 +7,6 @@ import { join } from 'path'
7import { buildUUID } from '@server/helpers/uuid' 7import { buildUUID } from '@server/helpers/uuid'
8import { HttpStatusCode } from '@shared/core-utils' 8import { HttpStatusCode } from '@shared/core-utils'
9import { 9import {
10 buildServerDirectory,
11 cleanupTests, 10 cleanupTests,
12 CLICommand, 11 CLICommand,
13 doubleFollow, 12 doubleFollow,
@@ -26,14 +25,14 @@ import { VideoPlaylistPrivacy } from '@shared/models'
26 25
27const expect = chai.expect 26const expect = chai.expect
28 27
29async function countFiles (internalServerNumber: number, directory: string) { 28async function countFiles (server: ServerInfo, directory: string) {
30 const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) 29 const files = await readdir(server.serversCommand.buildDirectory(directory))
31 30
32 return files.length 31 return files.length
33} 32}
34 33
35async function assertNotExists (internalServerNumber: number, directory: string, substring: string) { 34async function assertNotExists (server: ServerInfo, directory: string, substring: string) {
36 const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) 35 const files = await readdir(server.serversCommand.buildDirectory(directory))
37 36
38 for (const f of files) { 37 for (const f of files) {
39 expect(f).to.not.contain(substring) 38 expect(f).to.not.contain(substring)
@@ -42,19 +41,19 @@ async function assertNotExists (internalServerNumber: number, directory: string,
42 41
43async function assertCountAreOkay (servers: ServerInfo[]) { 42async function assertCountAreOkay (servers: ServerInfo[]) {
44 for (const server of servers) { 43 for (const server of servers) {
45 const videosCount = await countFiles(server.internalServerNumber, 'videos') 44 const videosCount = await countFiles(server, 'videos')
46 expect(videosCount).to.equal(8) 45 expect(videosCount).to.equal(8)
47 46
48 const torrentsCount = await countFiles(server.internalServerNumber, 'torrents') 47 const torrentsCount = await countFiles(server, 'torrents')
49 expect(torrentsCount).to.equal(16) 48 expect(torrentsCount).to.equal(16)
50 49
51 const previewsCount = await countFiles(server.internalServerNumber, 'previews') 50 const previewsCount = await countFiles(server, 'previews')
52 expect(previewsCount).to.equal(2) 51 expect(previewsCount).to.equal(2)
53 52
54 const thumbnailsCount = await countFiles(server.internalServerNumber, 'thumbnails') 53 const thumbnailsCount = await countFiles(server, 'thumbnails')
55 expect(thumbnailsCount).to.equal(6) 54 expect(thumbnailsCount).to.equal(6)
56 55
57 const avatarsCount = await countFiles(server.internalServerNumber, 'avatars') 56 const avatarsCount = await countFiles(server, 'avatars')
58 expect(avatarsCount).to.equal(2) 57 expect(avatarsCount).to.equal(2)
59 } 58 }
60} 59}
@@ -122,7 +121,7 @@ describe('Test prune storage scripts', function () {
122 it('Should create some dirty files', async function () { 121 it('Should create some dirty files', async function () {
123 for (let i = 0; i < 2; i++) { 122 for (let i = 0; i < 2; i++) {
124 { 123 {
125 const base = buildServerDirectory(servers[0], 'videos') 124 const base = servers[0].serversCommand.buildDirectory('videos')
126 125
127 const n1 = buildUUID() + '.mp4' 126 const n1 = buildUUID() + '.mp4'
128 const n2 = buildUUID() + '.webm' 127 const n2 = buildUUID() + '.webm'
@@ -134,7 +133,7 @@ describe('Test prune storage scripts', function () {
134 } 133 }
135 134
136 { 135 {
137 const base = buildServerDirectory(servers[0], 'torrents') 136 const base = servers[0].serversCommand.buildDirectory('torrents')
138 137
139 const n1 = buildUUID() + '-240.torrent' 138 const n1 = buildUUID() + '-240.torrent'
140 const n2 = buildUUID() + '-480.torrent' 139 const n2 = buildUUID() + '-480.torrent'
@@ -146,7 +145,7 @@ describe('Test prune storage scripts', function () {
146 } 145 }
147 146
148 { 147 {
149 const base = buildServerDirectory(servers[0], 'thumbnails') 148 const base = servers[0].serversCommand.buildDirectory('thumbnails')
150 149
151 const n1 = buildUUID() + '.jpg' 150 const n1 = buildUUID() + '.jpg'
152 const n2 = buildUUID() + '.jpg' 151 const n2 = buildUUID() + '.jpg'
@@ -158,7 +157,7 @@ describe('Test prune storage scripts', function () {
158 } 157 }
159 158
160 { 159 {
161 const base = buildServerDirectory(servers[0], 'previews') 160 const base = servers[0].serversCommand.buildDirectory('previews')
162 161
163 const n1 = buildUUID() + '.jpg' 162 const n1 = buildUUID() + '.jpg'
164 const n2 = buildUUID() + '.jpg' 163 const n2 = buildUUID() + '.jpg'
@@ -170,7 +169,7 @@ describe('Test prune storage scripts', function () {
170 } 169 }
171 170
172 { 171 {
173 const base = buildServerDirectory(servers[0], 'avatars') 172 const base = servers[0].serversCommand.buildDirectory('avatars')
174 173
175 const n1 = buildUUID() + '.png' 174 const n1 = buildUUID() + '.png'
176 const n2 = buildUUID() + '.jpg' 175 const n2 = buildUUID() + '.jpg'
@@ -195,7 +194,7 @@ describe('Test prune storage scripts', function () {
195 194
196 for (const directory of Object.keys(badNames)) { 195 for (const directory of Object.keys(badNames)) {
197 for (const name of badNames[directory]) { 196 for (const name of badNames[directory]) {
198 await assertNotExists(servers[0].internalServerNumber, directory, name) 197 await assertNotExists(servers[0], directory, name)
199 } 198 }
200 } 199 }
201 }) 200 })
diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.ts
index 1b460e9c0..68a4711b6 100644
--- a/server/tests/cli/regenerate-thumbnails.ts
+++ b/server/tests/cli/regenerate-thumbnails.ts
@@ -4,7 +4,6 @@ import { writeFile } from 'fs-extra'
4import { basename, join } from 'path' 4import { basename, join } from 'path'
5import { Video, VideoDetails } from '@shared/models' 5import { Video, VideoDetails } from '@shared/models'
6import { 6import {
7 buildServerDirectory,
8 cleanupTests, 7 cleanupTests,
9 doubleFollow, 8 doubleFollow,
10 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -50,7 +49,7 @@ describe('Test regenerate thumbnails script', function () {
50 const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid 49 const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid
51 video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body)) 50 video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body))
52 51
53 thumbnail1Path = join(buildServerDirectory(servers[0], 'thumbnails'), basename(video1.thumbnailPath)) 52 thumbnail1Path = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(video1.thumbnailPath))
54 53
55 const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid 54 const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid
56 video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body)) 55 video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body))
@@ -62,7 +61,7 @@ describe('Test regenerate thumbnails script', function () {
62 61
63 remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body)) 62 remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body))
64 63
65 thumbnailRemotePath = join(buildServerDirectory(servers[0], 'thumbnails'), basename(remoteVideo.thumbnailPath)) 64 thumbnailRemotePath = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath))
66 } 65 }
67 66
68 await writeFile(thumbnail1Path, '') 67 await writeFile(thumbnail1Path, '')