@@ -1107,6 +1107,11 @@ obj:
11071107 } ) ;
11081108
11091109 describe ( 'Test with custom kubernetes schemas' , function ( ) {
1110+ afterEach ( ( ) => {
1111+ // remove Kubernetes setting not to affect next tests
1112+ languageService . configure ( languageSettingsSetup . withKubernetes ( false ) . languageSettings ) ;
1113+ yamlSettings . specificValidatorPaths = [ ] ;
1114+ } ) ;
11101115 it ( 'Test that properties that match multiple enums get validated properly' , ( done ) => {
11111116 languageService . configure ( languageSettingsSetup . withKubernetes ( ) . languageSettings ) ;
11121117 yamlSettings . specificValidatorPaths = [ '*.yml' , '*.yaml' ] ;
@@ -1152,6 +1157,65 @@ obj:
11521157 } )
11531158 . then ( done , done ) ;
11541159 } ) ;
1160+
1161+ it ( 'single custom kubernetes schema version should return validation errors' , async ( ) => {
1162+ const customKubernetesSchemaVersion =
1163+ 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.26.1-standalone-strict/all.json' ;
1164+ yamlSettings . kubernetesSchemaUrls = [ customKubernetesSchemaVersion ] ;
1165+ const settingsHandler = new SettingsHandler ( { } as Connection , languageService , yamlSettings , validationHandler , telemetry ) ;
1166+ const initialSettings = languageSettingsSetup . withKubernetes ( true ) . languageSettings ;
1167+ const kubernetesSettings = settingsHandler . configureSchemas (
1168+ customKubernetesSchemaVersion ,
1169+ [ '*k8s.yml' ] ,
1170+ undefined ,
1171+ initialSettings ,
1172+ SchemaPriority . SchemaAssociation
1173+ ) ;
1174+ languageService . configure ( kubernetesSettings ) ;
1175+ const content = `apiVersion: apps/v1\nkind: Deployment\nfoo: bar` ;
1176+ const result = await parseSetup ( content , 'invalid-k8s.yml' ) ;
1177+ expect ( result . length ) . to . eq ( 1 ) ;
1178+ expect ( result [ 0 ] . message ) . to . eq ( 'Property foo is not allowed.' ) ;
1179+ } ) ;
1180+
1181+ it ( 'custom kubernetes schema version and openshift custom resource definition (CRD) should return validation errors' , async ( ) => {
1182+ const customKubernetesSchemaVersion =
1183+ 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.26.1-standalone-strict/all.json' ;
1184+ const customOpenshiftSchemaVersion =
1185+ 'https://raw.githubusercontent.com/tricktron/CRDs-catalog/f-openshift-v4.11/openshift.io/v4.11/all.json' ;
1186+ yamlSettings . kubernetesSchemaUrls = [ customKubernetesSchemaVersion , customOpenshiftSchemaVersion ] ;
1187+ const settingsHandler = new SettingsHandler ( { } as Connection , languageService , yamlSettings , validationHandler , telemetry ) ;
1188+ const initialSettings = languageSettingsSetup . withKubernetes ( true ) . languageSettings ;
1189+ const kubernetesSettings = settingsHandler . configureSchemas (
1190+ customKubernetesSchemaVersion ,
1191+ [ '*k8s.yml' ] ,
1192+ undefined ,
1193+ initialSettings ,
1194+ SchemaPriority . SchemaAssociation
1195+ ) ;
1196+ const openshiftSettings = settingsHandler . configureSchemas (
1197+ customOpenshiftSchemaVersion ,
1198+ [ '*oc.yml' ] ,
1199+ undefined ,
1200+ initialSettings ,
1201+ SchemaPriority . SchemaAssociation
1202+ ) ;
1203+ languageService . configure ( kubernetesSettings ) ;
1204+ languageService . configure ( openshiftSettings ) ;
1205+ const kubernetes = `apiVersion: apps/v1\nkind: Deployment\nfoo: bar` ;
1206+ const openshift = `apiVersion: route.openshift.io/v1\nkind: Route\nbaz: abc` ;
1207+
1208+ const kubernetesResult = await parseSetup ( kubernetes , 'invalid-k8s.yml' ) ;
1209+
1210+ expect ( kubernetesResult . length ) . to . eq ( 1 ) ;
1211+ expect ( kubernetesResult [ 0 ] . message ) . to . eq ( 'Property foo is not allowed.' ) ;
1212+
1213+ const openshiftResult = await parseSetup ( openshift , 'invalid-oc.yml' ) ;
1214+
1215+ expect ( openshiftResult . length ) . to . eq ( 2 ) ;
1216+ expect ( openshiftResult [ 0 ] . message ) . to . eq ( 'Missing property "spec".' ) ;
1217+ expect ( openshiftResult [ 1 ] . message ) . to . eq ( 'Property baz is not allowed.' ) ;
1218+ } ) ;
11551219 } ) ;
11561220
11571221 // https://github.com/redhat-developer/yaml-language-server/issues/118
@@ -1904,24 +1968,5 @@ obj:
19041968 expect ( result [ 0 ] . message ) . to . eq ( 'Matches multiple schemas when only one must validate.' ) ;
19051969 expect ( telemetry . messages ) . to . be . empty ;
19061970 } ) ;
1907-
1908- it ( 'single custom kubernetes schema should return validation errors' , async ( ) => {
1909- const customKubernetesSchemaVersion = 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.26.1-standalone-strict/all.json' ;
1910- yamlSettings . kubernetesSchemaUrls = [ customKubernetesSchemaVersion ] ;
1911- const settingsHandler = new SettingsHandler ( { } as Connection , languageService , yamlSettings , validationHandler , telemetry ) ;
1912- const initialSettings = languageSettingsSetup . withKubernetes ( true ) . languageSettings ;
1913- const kubernetesSettings = settingsHandler . configureSchemas (
1914- customKubernetesSchemaVersion ,
1915- [ '*k8s.yml' ] ,
1916- undefined ,
1917- initialSettings ,
1918- SchemaPriority . SchemaAssociation
1919- ) ;
1920- languageService . configure ( kubernetesSettings ) ;
1921- const content = `apiVersion: apps/v1\nkind: Deployment\nfoo: bar` ;
1922- const result = await parseSetup ( content , 'invalid-k8s.yml' ) ;
1923- expect ( result . length ) . to . eq ( 1 ) ;
1924- expect ( result [ 0 ] . message ) . to . eq ( 'Property foo is not allowed.' ) ;
1925- } ) ;
19261971 } ) ;
19271972} ) ;
0 commit comments