Passing post proxy unit tests, proxy now supports write operations

Signed-off-by: Ruben Vallejo <rvallejo@gmail.com>
This commit is contained in:
Ruben Vallejo
2023-01-31 17:29:32 -05:00
committed by Ruben Vallejo
parent eec110675b
commit 81c5dca2ff
2 changed files with 18 additions and 32 deletions
@@ -276,6 +276,21 @@ describe('KubernetesBuilder', () => {
const worker = setupServer();
setupRequestMockHandlers(worker);
beforeEach(() => {
worker.use(
rest.post('https://localhost:1234/api/v1/namespaces', (req, res, ctx) =>
req
.arrayBuffer()
.then(body =>
res(
ctx.set('content-type', `${req.headers.get('content-type')}`),
ctx.body(body),
),
),
),
);
});
it('returns the given request body', async () => {
const requestBody = {
kind: 'Namespace',
@@ -290,21 +305,7 @@ describe('KubernetesBuilder', () => {
.set(HEADER_KUBERNETES_CLUSTER, 'some-cluster')
.send(requestBody);
worker.use(
rest.post('https://localhost:1234/api/v1/namespaces', (req, res, ctx) =>
req
.arrayBuffer()
.then(body =>
res(
ctx.set('content-type', `${req.headers.get('content-type')}`),
ctx.body(body),
),
),
),
rest.all(proxyEndpointRequest.url, (req, _res, _ctx) =>
req.passthrough(),
),
);
worker.use(rest.all(proxyEndpointRequest.url, req => req.passthrough()));
const response = await proxyEndpointRequest;
@@ -325,21 +326,7 @@ metadata:
.set('content-type', 'application/yaml')
.send(requestBody);
worker.use(
rest.post('https://localhost:1234/api/v1/namespaces', (req, res, ctx) =>
req
.arrayBuffer()
.then(body =>
res(
ctx.set('content-type', `${req.headers.get('content-type')}`),
ctx.body(body),
),
),
),
rest.all(proxyEndpointRequest.url, (req, _res, _ctx) =>
req.passthrough(),
),
);
worker.use(rest.all(proxyEndpointRequest.url, req => req.passthrough()));
const response = await proxyEndpointRequest;
expect(response.text).toEqual(requestBody);
@@ -265,6 +265,7 @@ export class KubernetesBuilder {
): express.Router {
const logger = this.env.logger;
const router = Router();
router.use('/proxy', proxy.createRequestHandler());
router.use(express.json());
// @deprecated
@@ -297,8 +298,6 @@ export class KubernetesBuilder {
});
});
router.use('/proxy', proxy.createRequestHandler());
addResourceRoutesToRouter(router, catalogApi, objectsProvider);
return router;