File tree Expand file tree Collapse file tree 3 files changed +89
-5
lines changed
Expand file tree Collapse file tree 3 files changed +89
-5
lines changed Original file line number Diff line number Diff line change 1+ import { describe , it , expect } from 'vitest' ;
2+ import {
3+ projectWorkspaceNameRegex ,
4+ managedControlPlaneNameRegex ,
5+ } from './regex' ;
6+
7+ describe ( 'projectWorkspaceNameRegex' , ( ) => {
8+ const valid = [
9+ 'Project1' ,
10+ 'my-project' ,
11+ 'A1-B2-C3' ,
12+ 'abc.DEF-123' ,
13+ 'a' . repeat ( 63 ) ,
14+ 'abc.def.ghi' ,
15+ 'A-1.b-2' ,
16+ 'abc123' ,
17+ 'abc-123.DEF' ,
18+ ] ;
19+ const invalid = [
20+ '-project' ,
21+ 'project-' ,
22+ '.project' ,
23+ 'project.' ,
24+ 'a' . repeat ( 64 ) ,
25+ 'abc..def' ,
26+ 'abc.-def' ,
27+ 'abc-.def' ,
28+ 'abc_def' ,
29+ 'abc@def' ,
30+ ] ;
31+
32+ it ( 'matches valid project or workspace names' , ( ) => {
33+ for ( const name of valid ) {
34+ expect ( projectWorkspaceNameRegex . test ( name ) ) . toBe ( true ) ;
35+ }
36+ } ) ;
37+
38+ it ( 'does not match invalid project or workspace names' , ( ) => {
39+ for ( const name of invalid ) {
40+ expect ( projectWorkspaceNameRegex . test ( name ) ) . toBe ( false ) ;
41+ }
42+ } ) ;
43+ } ) ;
44+
45+ describe ( 'managedControlPlaneNameRegex' , ( ) => {
46+ const valid = [
47+ 'my-mcp' ,
48+ 'abc123' ,
49+ 'abc-123' ,
50+ 'abc.def' ,
51+ 'a' . repeat ( 63 ) ,
52+ 'abc.def-ghi' ,
53+ 'abc-123.def' ,
54+ 'abc1-2.def3' ,
55+ 'abc.def.ghi' ,
56+ ] ;
57+ const invalid = [
58+ 'My-MCP' ,
59+ 'ABC' ,
60+ '-mcp' ,
61+ 'mcp-' ,
62+ '.mcp' ,
63+ 'mcp.' ,
64+ 'a' . repeat ( 64 ) ,
65+ 'abc..def' ,
66+ 'abc-.def' ,
67+ 'abc.-def' ,
68+ ] ;
69+
70+ it ( 'matches valid managed control plane names' , ( ) => {
71+ for ( const name of valid ) {
72+ expect ( managedControlPlaneNameRegex . test ( name ) ) . toBe ( true ) ;
73+ }
74+ } ) ;
75+
76+ it ( 'does not match invalid managed control plane names' , ( ) => {
77+ for ( const name of invalid ) {
78+ expect ( managedControlPlaneNameRegex . test ( name ) ) . toBe ( false ) ;
79+ }
80+ } ) ;
81+ } ) ;
Original file line number Diff line number Diff line change 1+ export const projectWorkspaceNameRegex =
2+ / ^ (? ! - ) [ a - z A - Z 0 - 9 - ] { 1 , 63 } (?< ! - ) (?: \. (? ! - ) [ a - z A - Z 0 - 9 - ] { 1 , 63 } (?< ! - ) ) * $ / ;
3+ export const managedControlPlaneNameRegex =
4+ / ^ (? ! - ) [ a - z 0 - 9 - ] { 1 , 63 } (?< ! - ) (?: \. (? ! - ) [ a - z 0 - 9 - ] { 1 , 63 } (?< ! - ) ) * $ / ;
Original file line number Diff line number Diff line change 11import { z } from 'zod' ;
22import { Member } from '../types/shared/members.ts' ;
33import i18n from '../../../../i18n.ts' ;
4+ import {
5+ managedControlPlaneNameRegex ,
6+ projectWorkspaceNameRegex ,
7+ } from './regex.ts' ;
48
59const { t } = i18n ;
610
711const member = z . custom < Member > ( ) ;
812
9- export const projectWorkspaceNameRegex =
10- / ^ (? ! - ) [ a - z A - Z 0 - 9 - ] { 1 , 63 } (?< ! - ) (?: \. (? ! - ) [ a - z A - Z 0 - 9 - ] { 1 , 63 } (?< ! - ) ) * $ / ;
11- export const managedControlPlaneNameRegex =
12- / ^ (? ! - ) [ a - z 0 - 9 - ] { 1 , 63 } (?< ! - ) (?: \. (? ! - ) [ a - z 0 - 9 - ] { 1 , 63 } (?< ! - ) ) * $ / ;
13-
1413export const validationSchemaProjectWorkspace = z . object ( {
1514 name : z
1615 . string ( )
You can’t perform that action at this time.
0 commit comments