mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Create single function for port generation
This reduces the chances of several integration tests re-using the same port.
This commit is contained in:
parent
d1eadd75e7
commit
fa8d406f34
@ -4,9 +4,10 @@ import fetch from 'cross-fetch';
|
|||||||
import type { Initializer } from '../../src/init/Initializer';
|
import type { Initializer } from '../../src/init/Initializer';
|
||||||
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
||||||
import { joinFilePath } from '../../src/util/PathUtil';
|
import { joinFilePath } from '../../src/util/PathUtil';
|
||||||
|
import { getPort } from '../util/Util';
|
||||||
import { getTestFolder, instantiateFromConfig, removeFolder } from './Config';
|
import { getTestFolder, instantiateFromConfig, removeFolder } from './Config';
|
||||||
|
|
||||||
const port = 6006;
|
const port = getPort('DynamicPods');
|
||||||
const baseUrl = `http://localhost:${port}/`;
|
const baseUrl = `http://localhost:${port}/`;
|
||||||
const rootFilePath = getTestFolder('dynamicPods');
|
const rootFilePath = getTestFolder('dynamicPods');
|
||||||
const podConfigJson = joinFilePath(rootFilePath, 'config-pod.json');
|
const podConfigJson = joinFilePath(rootFilePath, 'config-pod.json');
|
||||||
|
@ -4,9 +4,10 @@ import type { BaseHttpServerFactory } from '../../src/server/BaseHttpServerFacto
|
|||||||
import type { HttpHandlerInput } from '../../src/server/HttpHandler';
|
import type { HttpHandlerInput } from '../../src/server/HttpHandler';
|
||||||
import { HttpHandler } from '../../src/server/HttpHandler';
|
import { HttpHandler } from '../../src/server/HttpHandler';
|
||||||
import { StaticAsyncHandler } from '../util/StaticAsyncHandler';
|
import { StaticAsyncHandler } from '../util/StaticAsyncHandler';
|
||||||
|
import { getPort } from '../util/Util';
|
||||||
import { instantiateFromConfig } from './Config';
|
import { instantiateFromConfig } from './Config';
|
||||||
|
|
||||||
const port = 6002;
|
const port = getPort('Middleware');
|
||||||
|
|
||||||
class SimpleHttpHandler extends HttpHandler {
|
class SimpleHttpHandler extends HttpHandler {
|
||||||
public async handle(input: HttpHandlerInput): Promise<void> {
|
public async handle(input: HttpHandlerInput): Promise<void> {
|
||||||
|
@ -2,9 +2,10 @@ import type { Server } from 'http';
|
|||||||
import fetch from 'cross-fetch';
|
import fetch from 'cross-fetch';
|
||||||
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
||||||
import { readableToString } from '../../src/util/StreamUtil';
|
import { readableToString } from '../../src/util/StreamUtil';
|
||||||
|
import { getPort } from '../util/Util';
|
||||||
import { instantiateFromConfig } from './Config';
|
import { instantiateFromConfig } from './Config';
|
||||||
|
|
||||||
const port = 6003;
|
const port = getPort('PodCreation');
|
||||||
const baseUrl = `http://localhost:${port}/`;
|
const baseUrl = `http://localhost:${port}/`;
|
||||||
|
|
||||||
describe('A server with a pod handler', (): void => {
|
describe('A server with a pod handler', (): void => {
|
||||||
|
@ -4,12 +4,14 @@ import type { RedisResourceLocker } from '../../src';
|
|||||||
import { joinFilePath } from '../../src';
|
import { joinFilePath } from '../../src';
|
||||||
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
||||||
import { describeIf } from '../util/TestHelpers';
|
import { describeIf } from '../util/TestHelpers';
|
||||||
|
import { getPort } from '../util/Util';
|
||||||
import { instantiateFromConfig } from './Config';
|
import { instantiateFromConfig } from './Config';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the general functionality of the server using a RedisResourceLocker
|
* Test the general functionality of the server using a RedisResourceLocker
|
||||||
*/
|
*/
|
||||||
describeIf('docker', 'A server with a RedisResourceLocker as ResourceLocker', (): void => {
|
describeIf('docker', 'A server with a RedisResourceLocker as ResourceLocker', (): void => {
|
||||||
const port = 6008;
|
const port = getPort('RedisResourceLocker');
|
||||||
const baseUrl = `http://localhost:${port}/`;
|
const baseUrl = `http://localhost:${port}/`;
|
||||||
let server: Server;
|
let server: Server;
|
||||||
let locker: RedisResourceLocker;
|
let locker: RedisResourceLocker;
|
||||||
|
@ -2,9 +2,10 @@ import type { Server } from 'http';
|
|||||||
import fetch from 'cross-fetch';
|
import fetch from 'cross-fetch';
|
||||||
import type { Initializer } from '../../src/init/Initializer';
|
import type { Initializer } from '../../src/init/Initializer';
|
||||||
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
||||||
|
import { getPort } from '../util/Util';
|
||||||
import { instantiateFromConfig } from './Config';
|
import { instantiateFromConfig } from './Config';
|
||||||
|
|
||||||
const port = 6004;
|
const port = getPort('ServerFetch');
|
||||||
const baseUrl = `http://localhost:${port}/`;
|
const baseUrl = `http://localhost:${port}/`;
|
||||||
|
|
||||||
// Some tests with real Requests/Responses until the mocking library has been removed from the tests
|
// Some tests with real Requests/Responses until the mocking library has been removed from the tests
|
||||||
|
@ -3,9 +3,10 @@ import fetch from 'cross-fetch';
|
|||||||
import type { Initializer } from '../../src/init/Initializer';
|
import type { Initializer } from '../../src/init/Initializer';
|
||||||
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
||||||
import type { ResourceStore } from '../../src/storage/ResourceStore';
|
import type { ResourceStore } from '../../src/storage/ResourceStore';
|
||||||
|
import { getPort } from '../util/Util';
|
||||||
import { getTestFolder, instantiateFromConfig, removeFolder } from './Config';
|
import { getTestFolder, instantiateFromConfig, removeFolder } from './Config';
|
||||||
|
|
||||||
const port = 6005;
|
const port = getPort('Subdomains');
|
||||||
const baseUrl = `http://localhost:${port}/`;
|
const baseUrl = `http://localhost:${port}/`;
|
||||||
|
|
||||||
const rootFilePath = getTestFolder('subdomains');
|
const rootFilePath = getTestFolder('subdomains');
|
||||||
|
@ -2,9 +2,10 @@ import type { Server } from 'http';
|
|||||||
import fetch from 'cross-fetch';
|
import fetch from 'cross-fetch';
|
||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
||||||
|
import { getPort } from '../util/Util';
|
||||||
import { instantiateFromConfig } from './Config';
|
import { instantiateFromConfig } from './Config';
|
||||||
|
|
||||||
const port = 6001;
|
const port = getPort('WebSocketsProtocol');
|
||||||
const serverUrl = `http://localhost:${port}/`;
|
const serverUrl = `http://localhost:${port}/`;
|
||||||
const headers = { forwarded: 'host=example.pod;proto=https' };
|
const headers = { forwarded: 'host=example.pod;proto=https' };
|
||||||
|
|
||||||
|
@ -9,6 +9,26 @@ import type { HttpHandler } from '../../src/server/HttpHandler';
|
|||||||
import type { HttpRequest } from '../../src/server/HttpRequest';
|
import type { HttpRequest } from '../../src/server/HttpRequest';
|
||||||
import type { SystemError } from '../../src/util/errors/SystemError';
|
import type { SystemError } from '../../src/util/errors/SystemError';
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
|
const portNames = [
|
||||||
|
'DynamicPods',
|
||||||
|
'Middleware',
|
||||||
|
'PodCreation',
|
||||||
|
'RedisResourceLocker',
|
||||||
|
'ServerFetch',
|
||||||
|
'Subdomains',
|
||||||
|
'WebSocketsProtocol',
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export function getPort(name: typeof portNames[number]): number {
|
||||||
|
const idx = portNames.indexOf(name);
|
||||||
|
// Just in case something doesn't listen to the typings
|
||||||
|
if (idx < 0) {
|
||||||
|
throw new Error(`Unknown port name ${name}`);
|
||||||
|
}
|
||||||
|
return 6000 + idx;
|
||||||
|
}
|
||||||
|
|
||||||
export async function performRequest(
|
export async function performRequest(
|
||||||
handler: HttpHandler,
|
handler: HttpHandler,
|
||||||
requestUrl: URL,
|
requestUrl: URL,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user