Skip to content

Commit

Permalink
test(api7): e2e custom id
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Nov 10, 2024
1 parent cf85b2e commit 30d497b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
63 changes: 63 additions & 0 deletions libs/backend-api7/e2e/misc.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createEvent,
deleteEvent,
dumpConfiguration,
overrideEventResourceId,
syncEvents,
} from './support/utils';

Expand Down Expand Up @@ -68,4 +69,66 @@ describe('Miscellaneous', () => {
expect(result.services).toHaveLength(0);
});
});

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',
),
]));

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',
),
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-api7/e2e/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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 30d497b

Please sign in to comment.