@@ -1107,6 +1107,11 @@ obj:
1107
1107
} ) ;
1108
1108
1109
1109
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
+ } ) ;
1110
1115
it ( 'Test that properties that match multiple enums get validated properly' , ( done ) => {
1111
1116
languageService . configure ( languageSettingsSetup . withKubernetes ( ) . languageSettings ) ;
1112
1117
yamlSettings . specificValidatorPaths = [ '*.yml' , '*.yaml' ] ;
@@ -1152,6 +1157,62 @@ obj:
1152
1157
} )
1153
1158
. then ( done , done ) ;
1154
1159
} ) ;
1160
+
1161
+ it ( 'single custom kubernetes schema version should return validation errors' , async ( ) => {
1162
+ const customKubernetesSchemaVersion = 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.26.1-standalone-strict/all.json' ;
1163
+ yamlSettings . kubernetesSchemaUrls = [ customKubernetesSchemaVersion ] ;
1164
+ const settingsHandler = new SettingsHandler ( { } as Connection , languageService , yamlSettings , validationHandler , telemetry ) ;
1165
+ const initialSettings = languageSettingsSetup . withKubernetes ( true ) . languageSettings ;
1166
+ const kubernetesSettings = settingsHandler . configureSchemas (
1167
+ customKubernetesSchemaVersion ,
1168
+ [ '*k8s.yml' ] ,
1169
+ undefined ,
1170
+ initialSettings ,
1171
+ SchemaPriority . SchemaAssociation
1172
+ ) ;
1173
+ languageService . configure ( kubernetesSettings ) ;
1174
+ const content = `apiVersion: apps/v1\nkind: Deployment\nfoo: bar` ;
1175
+ const result = await parseSetup ( content , 'invalid-k8s.yml' ) ;
1176
+ expect ( result . length ) . to . eq ( 1 ) ;
1177
+ expect ( result [ 0 ] . message ) . to . eq ( 'Property foo is not allowed.' ) ;
1178
+ } ) ;
1179
+
1180
+ it ( 'custom kubernetes schema version and openshift custom resource definition (CRD) should return validation errors' , async ( ) => {
1181
+ const customKubernetesSchemaVersion = 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.26.1-standalone-strict/all.json' ;
1182
+ const customOpenshiftSchemaVersion = 'https://raw.githubusercontent.com/tricktron/CRDs-catalog/f-openshift-v4.11/openshift.io/v4.11/all.json' ;
1183
+ yamlSettings . kubernetesSchemaUrls = [ customKubernetesSchemaVersion , customOpenshiftSchemaVersion ] ;
1184
+ const settingsHandler = new SettingsHandler ( { } as Connection , languageService , yamlSettings , validationHandler , telemetry ) ;
1185
+ const initialSettings = languageSettingsSetup . withKubernetes ( true ) . languageSettings ;
1186
+ const kubernetesSettings = settingsHandler . configureSchemas (
1187
+ customKubernetesSchemaVersion ,
1188
+ [ '*k8s.yml' ] ,
1189
+ undefined ,
1190
+ initialSettings ,
1191
+ SchemaPriority . SchemaAssociation
1192
+ ) ;
1193
+ const openshiftSettings = settingsHandler . configureSchemas (
1194
+ customOpenshiftSchemaVersion ,
1195
+ [ '*oc.yml' ] ,
1196
+ undefined ,
1197
+ initialSettings ,
1198
+ SchemaPriority . SchemaAssociation
1199
+ ) ;
1200
+ languageService . configure ( kubernetesSettings ) ;
1201
+ languageService . configure ( openshiftSettings ) ;
1202
+ const kubernetes = `apiVersion: apps/v1\nkind: Deployment\nfoo: bar` ;
1203
+ const openshift = `apiVersion: route.openshift.io/v1\nkind: Route\nbaz: abc` ;
1204
+
1205
+ const kubernetesResult = await parseSetup ( kubernetes , 'invalid-k8s.yml' ) ;
1206
+
1207
+ expect ( kubernetesResult . length ) . to . eq ( 1 ) ;
1208
+ expect ( kubernetesResult [ 0 ] . message ) . to . eq ( 'Property foo is not allowed.' ) ;
1209
+
1210
+ const openshiftResult = await parseSetup ( openshift , 'invalid-oc.yml' ) ;
1211
+
1212
+ expect ( openshiftResult . length ) . to . eq ( 2 ) ;
1213
+ expect ( openshiftResult [ 0 ] . message ) . to . eq ( 'Missing property "spec".' ) ;
1214
+ expect ( openshiftResult [ 1 ] . message ) . to . eq ( 'Property baz is not allowed.' ) ;
1215
+ } ) ;
1155
1216
} ) ;
1156
1217
1157
1218
// https://github.com/redhat-developer/yaml-language-server/issues/118
@@ -1904,24 +1965,5 @@ obj:
1904
1965
expect ( result [ 0 ] . message ) . to . eq ( 'Matches multiple schemas when only one must validate.' ) ;
1905
1966
expect ( telemetry . messages ) . to . be . empty ;
1906
1967
} ) ;
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
- } ) ;
1926
1968
} ) ;
1927
1969
} ) ;
0 commit comments