-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): linter looser description length (#175)
- Loading branch information
Showing
6 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters