From 1cca8f69ad5788cc52dfe1fe3c3202a9d22fd344 Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Thu, 17 Oct 2024 16:12:25 +0800 Subject: [PATCH] test: add timeout e2e --- .../e2e/resources/route.e2e-spec.ts | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 libs/backend-api7/e2e/resources/route.e2e-spec.ts diff --git a/libs/backend-api7/e2e/resources/route.e2e-spec.ts b/libs/backend-api7/e2e/resources/route.e2e-spec.ts new file mode 100644 index 0000000..7bf0479 --- /dev/null +++ b/libs/backend-api7/e2e/resources/route.e2e-spec.ts @@ -0,0 +1,75 @@ +import * as ADCSDK from '@api7/adc-sdk'; + +import { BackendAPI7 } from '../../src'; +import { + createEvent, + deleteEvent, + dumpConfiguration, + syncEvents, +} from '../support/utils'; + +describe('Route E2E', () => { + let backend: BackendAPI7; + + beforeAll(() => { + backend = new BackendAPI7({ + server: process.env.SERVER, + token: process.env.TOKEN, + tlsSkipVerify: true, + gatewayGroup: 'default', + }); + }); + + describe('Timeout', () => { + const serviceName = 'test'; + const service = { + name: serviceName, + upstream: { + scheme: 'https', + nodes: [ + { + host: 'httpbin.org', + port: 443, + weight: 100, + }, + ], + }, + path_prefix: '/test', + strip_path_prefix: true, + } as ADCSDK.Service; + const route1Name = 'route1'; + const route1 = { + name: route1Name, + uris: ['/route1'], + timeout: { + connect: 111, + send: 222, + read: 333, + }, + } as ADCSDK.Route; + + it('Create resources', async () => + syncEvents(backend, [ + createEvent(ADCSDK.ResourceType.SERVICE, serviceName, service), + createEvent(ADCSDK.ResourceType.ROUTE, route1Name, route1, serviceName), + ])); + + 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].routes).toHaveLength(1); + expect(result.services[0].routes[0]).toMatchObject(route1); + }); + + it('Delete', async () => + syncEvents(backend, [ + deleteEvent(ADCSDK.ResourceType.SERVICE, serviceName), + ])); + + it('Dump again (service should not exist)', async () => { + const result = (await dumpConfiguration(backend)) as ADCSDK.Configuration; + expect(result.services).toHaveLength(0); + }); + }); +});