aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/server-commands/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-17 11:58:15 +0100
committerChocobozzz <me@florianbigard.com>2021-12-17 12:24:03 +0100
commitc55e3d7227fe1453869e309025996b9d75256d5d (patch)
tree08e9b0ca210d75c82c8606fef0852eca020e8e0e /shared/server-commands/server
parentbf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (diff)
downloadPeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.tar.gz
PeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.tar.zst
PeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.zip
Move test functions outside extra-utils
Diffstat (limited to 'shared/server-commands/server')
-rw-r--r--shared/server-commands/server/config-command.ts5
-rw-r--r--shared/server-commands/server/directories.ts34
-rw-r--r--shared/server-commands/server/index.ts3
-rw-r--r--shared/server-commands/server/jobs-command.ts3
-rw-r--r--shared/server-commands/server/jobs.ts2
-rw-r--r--shared/server-commands/server/plugins.ts18
-rw-r--r--shared/server-commands/server/server.ts8
-rw-r--r--shared/server-commands/server/servers-command.ts4
-rw-r--r--shared/server-commands/server/servers.ts2
-rw-r--r--shared/server-commands/server/tracker.ts27
10 files changed, 11 insertions, 95 deletions
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 @@
1import { merge } from 'lodash' 1import { merge } from 'lodash'
2import { About, CustomConfig, HttpStatusCode, ServerConfig } from '@shared/models'
2import { DeepPartial } from '@shared/typescript-utils' 3import { DeepPartial } from '@shared/typescript-utils'
3import { About, HttpStatusCode, ServerConfig } from '@shared/models' 4import { AbstractCommand, OverrideCommandOptions } from '../shared/abstract-command'
4import { CustomConfig } from '../../models/server/custom-config.model'
5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6 5
7export class ConfigCommand extends AbstractCommand { 6export class ConfigCommand extends AbstractCommand {
8 7
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 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path'
6import { root } from '@shared/core-utils'
7import { PeerTubeServer } from './server'
8
9async function checkTmpIsEmpty (server: PeerTubeServer) {
10 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])
11
12 if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) {
13 await checkDirectoryIsEmpty(server, 'tmp/hls')
14 }
15}
16
17async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) {
18 const testDirectory = 'test' + server.internalServerNumber
19
20 const directoryPath = join(root(), testDirectory, directory)
21
22 const directoryExists = await pathExists(directoryPath)
23 expect(directoryExists).to.be.true
24
25 const files = await readdir(directoryPath)
26 const filtered = files.filter(f => exceptions.includes(f) === false)
27
28 expect(filtered).to.have.lengthOf(0)
29}
30
31export {
32 checkTmpIsEmpty,
33 checkDirectoryIsEmpty
34}
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 @@
1export * from './config-command' 1export * from './config-command'
2export * from './contact-form-command' 2export * from './contact-form-command'
3export * from './debug-command' 3export * from './debug-command'
4export * from './directories'
5export * from './follows-command' 4export * from './follows-command'
6export * from './follows' 5export * from './follows'
7export * from './jobs' 6export * from './jobs'
8export * from './jobs-command' 7export * from './jobs-command'
9export * from './object-storage-command' 8export * from './object-storage-command'
10export * from './plugins-command' 9export * from './plugins-command'
11export * from './plugins'
12export * from './redundancy-command' 10export * from './redundancy-command'
13export * from './server' 11export * from './server'
14export * from './servers-command' 12export * from './servers-command'
15export * from './servers' 13export * from './servers'
16export * from './stats-command' 14export * from './stats-command'
17export * 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 @@
1import { pick } from '@shared/core-utils' 1import { pick } from '@shared/core-utils'
2import { HttpStatusCode } from '@shared/models' 2import { HttpStatusCode, Job, JobState, JobType, ResultList } from '@shared/models'
3import { Job, JobState, JobType, ResultList } from '../../models'
4import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 4
6export class JobsCommand extends AbstractCommand { 5export 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 @@
1 1
2import { expect } from 'chai' 2import { expect } from 'chai'
3import { wait } from '@shared/core-utils'
3import { JobState, JobType } from '../../models' 4import { JobState, JobType } from '../../models'
4import { wait } from '../miscs'
5import { PeerTubeServer } from './server' 5import { PeerTubeServer } from './server'
6 6
7async function waitJobs (serversArg: PeerTubeServer[] | PeerTubeServer, skipDelayed = false) { 7async 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 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { PeerTubeServer } from './server'
5
6async function testHelloWorldRegisteredSettings (server: PeerTubeServer) {
7 const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' })
8
9 const registeredSettings = body.registeredSettings
10 expect(registeredSettings).to.have.length.at.least(1)
11
12 const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name')
13 expect(adminNameSettings).to.not.be.undefined
14}
15
16export {
17 testHelloWorldRegisteredSettings
18}
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 @@
1import { ChildProcess, fork } from 'child_process' 1import { ChildProcess, fork } from 'child_process'
2import { copy } from 'fs-extra' 2import { copy } from 'fs-extra'
3import { join } from 'path' 3import { join } from 'path'
4import { root, randomInt } from '@shared/core-utils' 4import { parallelTests, randomInt, root } from '@shared/core-utils'
5import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '../../models/videos' 5import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '@shared/models'
6import { BulkCommand } from '../bulk' 6import { BulkCommand } from '../bulk'
7import { CLICommand } from '../cli' 7import { CLICommand } from '../cli'
8import { CustomPagesCommand } from '../custom-pages' 8import { CustomPagesCommand } from '../custom-pages'
9import { FeedCommand } from '../feeds' 9import { FeedCommand } from '../feeds'
10import { LogsCommand } from '../logs' 10import { LogsCommand } from '../logs'
11import { parallelTests, SQLCommand } from '../miscs' 11import { SQLCommand } from '../miscs'
12import { AbusesCommand } from '../moderation' 12import { AbusesCommand } from '../moderation'
13import { OverviewsCommand } from '../overviews' 13import { OverviewsCommand } from '../overviews'
14import { SearchCommand } from '../search' 14import { SearchCommand } from '../search'
@@ -33,11 +33,11 @@ import { ContactFormCommand } from './contact-form-command'
33import { DebugCommand } from './debug-command' 33import { DebugCommand } from './debug-command'
34import { FollowsCommand } from './follows-command' 34import { FollowsCommand } from './follows-command'
35import { JobsCommand } from './jobs-command' 35import { JobsCommand } from './jobs-command'
36import { ObjectStorageCommand } from './object-storage-command'
36import { PluginsCommand } from './plugins-command' 37import { PluginsCommand } from './plugins-command'
37import { RedundancyCommand } from './redundancy-command' 38import { RedundancyCommand } from './redundancy-command'
38import { ServersCommand } from './servers-command' 39import { ServersCommand } from './servers-command'
39import { StatsCommand } from './stats-command' 40import { StatsCommand } from './stats-command'
40import { ObjectStorageCommand } from './object-storage-command'
41 41
42export type RunServerOptions = { 42export type RunServerOptions = {
43 hideLogs?: boolean 43 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 @@
1import { exec } from 'child_process' 1import { exec } from 'child_process'
2import { copy, ensureDir, readFile, remove } from 'fs-extra' 2import { copy, ensureDir, readFile, remove } from 'fs-extra'
3import { basename, join } from 'path' 3import { basename, join } from 'path'
4import { root } from '@shared/core-utils' 4import { isGithubCI, root, wait } from '@shared/core-utils'
5import { getFileSize } from '@shared/extra-utils'
5import { HttpStatusCode } from '@shared/models' 6import { HttpStatusCode } from '@shared/models'
6import { getFileSize, isGithubCI, wait } from '../miscs'
7import { AbstractCommand, OverrideCommandOptions } from '../shared' 7import { AbstractCommand, OverrideCommandOptions } from '../shared'
8 8
9export class ServersCommand extends AbstractCommand { 9export 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 @@
1import { ensureDir } from 'fs-extra' 1import { ensureDir } from 'fs-extra'
2import { isGithubCI } from '../miscs' 2import { isGithubCI } from '@shared/core-utils'
3import { PeerTubeServer, RunServerOptions } from './server' 3import { PeerTubeServer, RunServerOptions } from './server'
4 4
5async function createSingleServer (serverNumber: number, configOverride?: Object, options: RunServerOptions = {}) { 5async 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 @@
1import { expect } from 'chai'
2import { sha1 } from '@shared/core-utils/crypto'
3import { makeGetRequest } from '../requests'
4
5async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) {
6 const path = '/tracker/announce'
7
8 const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`)
9
10 // From bittorrent-tracker
11 const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) {
12 return '%' + char.charCodeAt(0).toString(16).toUpperCase()
13 })
14
15 const res = await makeGetRequest({
16 url: serverUrl,
17 path,
18 rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`,
19 expectedStatus: 200
20 })
21
22 expect(res.text).to.not.contain('failure')
23}
24
25export {
26 hlsInfohashExist
27}