Skip to content

Commit

Permalink
feat(core): linter looser description length (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 authored Aug 22, 2024
1 parent 4b1a7c2 commit 52087e7
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/linter/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import { ConfigurationSchema } from './schema';

writeFileSync(
'schema.json',
JSON.stringify(zodToJsonSchema(ConfigurationSchema), null, 2),
JSON.stringify(zodToJsonSchema(ConfigurationSchema), null, 2) + '\n',
);
5 changes: 4 additions & 1 deletion apps/cli/src/linter/schema.ts
Original file line number Diff line number Diff line change
@@ -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())]),
Expand Down
57 changes: 57 additions & 0 deletions apps/cli/src/linter/specs/common.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});
});
});
65 changes: 65 additions & 0 deletions libs/backend-api7/e2e/misc.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
2 changes: 1 addition & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"description": {
"type": "string",
"maxLength": 256
"maxLength": 65536
},
"labels": {
"type": "object",
Expand Down

0 comments on commit 52087e7

Please sign in to comment.