From c55e3d7227fe1453869e309025996b9d75256d5d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 17 Dec 2021 11:58:15 +0100 Subject: Move test functions outside extra-utils --- shared/server-commands/videos/blacklist-command.ts | 3 +- shared/server-commands/videos/captions-command.ts | 2 +- shared/server-commands/videos/captions.ts | 21 ----- shared/server-commands/videos/channels-command.ts | 12 ++- shared/server-commands/videos/index.ts | 4 - shared/server-commands/videos/live-command.ts | 2 +- shared/server-commands/videos/live.ts | 41 +------- shared/server-commands/videos/playlists.ts | 25 ----- .../server-commands/videos/streaming-playlists.ts | 77 --------------- shared/server-commands/videos/videos-command.ts | 4 +- shared/server-commands/videos/videos.ts | 104 --------------------- 11 files changed, 15 insertions(+), 280 deletions(-) delete mode 100644 shared/server-commands/videos/captions.ts delete mode 100644 shared/server-commands/videos/playlists.ts delete mode 100644 shared/server-commands/videos/streaming-playlists.ts delete mode 100644 shared/server-commands/videos/videos.ts (limited to 'shared/server-commands/videos') diff --git a/shared/server-commands/videos/blacklist-command.ts b/shared/server-commands/videos/blacklist-command.ts index 3a2ef89ba..47e23ebc8 100644 --- a/shared/server-commands/videos/blacklist-command.ts +++ b/shared/server-commands/videos/blacklist-command.ts @@ -1,6 +1,5 @@ -import { HttpStatusCode, ResultList } from '@shared/models' -import { VideoBlacklist, VideoBlacklistType } from '../../models/videos' +import { HttpStatusCode, ResultList, VideoBlacklist, VideoBlacklistType } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class BlacklistCommand extends AbstractCommand { diff --git a/shared/server-commands/videos/captions-command.ts b/shared/server-commands/videos/captions-command.ts index a65ea99e3..62bf9c5e6 100644 --- a/shared/server-commands/videos/captions-command.ts +++ b/shared/server-commands/videos/captions-command.ts @@ -1,5 +1,5 @@ +import { buildAbsoluteFixturePath } from '@shared/core-utils' import { HttpStatusCode, ResultList, VideoCaption } from '@shared/models' -import { buildAbsoluteFixturePath } from '../miscs' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class CaptionsCommand extends AbstractCommand { diff --git a/shared/server-commands/videos/captions.ts b/shared/server-commands/videos/captions.ts deleted file mode 100644 index 35e722408..000000000 --- a/shared/server-commands/videos/captions.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { expect } from 'chai' -import request from 'supertest' -import { HttpStatusCode } from '@shared/models' - -async function testCaptionFile (url: string, captionPath: string, toTest: RegExp | string) { - const res = await request(url) - .get(captionPath) - .expect(HttpStatusCode.OK_200) - - if (toTest instanceof RegExp) { - expect(res.text).to.match(toTest) - } else { - expect(res.text).to.contain(toTest) - } -} - -// --------------------------------------------------------------------------- - -export { - testCaptionFile -} diff --git a/shared/server-commands/videos/channels-command.ts b/shared/server-commands/videos/channels-command.ts index e406e570b..8ab124658 100644 --- a/shared/server-commands/videos/channels-command.ts +++ b/shared/server-commands/videos/channels-command.ts @@ -1,7 +1,13 @@ import { pick } from '@shared/core-utils' -import { ActorFollow, HttpStatusCode, ResultList, VideoChannel, VideoChannelCreateResult } from '@shared/models' -import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model' -import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model' +import { + ActorFollow, + HttpStatusCode, + ResultList, + VideoChannel, + VideoChannelCreate, + VideoChannelCreateResult, + VideoChannelUpdate +} from '@shared/models' import { unwrapBody } from '../requests' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/server-commands/videos/index.ts b/shared/server-commands/videos/index.ts index 26e663f46..68a188b21 100644 --- a/shared/server-commands/videos/index.ts +++ b/shared/server-commands/videos/index.ts @@ -1,6 +1,5 @@ export * from './blacklist-command' export * from './captions-command' -export * from './captions' export * from './change-ownership-command' export * from './channels' export * from './channels-command' @@ -10,10 +9,7 @@ export * from './imports-command' export * from './live-command' export * from './live' export * from './playlists-command' -export * from './playlists' export * from './services-command' export * from './streaming-playlists-command' -export * from './streaming-playlists' export * from './comments-command' export * from './videos-command' -export * from './videos' diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts index 74f5d3089..f7816eca0 100644 --- a/shared/server-commands/videos/live-command.ts +++ b/shared/server-commands/videos/live-command.ts @@ -3,8 +3,8 @@ import { readdir } from 'fs-extra' import { omit } from 'lodash' import { join } from 'path' +import { wait } from '@shared/core-utils' import { HttpStatusCode, LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoCreateResult, VideoDetails, VideoState } from '@shared/models' -import { wait } from '../miscs' import { unwrapBody } from '../requests' import { AbstractCommand, OverrideCommandOptions } from '../shared' import { sendRTMPStream, testFfmpegStreamError } from './live' diff --git a/shared/server-commands/videos/live.ts b/shared/server-commands/videos/live.ts index d3665bc90..7a7faa911 100644 --- a/shared/server-commands/videos/live.ts +++ b/shared/server-commands/videos/live.ts @@ -1,10 +1,5 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg' -import { pathExists, readdir } from 'fs-extra' -import { join } from 'path' -import { buildAbsoluteFixturePath, wait } from '../miscs' +import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' import { PeerTubeServer } from '../server/server' function sendRTMPStream (options: { @@ -95,43 +90,11 @@ async function waitUntilLiveSavedOnAllServers (servers: PeerTubeServer[], videoI } } -async function checkLiveCleanupAfterSave (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) { - const basePath = server.servers.buildDirectory('streaming-playlists') - const hlsPath = join(basePath, 'hls', videoUUID) - - if (resolutions.length === 0) { - const result = await pathExists(hlsPath) - expect(result).to.be.false - - return - } - - const files = await readdir(hlsPath) - - // fragmented file and playlist per resolution + master playlist + segments sha256 json file - expect(files).to.have.lengthOf(resolutions.length * 2 + 2) - - for (const resolution of resolutions) { - const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`)) - expect(fragmentedFile).to.exist - - const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`)) - expect(playlistFile).to.exist - } - - const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8')) - expect(masterPlaylistFile).to.exist - - const shaFile = files.find(f => f.endsWith('-segments-sha256.json')) - expect(shaFile).to.exist -} - export { sendRTMPStream, waitFfmpegUntilError, testFfmpegStreamError, stopFfmpeg, waitUntilLivePublishedOnAllServers, - waitUntilLiveSavedOnAllServers, - checkLiveCleanupAfterSave + waitUntilLiveSavedOnAllServers } diff --git a/shared/server-commands/videos/playlists.ts b/shared/server-commands/videos/playlists.ts deleted file mode 100644 index 3dde52bb9..000000000 --- a/shared/server-commands/videos/playlists.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { expect } from 'chai' -import { readdir } from 'fs-extra' -import { join } from 'path' -import { root } from '../miscs' - -async function checkPlaylistFilesWereRemoved ( - playlistUUID: string, - internalServerNumber: number, - directories = [ 'thumbnails' ] -) { - const testDirectory = 'test' + internalServerNumber - - for (const directory of directories) { - const directoryPath = join(root(), testDirectory, directory) - - const files = await readdir(directoryPath) - for (const file of files) { - expect(file).to.not.contain(playlistUUID) - } - } -} - -export { - checkPlaylistFilesWereRemoved -} diff --git a/shared/server-commands/videos/streaming-playlists.ts b/shared/server-commands/videos/streaming-playlists.ts deleted file mode 100644 index 0451c0efe..000000000 --- a/shared/server-commands/videos/streaming-playlists.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { expect } from 'chai' -import { basename } from 'path' -import { sha256 } from '@shared/core-utils/crypto' -import { removeFragmentedMP4Ext } from '@shared/core-utils' -import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' -import { PeerTubeServer } from '../server' - -async function checkSegmentHash (options: { - server: PeerTubeServer - baseUrlPlaylist: string - baseUrlSegment: string - resolution: number - hlsPlaylist: VideoStreamingPlaylist -}) { - const { server, baseUrlPlaylist, baseUrlSegment, resolution, hlsPlaylist } = options - const command = server.streamingPlaylists - - const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) - const videoName = basename(file.fileUrl) - - const playlist = await command.get({ url: `${baseUrlPlaylist}/${removeFragmentedMP4Ext(videoName)}.m3u8` }) - - const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) - - const length = parseInt(matches[1], 10) - const offset = parseInt(matches[2], 10) - const range = `${offset}-${offset + length - 1}` - - const segmentBody = await command.getSegment({ - url: `${baseUrlSegment}/${videoName}`, - expectedStatus: HttpStatusCode.PARTIAL_CONTENT_206, - range: `bytes=${range}` - }) - - const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) - expect(sha256(segmentBody)).to.equal(shaBody[videoName][range]) -} - -async function checkLiveSegmentHash (options: { - server: PeerTubeServer - baseUrlSegment: string - videoUUID: string - segmentName: string - hlsPlaylist: VideoStreamingPlaylist -}) { - const { server, baseUrlSegment, videoUUID, segmentName, hlsPlaylist } = options - const command = server.streamingPlaylists - - const segmentBody = await command.getSegment({ url: `${baseUrlSegment}/${videoUUID}/${segmentName}` }) - const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) - - expect(sha256(segmentBody)).to.equal(shaBody[segmentName]) -} - -async function checkResolutionsInMasterPlaylist (options: { - server: PeerTubeServer - playlistUrl: string - resolutions: number[] -}) { - const { server, playlistUrl, resolutions } = options - - const masterPlaylist = await server.streamingPlaylists.get({ url: playlistUrl }) - - for (const resolution of resolutions) { - const reg = new RegExp( - '#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',(FRAME-RATE=\\d+,)?CODECS="avc1.64001f,mp4a.40.2"' - ) - - expect(masterPlaylist).to.match(reg) - } -} - -export { - checkSegmentHash, - checkLiveSegmentHash, - checkResolutionsInMasterPlaylist -} diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts index 8ea828b40..ead57b9aa 100644 --- a/shared/server-commands/videos/videos-command.ts +++ b/shared/server-commands/videos/videos-command.ts @@ -5,8 +5,7 @@ import { createReadStream, stat } from 'fs-extra' import got, { Response as GotResponse } from 'got' import { omit } from 'lodash' import validator from 'validator' -import { buildUUID } from '@shared/core-utils/uuid' -import { pick } from '@shared/core-utils' +import { buildAbsoluteFixturePath, buildUUID, pick, wait } from '@shared/core-utils' import { HttpStatusCode, ResultList, @@ -20,7 +19,6 @@ import { VideosCommonQuery, VideoTranscodingCreate } from '@shared/models' -import { buildAbsoluteFixturePath, wait } from '../miscs' import { unwrapBody } from '../requests' import { waitJobs } from '../server' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/server-commands/videos/videos.ts b/shared/server-commands/videos/videos.ts deleted file mode 100644 index 2c3464aa8..000000000 --- a/shared/server-commands/videos/videos.ts +++ /dev/null @@ -1,104 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ - -import { expect } from 'chai' -import { pathExists, readdir } from 'fs-extra' -import { basename, join } from 'path' -import { HttpStatusCode, VideoCaption, VideoDetails } from '@shared/models' -import { waitJobs } from '../server' -import { PeerTubeServer } from '../server/server' -import { VideoEdit } from './videos-command' - -async function checkVideoFilesWereRemoved (options: { - server: PeerTubeServer - video: VideoDetails - captions?: VideoCaption[] - onlyVideoFiles?: boolean // default false -}) { - const { video, server, captions = [], onlyVideoFiles = false } = options - - const webtorrentFiles = video.files || [] - const hlsFiles = video.streamingPlaylists[0]?.files || [] - - const thumbnailName = basename(video.thumbnailPath) - const previewName = basename(video.previewPath) - - const torrentNames = webtorrentFiles.concat(hlsFiles).map(f => basename(f.torrentUrl)) - - const captionNames = captions.map(c => basename(c.captionPath)) - - const webtorrentFilenames = webtorrentFiles.map(f => basename(f.fileUrl)) - const hlsFilenames = hlsFiles.map(f => basename(f.fileUrl)) - - let directories: { [ directory: string ]: string[] } = { - videos: webtorrentFilenames, - redundancy: webtorrentFilenames, - [join('playlists', 'hls')]: hlsFilenames, - [join('redundancy', 'hls')]: hlsFilenames - } - - if (onlyVideoFiles !== true) { - directories = { - ...directories, - - thumbnails: [ thumbnailName ], - previews: [ previewName ], - torrents: torrentNames, - captions: captionNames - } - } - - for (const directory of Object.keys(directories)) { - const directoryPath = server.servers.buildDirectory(directory) - - const directoryExists = await pathExists(directoryPath) - if (directoryExists === false) continue - - const existingFiles = await readdir(directoryPath) - for (const existingFile of existingFiles) { - for (const shouldNotExist of directories[directory]) { - expect(existingFile, `File ${existingFile} should not exist in ${directoryPath}`).to.not.contain(shouldNotExist) - } - } - } -} - -async function saveVideoInServers (servers: PeerTubeServer[], uuid: string) { - for (const server of servers) { - server.store.videoDetails = await server.videos.get({ id: uuid }) - } -} - -function checkUploadVideoParam ( - server: PeerTubeServer, - token: string, - attributes: Partial, - expectedStatus = HttpStatusCode.OK_200, - mode: 'legacy' | 'resumable' = 'legacy' -) { - return mode === 'legacy' - ? server.videos.buildLegacyUpload({ token, attributes, expectedStatus }) - : server.videos.buildResumeUpload({ token, attributes, expectedStatus }) -} - -// serverNumber starts from 1 -async function uploadRandomVideoOnServers ( - servers: PeerTubeServer[], - serverNumber: number, - additionalParams?: VideoEdit & { prefixName?: string } -) { - const server = servers.find(s => s.serverNumber === serverNumber) - const res = await server.videos.randomUpload({ wait: false, additionalParams }) - - await waitJobs(servers) - - return res -} - -// --------------------------------------------------------------------------- - -export { - checkUploadVideoParam, - uploadRandomVideoOnServers, - checkVideoFilesWereRemoved, - saveVideoInServers -} -- cgit v1.2.3