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.ts223
1 files changed, 0 insertions, 223 deletions
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
deleted file mode 100644
index 72a4b1332..000000000
--- a/server/tests/cli/prune-storage.ts
+++ /dev/null
@@ -1,223 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { createFile, readdir } from 'fs-extra'
5import { join } from 'path'
6import { wait } from '@shared/core-utils'
7import { buildUUID } from '@shared/extra-utils'
8import { HttpStatusCode, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
9import {
10 cleanupTests,
11 CLICommand,
12 createMultipleServers,
13 doubleFollow,
14 killallServers,
15 makeGetRequest,
16 PeerTubeServer,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
19 waitJobs
20} from '@shared/server-commands'
21
22async function assertNotExists (server: PeerTubeServer, directory: string, substring: string) {
23 const files = await readdir(server.servers.buildDirectory(directory))
24
25 for (const f of files) {
26 expect(f).to.not.contain(substring)
27 }
28}
29
30async function assertCountAreOkay (servers: PeerTubeServer[]) {
31 for (const server of servers) {
32 const videosCount = await server.servers.countFiles('web-videos')
33 expect(videosCount).to.equal(9) // 2 videos with 4 resolutions + private directory
34
35 const privateVideosCount = await server.servers.countFiles('web-videos/private')
36 expect(privateVideosCount).to.equal(4)
37
38 const torrentsCount = await server.servers.countFiles('torrents')
39 expect(torrentsCount).to.equal(24)
40
41 const previewsCount = await server.servers.countFiles('previews')
42 expect(previewsCount).to.equal(3)
43
44 const thumbnailsCount = await server.servers.countFiles('thumbnails')
45 expect(thumbnailsCount).to.equal(5) // 3 local videos, 1 local playlist, 2 remotes videos (lazy downloaded) and 1 remote playlist
46
47 const avatarsCount = await server.servers.countFiles('avatars')
48 expect(avatarsCount).to.equal(4)
49
50 const hlsRootCount = await server.servers.countFiles(join('streaming-playlists', 'hls'))
51 expect(hlsRootCount).to.equal(3) // 2 videos + private directory
52
53 const hlsPrivateRootCount = await server.servers.countFiles(join('streaming-playlists', 'hls', 'private'))
54 expect(hlsPrivateRootCount).to.equal(1)
55 }
56}
57
58describe('Test prune storage scripts', function () {
59 let servers: PeerTubeServer[]
60 const badNames: { [directory: string]: string[] } = {}
61
62 before(async function () {
63 this.timeout(120000)
64
65 servers = await createMultipleServers(2, { transcoding: { enabled: true } })
66 await setAccessTokensToServers(servers)
67 await setDefaultVideoChannel(servers)
68
69 for (const server of servers) {
70 await server.videos.upload({ attributes: { name: 'video 1', privacy: VideoPrivacy.PUBLIC } })
71 await server.videos.upload({ attributes: { name: 'video 2', privacy: VideoPrivacy.PUBLIC } })
72
73 await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE } })
74
75 await server.users.updateMyAvatar({ fixture: 'avatar.png' })
76
77 await server.playlists.create({
78 attributes: {
79 displayName: 'playlist',
80 privacy: VideoPlaylistPrivacy.PUBLIC,
81 videoChannelId: server.store.channel.id,
82 thumbnailfile: 'custom-thumbnail.jpg'
83 }
84 })
85 }
86
87 await doubleFollow(servers[0], servers[1])
88
89 // Lazy load the remote avatars
90 {
91 const account = await servers[0].accounts.get({ accountName: 'root@' + servers[1].host })
92
93 for (const avatar of account.avatars) {
94 await makeGetRequest({
95 url: servers[0].url,
96 path: avatar.path,
97 expectedStatus: HttpStatusCode.OK_200
98 })
99 }
100 }
101
102 {
103 const account = await servers[1].accounts.get({ accountName: 'root@' + servers[0].host })
104 for (const avatar of account.avatars) {
105 await makeGetRequest({
106 url: servers[1].url,
107 path: avatar.path,
108 expectedStatus: HttpStatusCode.OK_200
109 })
110 }
111 }
112
113 await wait(1000)
114
115 await waitJobs(servers)
116 await killallServers(servers)
117
118 await wait(1000)
119 })
120
121 it('Should have the files on the disk', async function () {
122 await assertCountAreOkay(servers)
123 })
124
125 it('Should create some dirty files', async function () {
126 for (let i = 0; i < 2; i++) {
127 {
128 const basePublic = servers[0].servers.buildDirectory('web-videos')
129 const basePrivate = servers[0].servers.buildDirectory(join('web-videos', 'private'))
130
131 const n1 = buildUUID() + '.mp4'
132 const n2 = buildUUID() + '.webm'
133
134 await createFile(join(basePublic, n1))
135 await createFile(join(basePublic, n2))
136 await createFile(join(basePrivate, n1))
137 await createFile(join(basePrivate, n2))
138
139 badNames['web-videos'] = [ n1, n2 ]
140 }
141
142 {
143 const base = servers[0].servers.buildDirectory('torrents')
144
145 const n1 = buildUUID() + '-240.torrent'
146 const n2 = buildUUID() + '-480.torrent'
147
148 await createFile(join(base, n1))
149 await createFile(join(base, n2))
150
151 badNames['torrents'] = [ n1, n2 ]
152 }
153
154 {
155 const base = servers[0].servers.buildDirectory('thumbnails')
156
157 const n1 = buildUUID() + '.jpg'
158 const n2 = buildUUID() + '.jpg'
159
160 await createFile(join(base, n1))
161 await createFile(join(base, n2))
162
163 badNames['thumbnails'] = [ n1, n2 ]
164 }
165
166 {
167 const base = servers[0].servers.buildDirectory('previews')
168
169 const n1 = buildUUID() + '.jpg'
170 const n2 = buildUUID() + '.jpg'
171
172 await createFile(join(base, n1))
173 await createFile(join(base, n2))
174
175 badNames['previews'] = [ n1, n2 ]
176 }
177
178 {
179 const base = servers[0].servers.buildDirectory('avatars')
180
181 const n1 = buildUUID() + '.png'
182 const n2 = buildUUID() + '.jpg'
183
184 await createFile(join(base, n1))
185 await createFile(join(base, n2))
186
187 badNames['avatars'] = [ n1, n2 ]
188 }
189
190 {
191 const directory = join('streaming-playlists', 'hls')
192 const basePublic = servers[0].servers.buildDirectory(directory)
193 const basePrivate = servers[0].servers.buildDirectory(join(directory, 'private'))
194
195 const n1 = buildUUID()
196 await createFile(join(basePublic, n1))
197 await createFile(join(basePrivate, n1))
198 badNames[directory] = [ n1 ]
199 }
200 }
201 })
202
203 it('Should run prune storage', async function () {
204 this.timeout(30000)
205
206 const env = servers[0].cli.getEnv()
207 await CLICommand.exec(`echo y | ${env} npm run prune-storage`)
208 })
209
210 it('Should have removed files', async function () {
211 await assertCountAreOkay(servers)
212
213 for (const directory of Object.keys(badNames)) {
214 for (const name of badNames[directory]) {
215 await assertNotExists(servers[0], directory, name)
216 }
217 }
218 })
219
220 after(async function () {
221 await cleanupTests(servers)
222 })
223})