From 52087e7cddf132188045660e6aa3d570920ad2e7 Mon Sep 17 00:00:00 2001 From: Zeping Bai Date: Thu, 22 Aug 2024 11:56:47 +0800 Subject: [PATCH] feat(core): linter looser description length (#175) --- .github/workflows/e2e.yaml | 2 +- apps/cli/src/linter/exporter.ts | 2 +- apps/cli/src/linter/schema.ts | 5 +- apps/cli/src/linter/specs/common.spec.ts | 57 +++++++++++++++++++++ libs/backend-api7/e2e/misc.e2e-spec.ts | 65 ++++++++++++++++++++++++ schema.json | 2 +- 6 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 apps/cli/src/linter/specs/common.spec.ts create mode 100644 libs/backend-api7/e2e/misc.e2e-spec.ts diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index ef3e5df..6d688a6 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -39,7 +39,7 @@ jobs: if: contains(github.event.pull_request.labels.*.name, 'test/api7') || github.event_name == 'push' strategy: matrix: - version: [3.2.13.0, 3.2.14.3] + version: [3.2.13.0, 3.2.14.5] env: BACKEND_API7_DOWNLOAD_URL: https://run.api7.ai/api7-ee/api7-ee-v${{ matrix.version }}.tar.gz BACKEND_API7_LICENSE: ${{ secrets.BACKEND_API7_LICENSE }} diff --git a/apps/cli/src/linter/exporter.ts b/apps/cli/src/linter/exporter.ts index 5fe265f..2d5fcad 100644 --- a/apps/cli/src/linter/exporter.ts +++ b/apps/cli/src/linter/exporter.ts @@ -11,5 +11,5 @@ import { ConfigurationSchema } from './schema'; writeFileSync( 'schema.json', - JSON.stringify(zodToJsonSchema(ConfigurationSchema), null, 2), + JSON.stringify(zodToJsonSchema(ConfigurationSchema), null, 2) + '\n', ); diff --git a/apps/cli/src/linter/schema.ts b/apps/cli/src/linter/schema.ts index 9686048..3b268a2 100644 --- a/apps/cli/src/linter/schema.ts +++ b/apps/cli/src/linter/schema.ts @@ -1,7 +1,10 @@ import { z } from 'zod'; const nameSchema = z.string().min(1).max(100); -const descriptionSchema = z.string().max(256).optional(); +const descriptionSchema = z + .string() + .max(64 * 1024) + .optional(); const labelsSchema = z.record( z.string(), z.union([z.string(), z.array(z.string())]), diff --git a/apps/cli/src/linter/specs/common.spec.ts b/apps/cli/src/linter/specs/common.spec.ts new file mode 100644 index 0000000..d12d784 --- /dev/null +++ b/apps/cli/src/linter/specs/common.spec.ts @@ -0,0 +1,57 @@ +import * as ADCSDK from '@api7/adc-sdk'; + +import { check } from '../'; + +describe('Common Linter', () => { + const cases = [ + { + name: 'should check description length (length <= 64 * 1024)', + input: { + services: [ + { + name: 'test', + description: ''.padEnd(64 * 1024, '0'), + routes: [], + }, + ], + } as ADCSDK.Configuration, + expect: true, + errors: [], + }, + { + name: 'should check description length (length > 64 * 1024)', + input: { + services: [ + { + name: 'test', + description: ''.padEnd(64 * 1024 + 1, '0'), + routes: [], + }, + ], + } as ADCSDK.Configuration, + expect: false, + errors: [ + { + code: 'too_big', + exact: false, + inclusive: true, + maximum: 65536, + message: 'String must contain at most 65536 character(s)', + path: ['services', 0, 'description'], + type: 'string', + }, + ], + }, + ]; + + // test cases runner + cases.forEach((item) => { + it(item.name, () => { + const result = check(item.input); + expect(result.success).toEqual(item.expect); + if (!item.expect) { + expect(result.error.errors).toEqual(item.errors); + } + }); + }); +}); diff --git a/libs/backend-api7/e2e/misc.e2e-spec.ts b/libs/backend-api7/e2e/misc.e2e-spec.ts new file mode 100644 index 0000000..877deec --- /dev/null +++ b/libs/backend-api7/e2e/misc.e2e-spec.ts @@ -0,0 +1,65 @@ +import * as ADCSDK from '@api7/adc-sdk'; +import { unset } from 'lodash'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { BackendAPI7 } from '../src'; +import { + createEvent, + deleteEvent, + dumpConfiguration, + syncEvents, + updateEvent, +} from './support/utils'; + +describe('Miscellaneous', () => { + let backend: BackendAPI7; + + beforeAll(() => { + backend = new BackendAPI7({ + server: process.env.SERVER, + token: process.env.TOKEN, + tlsSkipVerify: true, + gatewayGroup: 'default', + }); + }); + + describe('Sync resources with the description greater than 256 bytes', () => { + const service1Name = 'service1'; + const service1 = { + name: service1Name, + description: ''.padEnd(64 * 1024, '0'), // 65536 bytes + upstream: { + scheme: 'https', + nodes: [ + { + host: 'httpbin.org', + port: 443, + weight: 100, + }, + ], + }, + } as ADCSDK.Service; + + it('Create services', async () => + syncEvents(backend, [ + createEvent(ADCSDK.ResourceType.SERVICE, service1Name, service1), + ])); + + it('Dump', async () => { + const result = (await dumpConfiguration(backend)) as ADCSDK.Configuration; + expect(result.services).toHaveLength(1); + expect(result.services[0]).toMatchObject(service1); + }); + + it('Delete service', async () => + syncEvents(backend, [ + deleteEvent(ADCSDK.ResourceType.SERVICE, service1Name), + ])); + + it('Dump again', async () => { + const result = (await dumpConfiguration(backend)) as ADCSDK.Configuration; + expect(result.services).toHaveLength(0); + }); + }); +}); diff --git a/schema.json b/schema.json index 8b22e06..295f3ac 100644 --- a/schema.json +++ b/schema.json @@ -13,7 +13,7 @@ }, "description": { "type": "string", - "maxLength": 256 + "maxLength": 65536 }, "labels": { "type": "object",