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/server/config-command.ts | 5 ++-- shared/server-commands/server/directories.ts | 34 ------------------------ shared/server-commands/server/index.ts | 3 --- shared/server-commands/server/jobs-command.ts | 3 +-- shared/server-commands/server/jobs.ts | 2 +- shared/server-commands/server/plugins.ts | 18 ------------- shared/server-commands/server/server.ts | 8 +++--- shared/server-commands/server/servers-command.ts | 4 +-- shared/server-commands/server/servers.ts | 2 +- shared/server-commands/server/tracker.ts | 27 ------------------- 10 files changed, 11 insertions(+), 95 deletions(-) delete mode 100644 shared/server-commands/server/directories.ts delete mode 100644 shared/server-commands/server/plugins.ts delete mode 100644 shared/server-commands/server/tracker.ts (limited to 'shared/server-commands/server') diff --git a/shared/server-commands/server/config-command.ts b/shared/server-commands/server/config-command.ts index 89ae8eb4f..797231b1d 100644 --- a/shared/server-commands/server/config-command.ts +++ b/shared/server-commands/server/config-command.ts @@ -1,8 +1,7 @@ import { merge } from 'lodash' +import { About, CustomConfig, HttpStatusCode, ServerConfig } from '@shared/models' import { DeepPartial } from '@shared/typescript-utils' -import { About, HttpStatusCode, ServerConfig } from '@shared/models' -import { CustomConfig } from '../../models/server/custom-config.model' -import { AbstractCommand, OverrideCommandOptions } from '../shared' +import { AbstractCommand, OverrideCommandOptions } from '../shared/abstract-command' export class ConfigCommand extends AbstractCommand { diff --git a/shared/server-commands/server/directories.ts b/shared/server-commands/server/directories.ts deleted file mode 100644 index e6f72d6fc..000000000 --- a/shared/server-commands/server/directories.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { pathExists, readdir } from 'fs-extra' -import { join } from 'path' -import { root } from '@shared/core-utils' -import { PeerTubeServer } from './server' - -async function checkTmpIsEmpty (server: PeerTubeServer) { - await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) - - if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) { - await checkDirectoryIsEmpty(server, 'tmp/hls') - } -} - -async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) { - const testDirectory = 'test' + server.internalServerNumber - - const directoryPath = join(root(), testDirectory, directory) - - const directoryExists = await pathExists(directoryPath) - expect(directoryExists).to.be.true - - const files = await readdir(directoryPath) - const filtered = files.filter(f => exceptions.includes(f) === false) - - expect(filtered).to.have.lengthOf(0) -} - -export { - checkTmpIsEmpty, - checkDirectoryIsEmpty -} diff --git a/shared/server-commands/server/index.ts b/shared/server-commands/server/index.ts index 76a2099da..0a4b21fc4 100644 --- a/shared/server-commands/server/index.ts +++ b/shared/server-commands/server/index.ts @@ -1,17 +1,14 @@ export * from './config-command' export * from './contact-form-command' export * from './debug-command' -export * from './directories' export * from './follows-command' export * from './follows' export * from './jobs' export * from './jobs-command' export * from './object-storage-command' export * from './plugins-command' -export * from './plugins' export * from './redundancy-command' export * from './server' export * from './servers-command' export * from './servers' export * from './stats-command' -export * from './tracker' diff --git a/shared/server-commands/server/jobs-command.ts b/shared/server-commands/server/jobs-command.ts index 6636e7e4d..ac62157d1 100644 --- a/shared/server-commands/server/jobs-command.ts +++ b/shared/server-commands/server/jobs-command.ts @@ -1,6 +1,5 @@ import { pick } from '@shared/core-utils' -import { HttpStatusCode } from '@shared/models' -import { Job, JobState, JobType, ResultList } from '../../models' +import { HttpStatusCode, Job, JobState, JobType, ResultList } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class JobsCommand extends AbstractCommand { diff --git a/shared/server-commands/server/jobs.ts b/shared/server-commands/server/jobs.ts index 34fefd444..fc65a873b 100644 --- a/shared/server-commands/server/jobs.ts +++ b/shared/server-commands/server/jobs.ts @@ -1,7 +1,7 @@ import { expect } from 'chai' +import { wait } from '@shared/core-utils' import { JobState, JobType } from '../../models' -import { wait } from '../miscs' import { PeerTubeServer } from './server' async function waitJobs (serversArg: PeerTubeServer[] | PeerTubeServer, skipDelayed = false) { diff --git a/shared/server-commands/server/plugins.ts b/shared/server-commands/server/plugins.ts deleted file mode 100644 index c6316898d..000000000 --- a/shared/server-commands/server/plugins.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { PeerTubeServer } from './server' - -async function testHelloWorldRegisteredSettings (server: PeerTubeServer) { - const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) - - const registeredSettings = body.registeredSettings - expect(registeredSettings).to.have.length.at.least(1) - - const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name') - expect(adminNameSettings).to.not.be.undefined -} - -export { - testHelloWorldRegisteredSettings -} diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts index 339b9cabb..617069b11 100644 --- a/shared/server-commands/server/server.ts +++ b/shared/server-commands/server/server.ts @@ -1,14 +1,14 @@ import { ChildProcess, fork } from 'child_process' import { copy } from 'fs-extra' import { join } from 'path' -import { root, randomInt } from '@shared/core-utils' -import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '../../models/videos' +import { parallelTests, randomInt, root } from '@shared/core-utils' +import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '@shared/models' import { BulkCommand } from '../bulk' import { CLICommand } from '../cli' import { CustomPagesCommand } from '../custom-pages' import { FeedCommand } from '../feeds' import { LogsCommand } from '../logs' -import { parallelTests, SQLCommand } from '../miscs' +import { SQLCommand } from '../miscs' import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { SearchCommand } from '../search' @@ -33,11 +33,11 @@ import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' import { FollowsCommand } from './follows-command' import { JobsCommand } from './jobs-command' +import { ObjectStorageCommand } from './object-storage-command' import { PluginsCommand } from './plugins-command' import { RedundancyCommand } from './redundancy-command' import { ServersCommand } from './servers-command' import { StatsCommand } from './stats-command' -import { ObjectStorageCommand } from './object-storage-command' export type RunServerOptions = { hideLogs?: boolean diff --git a/shared/server-commands/server/servers-command.ts b/shared/server-commands/server/servers-command.ts index 47420c95f..c5d8d18dc 100644 --- a/shared/server-commands/server/servers-command.ts +++ b/shared/server-commands/server/servers-command.ts @@ -1,9 +1,9 @@ import { exec } from 'child_process' import { copy, ensureDir, readFile, remove } from 'fs-extra' import { basename, join } from 'path' -import { root } from '@shared/core-utils' +import { isGithubCI, root, wait } from '@shared/core-utils' +import { getFileSize } from '@shared/extra-utils' import { HttpStatusCode } from '@shared/models' -import { getFileSize, isGithubCI, wait } from '../miscs' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class ServersCommand extends AbstractCommand { diff --git a/shared/server-commands/server/servers.ts b/shared/server-commands/server/servers.ts index 21ab9405b..0faee3a8d 100644 --- a/shared/server-commands/server/servers.ts +++ b/shared/server-commands/server/servers.ts @@ -1,5 +1,5 @@ import { ensureDir } from 'fs-extra' -import { isGithubCI } from '../miscs' +import { isGithubCI } from '@shared/core-utils' import { PeerTubeServer, RunServerOptions } from './server' async function createSingleServer (serverNumber: number, configOverride?: Object, options: RunServerOptions = {}) { diff --git a/shared/server-commands/server/tracker.ts b/shared/server-commands/server/tracker.ts deleted file mode 100644 index ed43a5924..000000000 --- a/shared/server-commands/server/tracker.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { expect } from 'chai' -import { sha1 } from '@shared/core-utils/crypto' -import { makeGetRequest } from '../requests' - -async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) { - const path = '/tracker/announce' - - const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`) - - // From bittorrent-tracker - const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) { - return '%' + char.charCodeAt(0).toString(16).toUpperCase() - }) - - const res = await makeGetRequest({ - url: serverUrl, - path, - rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`, - expectedStatus: 200 - }) - - expect(res.text).to.not.contain('failure') -} - -export { - hlsInfohashExist -} -- cgit v1.2.3