proxy-backend: update tests to use proxy.endpoints
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/config-loader": "workspace:^",
|
||||
"@types/http-proxy-middleware": "^0.19.3",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"@types/uuid": "^8.0.0",
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
|
||||
import { getVoidLogger, SingleHostDiscovery } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
ConfigSources,
|
||||
MutableConfigSource,
|
||||
StaticConfigSource,
|
||||
} from '@backstage/config-loader';
|
||||
import express from 'express';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
@@ -56,34 +60,36 @@ describe('createRouter reloadable configuration', () => {
|
||||
const logger = getVoidLogger();
|
||||
|
||||
// Grab the subscriber function and use mutable config data to mock a config file change
|
||||
let subscriber: () => void;
|
||||
const mutableConfigData: any = {
|
||||
backend: {
|
||||
baseUrl: 'http://localhost:7007',
|
||||
listen: {
|
||||
port: 7007,
|
||||
},
|
||||
},
|
||||
proxy: {
|
||||
'/test': {
|
||||
target: 'https://non-existing-example.com',
|
||||
pathRewrite: {
|
||||
'.*': '/',
|
||||
const mutableConfigSource = MutableConfigSource.create({ data: {} });
|
||||
const config = await ConfigSources.toConfig(
|
||||
ConfigSources.merge([
|
||||
StaticConfigSource.create({
|
||||
data: {
|
||||
backend: {
|
||||
baseUrl: 'http://localhost:7007',
|
||||
listen: {
|
||||
port: 7007,
|
||||
},
|
||||
},
|
||||
proxy: {
|
||||
endpoints: {
|
||||
'/test': {
|
||||
target: 'https://non-existing-example.com',
|
||||
pathRewrite: {
|
||||
'.*': '/',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}),
|
||||
mutableConfigSource,
|
||||
]),
|
||||
);
|
||||
|
||||
const mockConfig = Object.assign(new ConfigReader(mutableConfigData), {
|
||||
subscribe: (s: () => void) => {
|
||||
subscriber = s;
|
||||
return { unsubscribe: () => {} };
|
||||
},
|
||||
});
|
||||
|
||||
const discovery = SingleHostDiscovery.fromConfig(mockConfig);
|
||||
const discovery = SingleHostDiscovery.fromConfig(config);
|
||||
const router = await createRouter({
|
||||
config: mockConfig,
|
||||
config,
|
||||
logger,
|
||||
discovery,
|
||||
});
|
||||
@@ -100,13 +106,18 @@ describe('createRouter reloadable configuration', () => {
|
||||
|
||||
expect(response1.status).toEqual(200);
|
||||
|
||||
mutableConfigData.proxy['/test2'] = {
|
||||
target: 'https://non-existing-example.com',
|
||||
pathRewrite: {
|
||||
'.*': '/',
|
||||
mutableConfigSource.setData({
|
||||
proxy: {
|
||||
endpoints: {
|
||||
'/test2': {
|
||||
target: 'https://non-existing-example.com',
|
||||
pathRewrite: {
|
||||
'.*': '/',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
subscriber!();
|
||||
});
|
||||
|
||||
const response2 = await agent.get('/test2');
|
||||
|
||||
|
||||
@@ -45,10 +45,12 @@ describe('createRouter', () => {
|
||||
},
|
||||
},
|
||||
proxy: {
|
||||
'/test': {
|
||||
target: 'https://example.com',
|
||||
headers: {
|
||||
Authorization: 'Bearer supersecret',
|
||||
endpoints: {
|
||||
'/test': {
|
||||
target: 'https://example.com',
|
||||
headers: {
|
||||
Authorization: 'Bearer supersecret',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -112,9 +114,11 @@ describe('createRouter', () => {
|
||||
},
|
||||
// no target would cause the buildMiddleware to fail
|
||||
proxy: {
|
||||
'/test': {
|
||||
headers: {
|
||||
Authorization: 'Bearer supersecret',
|
||||
endpoints: {
|
||||
'/test': {
|
||||
headers: {
|
||||
Authorization: 'Bearer supersecret',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -141,9 +145,11 @@ describe('createRouter', () => {
|
||||
},
|
||||
// no target would cause the buildMiddleware to fail
|
||||
proxy: {
|
||||
'/test': {
|
||||
headers: {
|
||||
Authorization: 'Bearer supersecret',
|
||||
endpoints: {
|
||||
'/test': {
|
||||
headers: {
|
||||
Authorization: 'Bearer supersecret',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -8055,6 +8055,7 @@ __metadata:
|
||||
"@backstage/backend-plugin-api": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/config": "workspace:^"
|
||||
"@backstage/config-loader": "workspace:^"
|
||||
"@types/express": ^4.17.6
|
||||
"@types/http-proxy-middleware": ^0.19.3
|
||||
"@types/supertest": ^2.0.8
|
||||
|
||||
Reference in New Issue
Block a user