aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/cli/prune-storage.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/cli/prune-storage.ts')
-rw-r--r--server/tests/cli/prune-storage.ts87
1 files changed, 38 insertions, 49 deletions
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index a0af09de8..954a87833 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -5,87 +5,78 @@ import * as chai from 'chai'
5import { createFile, readdir } from 'fs-extra' 5import { createFile, readdir } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { buildUUID } from '@server/helpers/uuid' 7import { buildUUID } from '@server/helpers/uuid'
8import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
9import { 8import {
10 buildServerDirectory,
11 cleanupTests, 9 cleanupTests,
12 createVideoPlaylist, 10 CLICommand,
11 createMultipleServers,
13 doubleFollow, 12 doubleFollow,
14 execCLI,
15 flushAndRunMultipleServers,
16 getAccount,
17 getEnvCli,
18 killallServers, 13 killallServers,
19 makeGetRequest, 14 makeGetRequest,
20 ServerInfo, 15 PeerTubeServer,
21 setAccessTokensToServers, 16 setAccessTokensToServers,
22 setDefaultVideoChannel, 17 setDefaultVideoChannel,
23 updateMyAvatar, 18 wait,
24 uploadVideo, 19 waitJobs
25 wait 20} from '@shared/extra-utils'
26} from '../../../shared/extra-utils' 21import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
27import { waitJobs } from '../../../shared/extra-utils/server/jobs'
28import { Account, VideoPlaylistPrivacy } from '../../../shared/models'
29 22
30const expect = chai.expect 23const expect = chai.expect
31 24
32async function countFiles (internalServerNumber: number, directory: string) { 25async function countFiles (server: PeerTubeServer, directory: string) {
33 const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) 26 const files = await readdir(server.servers.buildDirectory(directory))
34 27
35 return files.length 28 return files.length
36} 29}
37 30
38async function assertNotExists (internalServerNumber: number, directory: string, substring: string) { 31async function assertNotExists (server: PeerTubeServer, directory: string, substring: string) {
39 const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) 32 const files = await readdir(server.servers.buildDirectory(directory))
40 33
41 for (const f of files) { 34 for (const f of files) {
42 expect(f).to.not.contain(substring) 35 expect(f).to.not.contain(substring)
43 } 36 }
44} 37}
45 38
46async function assertCountAreOkay (servers: ServerInfo[]) { 39async function assertCountAreOkay (servers: PeerTubeServer[]) {
47 for (const server of servers) { 40 for (const server of servers) {
48 const videosCount = await countFiles(server.internalServerNumber, 'videos') 41 const videosCount = await countFiles(server, 'videos')
49 expect(videosCount).to.equal(8) 42 expect(videosCount).to.equal(8)
50 43
51 const torrentsCount = await countFiles(server.internalServerNumber, 'torrents') 44 const torrentsCount = await countFiles(server, 'torrents')
52 expect(torrentsCount).to.equal(16) 45 expect(torrentsCount).to.equal(16)
53 46
54 const previewsCount = await countFiles(server.internalServerNumber, 'previews') 47 const previewsCount = await countFiles(server, 'previews')
55 expect(previewsCount).to.equal(2) 48 expect(previewsCount).to.equal(2)
56 49
57 const thumbnailsCount = await countFiles(server.internalServerNumber, 'thumbnails') 50 const thumbnailsCount = await countFiles(server, 'thumbnails')
58 expect(thumbnailsCount).to.equal(6) 51 expect(thumbnailsCount).to.equal(6)
59 52
60 const avatarsCount = await countFiles(server.internalServerNumber, 'avatars') 53 const avatarsCount = await countFiles(server, 'avatars')
61 expect(avatarsCount).to.equal(2) 54 expect(avatarsCount).to.equal(2)
62 } 55 }
63} 56}
64 57
65describe('Test prune storage scripts', function () { 58describe('Test prune storage scripts', function () {
66 let servers: ServerInfo[] 59 let servers: PeerTubeServer[]
67 const badNames: { [directory: string]: string[] } = {} 60 const badNames: { [directory: string]: string[] } = {}
68 61
69 before(async function () { 62 before(async function () {
70 this.timeout(120000) 63 this.timeout(120000)
71 64
72 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: true } }) 65 servers = await createMultipleServers(2, { transcoding: { enabled: true } })
73 await setAccessTokensToServers(servers) 66 await setAccessTokensToServers(servers)
74 await setDefaultVideoChannel(servers) 67 await setDefaultVideoChannel(servers)
75 68
76 for (const server of servers) { 69 for (const server of servers) {
77 await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) 70 await server.videos.upload({ attributes: { name: 'video 1' } })
78 await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) 71 await server.videos.upload({ attributes: { name: 'video 2' } })
79 72
80 await updateMyAvatar({ url: server.url, accessToken: server.accessToken, fixture: 'avatar.png' }) 73 await server.users.updateMyAvatar({ fixture: 'avatar.png' })
81 74
82 await createVideoPlaylist({ 75 await server.playlists.create({
83 url: server.url, 76 attributes: {
84 token: server.accessToken,
85 playlistAttrs: {
86 displayName: 'playlist', 77 displayName: 'playlist',
87 privacy: VideoPlaylistPrivacy.PUBLIC, 78 privacy: VideoPlaylistPrivacy.PUBLIC,
88 videoChannelId: server.videoChannel.id, 79 videoChannelId: server.store.channel.id,
89 thumbnailfile: 'thumbnail.jpg' 80 thumbnailfile: 'thumbnail.jpg'
90 } 81 }
91 }) 82 })
@@ -95,29 +86,27 @@ describe('Test prune storage scripts', function () {
95 86
96 // Lazy load the remote avatar 87 // Lazy load the remote avatar
97 { 88 {
98 const res = await getAccount(servers[0].url, 'root@localhost:' + servers[1].port) 89 const account = await servers[0].accounts.get({ accountName: 'root@localhost:' + servers[1].port })
99 const account: Account = res.body
100 await makeGetRequest({ 90 await makeGetRequest({
101 url: servers[0].url, 91 url: servers[0].url,
102 path: account.avatar.path, 92 path: account.avatar.path,
103 statusCodeExpected: HttpStatusCode.OK_200 93 expectedStatus: HttpStatusCode.OK_200
104 }) 94 })
105 } 95 }
106 96
107 { 97 {
108 const res = await getAccount(servers[1].url, 'root@localhost:' + servers[0].port) 98 const account = await servers[1].accounts.get({ accountName: 'root@localhost:' + servers[0].port })
109 const account: Account = res.body
110 await makeGetRequest({ 99 await makeGetRequest({
111 url: servers[1].url, 100 url: servers[1].url,
112 path: account.avatar.path, 101 path: account.avatar.path,
113 statusCodeExpected: HttpStatusCode.OK_200 102 expectedStatus: HttpStatusCode.OK_200
114 }) 103 })
115 } 104 }
116 105
117 await wait(1000) 106 await wait(1000)
118 107
119 await waitJobs(servers) 108 await waitJobs(servers)
120 killallServers(servers) 109 await killallServers(servers)
121 110
122 await wait(1000) 111 await wait(1000)
123 }) 112 })
@@ -129,7 +118,7 @@ describe('Test prune storage scripts', function () {
129 it('Should create some dirty files', async function () { 118 it('Should create some dirty files', async function () {
130 for (let i = 0; i < 2; i++) { 119 for (let i = 0; i < 2; i++) {
131 { 120 {
132 const base = buildServerDirectory(servers[0], 'videos') 121 const base = servers[0].servers.buildDirectory('videos')
133 122
134 const n1 = buildUUID() + '.mp4' 123 const n1 = buildUUID() + '.mp4'
135 const n2 = buildUUID() + '.webm' 124 const n2 = buildUUID() + '.webm'
@@ -141,7 +130,7 @@ describe('Test prune storage scripts', function () {
141 } 130 }
142 131
143 { 132 {
144 const base = buildServerDirectory(servers[0], 'torrents') 133 const base = servers[0].servers.buildDirectory('torrents')
145 134
146 const n1 = buildUUID() + '-240.torrent' 135 const n1 = buildUUID() + '-240.torrent'
147 const n2 = buildUUID() + '-480.torrent' 136 const n2 = buildUUID() + '-480.torrent'
@@ -153,7 +142,7 @@ describe('Test prune storage scripts', function () {
153 } 142 }
154 143
155 { 144 {
156 const base = buildServerDirectory(servers[0], 'thumbnails') 145 const base = servers[0].servers.buildDirectory('thumbnails')
157 146
158 const n1 = buildUUID() + '.jpg' 147 const n1 = buildUUID() + '.jpg'
159 const n2 = buildUUID() + '.jpg' 148 const n2 = buildUUID() + '.jpg'
@@ -165,7 +154,7 @@ describe('Test prune storage scripts', function () {
165 } 154 }
166 155
167 { 156 {
168 const base = buildServerDirectory(servers[0], 'previews') 157 const base = servers[0].servers.buildDirectory('previews')
169 158
170 const n1 = buildUUID() + '.jpg' 159 const n1 = buildUUID() + '.jpg'
171 const n2 = buildUUID() + '.jpg' 160 const n2 = buildUUID() + '.jpg'
@@ -177,7 +166,7 @@ describe('Test prune storage scripts', function () {
177 } 166 }
178 167
179 { 168 {
180 const base = buildServerDirectory(servers[0], 'avatars') 169 const base = servers[0].servers.buildDirectory('avatars')
181 170
182 const n1 = buildUUID() + '.png' 171 const n1 = buildUUID() + '.png'
183 const n2 = buildUUID() + '.jpg' 172 const n2 = buildUUID() + '.jpg'
@@ -193,8 +182,8 @@ describe('Test prune storage scripts', function () {
193 it('Should run prune storage', async function () { 182 it('Should run prune storage', async function () {
194 this.timeout(30000) 183 this.timeout(30000)
195 184
196 const env = getEnvCli(servers[0]) 185 const env = servers[0].cli.getEnv()
197 await execCLI(`echo y | ${env} npm run prune-storage`) 186 await CLICommand.exec(`echo y | ${env} npm run prune-storage`)
198 }) 187 })
199 188
200 it('Should have removed files', async function () { 189 it('Should have removed files', async function () {
@@ -202,7 +191,7 @@ describe('Test prune storage scripts', function () {
202 191
203 for (const directory of Object.keys(badNames)) { 192 for (const directory of Object.keys(badNames)) {
204 for (const name of badNames[directory]) { 193 for (const name of badNames[directory]) {
205 await assertNotExists(servers[0].internalServerNumber, directory, name) 194 await assertNotExists(servers[0], directory, name)
206 } 195 }
207 } 196 }
208 }) 197 })