kibana/x-pack/plugins/ml/common/util/es_utils.test.ts
James Gowdy 35302ed273
[ML] Client side cut over (#60100)
* [ML] Client side cut over

* updating paths and commented code

* changes based on review

* disabling telemetry tests

* fixing start job stylesheets

* fixing everything that is broken

* fixing types and ml icon order

* using icon constant
2020-03-13 19:16:41 +00:00

58 lines
2.4 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { isValidIndexName } from './es_utils';
describe('Util: isValidIndexName()', () => {
test('Validation checks.', () => {
// Lowercase only
expect(isValidIndexName('lorem')).toBe(true);
expect(isValidIndexName('loRem')).toBe(false);
// Cannot include \, /, *, ?, ", <, >, |, space character, comma, #, :
expect(isValidIndexName('\\')).toBe(false);
expect(isValidIndexName('/')).toBe(false);
expect(isValidIndexName('*')).toBe(false);
expect(isValidIndexName('?')).toBe(false);
expect(isValidIndexName('"')).toBe(false);
expect(isValidIndexName('<')).toBe(false);
expect(isValidIndexName('>')).toBe(false);
expect(isValidIndexName('|')).toBe(false);
expect(isValidIndexName(' ')).toBe(false);
expect(isValidIndexName(',')).toBe(false);
expect(isValidIndexName('#')).toBe(false);
// Cannot start with -, _, +
expect(isValidIndexName('lorem-ipsum')).toBe(true);
expect(isValidIndexName('lorem_ipsum')).toBe(true);
expect(isValidIndexName('lorem+ipsum')).toBe(true);
expect(isValidIndexName('lorem-')).toBe(true);
expect(isValidIndexName('lorem_')).toBe(true);
expect(isValidIndexName('lorem+')).toBe(true);
expect(isValidIndexName('-lorem')).toBe(false);
expect(isValidIndexName('_lorem')).toBe(false);
expect(isValidIndexName('+lorem')).toBe(false);
// Cannot be . or ..
expect(isValidIndexName('lorem.ipsum')).toBe(true);
expect(isValidIndexName('lorem.')).toBe(true);
expect(isValidIndexName('.lorem')).toBe(true);
expect(isValidIndexName('lorem..ipsum')).toBe(true);
expect(isValidIndexName('lorem..')).toBe(true);
expect(isValidIndexName('..lorem')).toBe(true);
expect(isValidIndexName('.')).toBe(false);
expect(isValidIndexName('..')).toBe(false);
// Cannot be longer than 255 bytes (note it is bytes,
// so multi-byte characters will count towards the 255 limit faster)
expect(isValidIndexName('a'.repeat(255))).toBe(true);
expect(isValidIndexName('a'.repeat(256))).toBe(false);
// multi-byte character test
// because jest doesn't have TextEncoder this will still be true
expect(isValidIndexName('あ'.repeat(255))).toBe(true);
});
});