Skip to content

Commit

Permalink
test(apisix): e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Nov 10, 2024
1 parent aa415af commit 47d44c5
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
85 changes: 85 additions & 0 deletions libs/backend-apisix/e2e/misc.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as ADCSDK from '@api7/adc-sdk';

import { BackendAPISIX } from '../src';
import {
createEvent,
deleteEvent,
dumpConfiguration,
overrideEventResourceId,
syncEvents,
} from './support/utils';

describe('Miscellaneous', () => {
let backend: BackendAPISIX;

beforeAll(() => {
backend = new BackendAPISIX({
server: process.env.SERVER,
token: process.env.TOKEN,
});
});

describe('Sync resources with custom id', () => {
const routeName = 'Test Route';
const serviceName = 'Test Service';
const route = {
id: 'custom-route',
name: routeName,
uris: ['/test'],
};
const service = {
id: 'custom-service',
name: serviceName,
upstream: {
scheme: 'https',
nodes: [
{
host: 'httpbin.org',
port: 443,
weight: 100,
},
],
},
routes: [route],
} as ADCSDK.Service;

it('Create services', async () =>
syncEvents(backend, [
overrideEventResourceId(
createEvent(ADCSDK.ResourceType.SERVICE, serviceName, service),
'custom-service',
),
overrideEventResourceId(
createEvent(ADCSDK.ResourceType.ROUTE, routeName, route, serviceName),
'custom-route',
'custom-service',
),
]));

it('Dump', async () => {
const result = (await dumpConfiguration(backend)) as ADCSDK.Configuration;
expect(result.services).toHaveLength(1);
expect(result.services[0]).toMatchObject(service);
expect(result.services[0]).toMatchObject(service);
expect(result.services[0].routes[0]).toMatchObject(route);
});

it('Delete service', async () =>
syncEvents(backend, [
overrideEventResourceId(
deleteEvent(ADCSDK.ResourceType.ROUTE, routeName, serviceName),
'custom-route',
'custom-service',
),
overrideEventResourceId(
deleteEvent(ADCSDK.ResourceType.SERVICE, serviceName),
'custom-service',
),
]));

it('Dump again', async () => {
const result = (await dumpConfiguration(backend)) as ADCSDK.Configuration;
expect(result.services).toHaveLength(0);
});
});
});
10 changes: 10 additions & 0 deletions libs/backend-apisix/e2e/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ export const deleteEvent = (
: undefined,
});

export const overrideEventResourceId = (
event: ADCSDK.Event,
resourceId: string,
parentId?: string,
) => {
event.resourceId = resourceId;
if (parentId) event.parentId = parentId;
return event;
};

type cond = boolean | (() => boolean);

export const conditionalDescribe = (cond: cond) =>
Expand Down

0 comments on commit 47d44c5

Please sign in to comment.