Debian Codegraph @

mysql-test/suite/x/t/admin_create_collection_with_validation.test

raw
1 ## Test create_collection command in context of schema validation
2
3 ## Preamble
4 --source include/xplugin_preamble.inc
5 --source include/xplugin_create_user.inc
6 ## Tests start here
7
8 create schema xtest default charset 'utf8mb4';
9
10 --let $xtest_file= $MYSQL_TMP_DIR/admin_create_collection_with_validation.xpl
11 --write_file $xtest_file
12 -->import validation_schema.macro
13 -->varlet %TEST_COLL% test_coll
14
15 -->macro Drop_test_collection
16 -->callmacro Drop_collection %TEST_COLL%
17 -->endmacro
18
19 varlet %CREATE_COLLECTION_ARG_HEAD% {
20 "schema": "xtest", "name": "%TEST_COLL%", "options": {"validation":;
21 -->varlet %CREATE_COLLECTION_ARG_TAIL% }}
22
23 -->macro Create_collection_validation_string %LEVEL%
24 varlet %STR% %CREATE_COLLECTION_ARG_HEAD% {"schema": "{
25 \"id\": \"http://json-schema.org/geo\",
26 \"$schema\": \"http://json-schema.org/draft-06/schema#\",
27 \"description\": \"A geographical coordinate\",
28 \"type\": \"object\",
29 \"properties\": {
30 \"latitude\": {\"type\": \"number\", \"minimum\": -90, \"maximum\": 90},
31 \"longitude\": {\"type\": \"number\", \"minimum\": -180, \"maximum\": 180}},
32 \"required\": [\"latitude\", \"longitude\"]}",
33 "level": %LEVEL%}
34 %CREATE_COLLECTION_ARG_TAIL%;
35 -->stmtadmin COMMAND %STR%
36 -->endmacro
37
38 -->macro Create_collection_validation_obj %LEVEL%
39 varlet %STR% %CREATE_COLLECTION_ARG_HEAD% {"schema": {
40 "id": "http://json-schema.org/geo",
41 "$schema": "http://json-schema.org/draft-06/schema#",
42 "description": "A geographical coordinate",
43 "type": "object",
44 "properties": {
45 "latitude": {"type": "number", "minimum": -90, "maximum": 90},
46 "longitude": {"type": "number", "minimum": -180, "maximum": 180}},
47 "required": ["latitude", "longitude"]},
48 "level": %LEVEL%}
49 %CREATE_COLLECTION_ARG_TAIL%;
50 -->stmtadmin COMMAND %STR%
51 -->endmacro
52
53 -->echo
54 -->echo
55 -->echo ## I. Check validation schema setting when creating a collection. Check
56 -->echo # result of insert operation which violates the check constraints.
57 -->echo #
58 -->echo # 1. Check collection creation with valid schema encoded as protobuf
59 -->echo # string.
60 -->echo # 2. Check collection creation with valid schema encoded as
61 -->echo # Mysqlx.Datatypes.Object.
62 -->echo # 3. Check that when validation is not enforced then it is possible to
63 -->echo # insert noncopmlying data.
64 -->echo # 4. Check collection creation using schema encoded as
65 -->echo # Mysqlx>datatypes.Object containing special characters in key/values.
66 -->echo
67 -->echo ## II. Check validation level setting.
68 -->echo #
69 -->echo # 1. Check validation level set to 'off'.
70 -->echo # a. Check validation level for validation encoded as protobuf string.
71 -->echo # b. Check validation level for validation encoded as
72 -->echo # Mysqlx.Datatypes.Object.
73 -->echo # 2. Check validation level set to 'strict'.
74 -->echo # a. Check validation level for validation encoded as protobuf string.
75 -->echo # b. Check validation level for validation encoded as
76 -->echo # Mysqlx.Datatypes.Object.
77 -->echo # 3. Assert that validation field is optional and check the default
78 -->echo # setting for validation level.
79 -->echo # a. Check validation level for validation encoded as protobuf string.
80 -->echo # b. Check validation level for validation encoded as
81 -->echo # Mysqlx.Datatypes.Object.
82 -->echo # 4. Check invalid value for validation level field.
83 -->echo # a. Check validation level for validation encoded as protobuf string.
84 -->echo # b. Check validation level for validation encoded as
85 -->echo # Mysqlx.Datatypes.Object.
86 -->echo # 5. Check invalid collection option.
87 -->echo
88 -->echo ## III. Create collection without the optional validation field.
89 -->echo
90 -->echo ## IV. Create collection with empty validation schema field.
91 -->echo #
92 -->echo # 1. Check empty validation schema for validation encoded as protobuf
93 -->echo # string.
94 -->echo # 2. Check empty validation schema for validation encoded as
95 -->echo # Mysqlx.Datatypes.Object.
96 -->echo
97 -->echo ## V. Create collection with invalid validation options.
98 -->echo #
99 -->echo # 1. Validation contains only unknown fields.
100 -->echo # 2. Validation contains valid fields along with unknown fields.
101 -->echo # 3. Options is different type than "object".
102 -->echo
103 -->echo ## IV. Create collection with empty validation level.
104 -->echo #
105 -->echo # 1. Check empty validation level for validation encoded as protobuf
106 -->echo # string.
107 -->echo # 2. Check empty validation level for validation encoded as
108 -->echo # Mysqlx.Datatypes.Object.
109
110 -->quiet
111
112 -->echo
113 -->echo #
114 -->echo # I.1
115 -->callmacro Create_collection_validation_string "strict"
116 -->recvresult
117 -->stmtsql show create table xtest.%TEST_COLL%
118 -->recvresult
119 callmacro Insert_value_to_collection %TEST_COLL%
120 '{"_id": "one", "latitude":3312}';
121 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
122 callmacro Insert_value_to_collection %TEST_COLL%
123 '{"_id": "one", "latitude":45, "longitude":54}';
124 -->recvresult
125 callmacro Update_item %TEST_COLL%
126 latitude
127 {type: V_SINT v_signed_int: 45}
128 {type: V_SINT v_signed_int: 999};
129 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
130 callmacro Update_item %TEST_COLL%
131 latitude
132 {type: V_SINT v_signed_int: 45}
133 {type: V_SINT v_signed_int: 72};
134 -->recvresult
135 -->stmtsql SELECT * FROM xtest.%TEST_COLL%;
136 -->recvresult
137 -->callmacro Drop_test_collection
138
139 -->echo
140 -->echo #
141 -->echo # I.2
142 -->callmacro Create_collection_validation_obj "strict"
143 -->recvresult
144 -->stmtsql show create table xtest.%TEST_COLL%
145 -->recvresult
146 callmacro Insert_value_to_collection %TEST_COLL%
147 '{"_id": "one", "latitude":3312}';
148 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
149 callmacro Insert_value_to_collection %TEST_COLL%
150 '{"_id": "one", "latitude":45, "longitude":54}';
151 -->recvresult
152 callmacro Update_item %TEST_COLL%
153 latitude
154 {type: V_SINT v_signed_int: 45}
155 {type: V_SINT v_signed_int: 999};
156 -->recverror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
157 callmacro Update_item %TEST_COLL%
158 latitude
159 {type: V_SINT v_signed_int: 45}
160 {type: V_SINT v_signed_int: 72};
161 -->recvresult
162 -->stmtsql select * from xtest.%TEST_COLL%;
163 -->recvresult
164 -->callmacro Drop_test_collection
165
166 -->echo
167 -->echo #
168 -->echo # I.3
169 -->callmacro Create_collection_validation_string "off"
170 -->recvresult
171 callmacro Insert_value_to_collection %TEST_COLL%
172 '{"_id": "one", "latitude":3312}';
173 -->recvresult
174 callmacro Insert_value_to_collection %TEST_COLL%
175 '{"_id": "two", "latitude":45, "longitude":54}';
176 -->recvresult
177 -->stmtsql select * from xtest.%TEST_COLL%;
178 -->recvresult
179 -->callmacro Drop_test_collection
180
181 -->echo
182 -->echo #
183 -->echo # I.4
184 stmtadmin create_collection {"schema": "xtest", "name": "%TEST_COLL%", "options": {
185 "validation": {
186 "level": "STRICT",
187 "schema": {"description": "t`y\\p\"e o`b`\\\\c\"\"t"}
188 }
189 }};
190 -->recvresult
191 -->stmtsql show create table xtest.%TEST_COLL%
192 -->recvresult
193 -->callmacro Drop_test_collection
194
195 -->echo
196 -->echo #
197 -->echo # II.1.a
198 -->callmacro Create_collection_validation_string "off"
199 -->recvresult
200 -->callmacro Assert_is_enforced %TEST_COLL% NO
201 -->callmacro Drop_test_collection
202 -->callmacro Create_collection_validation_string "OFF"
203 -->recvresult
204 -->callmacro Assert_is_enforced %TEST_COLL% NO
205 -->callmacro Drop_test_collection
206
207 -->echo
208 -->echo #
209 -->echo # II.1.b
210 -->callmacro Create_collection_validation_obj "off"
211 -->recvresult
212 -->callmacro Assert_is_enforced %TEST_COLL% NO
213 -->callmacro Drop_test_collection
214 -->callmacro Create_collection_validation_obj "OFF"
215 -->recvresult
216 -->callmacro Assert_is_enforced %TEST_COLL% NO
217 -->callmacro Drop_test_collection
218
219 -->echo
220 -->echo #
221 -->echo # II.2.a
222 -->callmacro Create_collection_validation_string "strict"
223 -->recvresult
224 -->callmacro Assert_is_enforced %TEST_COLL% YES
225 -->callmacro Drop_test_collection
226 -->callmacro Create_collection_validation_string "STRICT"
227 -->recvresult
228 -->callmacro Assert_is_enforced %TEST_COLL% YES
229 -->callmacro Drop_test_collection
230
231 -->echo
232 -->echo #
233 -->echo # II.2.b
234 -->callmacro Create_collection_validation_obj "strict"
235 -->recvresult
236 -->callmacro Assert_is_enforced %TEST_COLL% YES
237 -->callmacro Drop_test_collection
238 -->callmacro Create_collection_validation_obj "STRICT"
239 -->recvresult
240 -->callmacro Assert_is_enforced %TEST_COLL% YES
241 -->callmacro Drop_test_collection
242
243 -->echo
244 -->echo #
245 -->echo # II.3.a
246 stmtadmin create_collection {"schema": "xtest", "name": "%TEST_COLL%", "options": {
247 "validation": {
248 "schema": "{\"type\": \"object\"}"
249 }
250 }};
251 -->recvresult
252 -->callmacro Assert_is_enforced %TEST_COLL% YES
253 -->callmacro Drop_test_collection
254
255 -->echo
256 -->echo #
257 -->echo # II.3.b
258 stmtadmin create_collection {"schema": "xtest", "name": "%TEST_COLL%", "options": {
259 "validation": {
260 "schema": {"type": "object"}
261 }
262 }};
263 -->recvresult
264 -->callmacro Assert_is_enforced %TEST_COLL% YES
265 -->callmacro Drop_test_collection
266
267 -->echo
268 -->echo #
269 -->echo # II.4.a
270 -->callmacro Create_collection_validation_string "somerandomgarbage"
271 -->recverror ER_X_CMD_ARGUMENT_VALUE
272
273 -->echo
274 -->echo #
275 -->echo # II.4.b
276 -->callmacro Create_collection_validation_obj "somerandomgarbage"
277 -->recverror ER_X_CMD_ARGUMENT_VALUE
278
279 -->echo
280 -->echo #
281 -->echo # II.5
282 stmtadmin create_collection {"schema": "xtest", "name": "%TEST_COLL%", "options": {
283 "foo": {
284 "schema": {"type": "object"}
285 }
286 }};
287 -->recverror ER_X_CMD_INVALID_ARGUMENT
288
289 -->echo
290 -->echo #
291 -->echo # III
292 -->stmtadmin COMMAND {"schema": "xtest", "name": "%TEST_COLL%"}
293 -->recvresult
294 -->stmtsql show create table xtest.%TEST_COLL%
295 -->recvresult
296 -->callmacro Drop_test_collection
297
298 -->echo
299 -->echo #
300 -->echo # IV.1
301 stmtadmin create_collection {"schema": "xtest", "name": "%TEST_COLL%", "options": {
302 "validation": {
303 "schema": "{}"
304 }
305 }};
306 -->recvresult
307 -->stmtsql show create table xtest.%TEST_COLL%
308 -->recvresult
309 -->callmacro Drop_test_collection
310
311 -->echo
312 -->echo #
313 -->echo # IV.2
314 stmtadmin create_collection {"schema": "xtest", "name": "%TEST_COLL%", "options": {
315 "validation": {
316 "schema": {}
317 }
318 }};
319 -->recvresult
320 -->stmtsql show create table xtest.%TEST_COLL%
321 -->recvresult
322 -->callmacro Drop_test_collection
323
324
325 -->echo
326 -->echo #
327 -->echo # V.1
328 stmtadmin COMMAND {"schema": "xtest", "name": "coll", "options": {
329 "validation": {
330 "foo": "bar", "baz": ""
331 }
332 }};
333 -->recverror ER_X_CMD_INVALID_ARGUMENT
334
335
336 -->echo
337 -->echo #
338 -->echo # V.2
339 stmtadmin COMMAND {"schema": "xtest", "name": "coll", "options": {
340 "validation": {
341 "foo": "bar", "level": "off"
342 }
343 }};
344 -->recverror ER_X_CMD_INVALID_ARGUMENT
345
346 -->echo
347 -->echo #
348 -->echo # V.3
349 stmtadmin COMMAND {"schema": "xtest", "name": "coll", "options": "dump" };
350 -->recverror ER_X_CMD_ARGUMENT_TYPE
351
352 -->echo
353 -->echo #
354 -->echo # VI.1
355 stmtadmin create_collection {
356 "schema":"xtest",
357 "name": "%TEST_COLL%",
358 "options": {
359 "validation": {
360 "schema": {
361 "type": "object",
362 "properties": {
363 "latitude": {"type": "number", "minimum": -90, "maximum": 90},
364 "longitude": {"type": "number", "minimum": -180, "maximum": 180}
365 },
366 "required": ["latitude", "longitude"]
367 }
368 }
369 }
370 };
371 -->recvresult
372 callmacro Insert_value_to_collection %TEST_COLL%
373 '{"_id": "one", "latitude":45, "longitude":54}';
374 -->recvresult
375 callmacro Insert_value_to_collection %TEST_COLL%
376 '{"_id": "two", "wrong":45, "data":54}';
377 -->expecterror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
378 -->recvresult
379 -->callmacro Drop_test_collection
380
381 -->echo
382 -->echo #
383 -->echo # VI.2
384 stmtadmin create_collection {
385 "schema":"xtest",
386 "name": "%TEST_COLL%",
387 "options": {
388 "validation": {
389 "schema": "{
390 \"type\": \"object\",
391 \"properties\": {
392 \"latitude\": {\"type\": \"number\", \"minimum\": -90, \"maximum\": 90},
393 \"longitude\": {\"type\": \"number\", \"minimum\": -180, \"maximum\": 180}
394 },
395 \"required\": [\"latitude\", \"longitude\"]
396 }"
397 }
398 }
399 };
400 -->recvresult
401 callmacro Insert_value_to_collection %TEST_COLL%
402 '{"_id": "one", "latitude":45, "longitude":54}';
403 -->recvresult
404 callmacro Insert_value_to_collection %TEST_COLL%
405 '{"_id": "two", "wrong":45, "data":54}';
406 -->expecterror ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA
407 -->recvresult
408 -->callmacro Drop_test_collection
409
410 EOF
411
412 --let $xtest_file_2= $MYSQL_TMP_DIR/admin_ensure_collection_validation_custom.xpl
413 --write_file $xtest_file_2
414
415 -->echo
416 -->echo
417 -->echo ## I. Check that validation schema do not affect how ensure_collection
418 -->echo ## establishes whether to create a collection.
419 -->echo #
420 -->echo # 1. Try to create two collections with same name and identical
421 -->echo # validation schema.
422 -->echo # 2. Try to create two collections with same name and different
423 -->echo # validation schema.
424 -->echo # 3. Try to create two collections with same name, one containing
425 -->echo # custom validation schema and the next without a validation schema.
426 -->echo # 4. Try to create two collections with different name and identical
427 -->echo # validation schema.
428 -->echo # 5. Try to create two collections with different name and different
429 -->echo # validation schema.
430
431 -->echo
432 -->echo #
433 -->echo # I.1
434 stmtadmin ensure_collection {"schema": "xtest", "name": "test_coll", "options": {
435 "validation": {
436 "schema": {"description":"bar"}
437 }
438 }};
439 -->recvresult
440 stmtadmin ensure_collection {"schema": "xtest", "name": "test_coll", "options": {
441 "validation": {
442 "schema": {"description":"bar"}
443 }
444 }};
445 -->recvresult
446 -->noquiet
447 -->stmtsql show create table xtest.test_coll
448 -->recvresult
449 -->quiet
450 -->stmtsql DROP TABLE IF EXISTS xtest.test_coll
451 -->recvresult
452
453 -->echo
454 -->echo #
455 -->echo # I.2
456 stmtadmin ensure_collection {"schema": "xtest", "name": "test_coll", "options": {
457 "validation": {
458 "schema": {"description":"baz"}
459 }
460 }};
461 -->recvresult
462 stmtadmin ensure_collection {"schema": "xtest", "name": "test_coll", "options": {
463 "validation": {
464 "schema": {"description":"foo"}
465 }
466 }};
467 -->recvresult
468 -->noquiet
469 -->stmtsql show create table xtest.test_coll
470 -->recvresult
471 -->quiet
472 -->stmtsql DROP TABLE IF EXISTS xtest.test_coll
473 -->recvresult
474
475 -->echo
476 -->echo #
477 -->echo # I.3
478 stmtadmin ensure_collection {"schema": "xtest", "name": "test_coll", "options": {
479 "validation": {
480 "schema": {"description":"custom schema"}
481 }
482 }};
483 -->recvresult
484 -->stmtsql show create table xtest.test_coll
485 -->recvresult
486 -->stmtadmin ensure_collection {"schema": "xtest", "name": "test_coll"}
487 -->recvresult
488 -->stmtsql show create table xtest.test_coll
489 -->recvresult
490 -->stmtsql DROP TABLE IF EXISTS xtest.test_coll
491 -->recvresult
492
493 -->echo
494 -->echo #
495 -->echo # I.4
496 stmtadmin ensure_collection {"schema": "xtest", "name": "test_coll", "options": {
497 "validation": {
498 "schema": {"type":"object"}
499 }
500 }};
501 -->recvresult
502 stmtadmin ensure_collection {"schema": "xtest", "name": "foo_bar", "options": {
503 "validation": {
504 "schema": {"type":"object"}
505 }
506 }};
507 -->recvresult
508 -->stmtsql DROP TABLE IF EXISTS xtest.test_coll
509 -->recvresult
510 -->stmtsql DROP TABLE IF EXISTS xtest.foo_bar
511 -->recvresult
512
513 -->echo
514 -->echo #
515 -->echo # I.5
516 stmtadmin ensure_collection {"schema": "xtest", "name": "test_coll", "options": {
517 "validation": {
518 "schema": {"type":"object"}
519 }
520 }};
521 -->recvresult
522 stmtadmin ensure_collection {"schema": "xtest", "name": "foo_bar", "options": {
523 "validation": {
524 "schema": {"description":"foo"}
525 }
526 }};
527 -->recvresult
528 -->stmtsql DROP TABLE IF EXISTS xtest.test_coll
529 -->recvresult
530 -->stmtsql DROP TABLE IF EXISTS xtest.foo_bar
531 -->recvresult
532
533 EOF
534
535 --let $command=create_collection
536 --exec $MYSQLXTEST -ux_root --password='' --file=$xtest_file -vCOMMAND=$command 2>&1
537
538 --let $command=ensure_collection
539 --exec $MYSQLXTEST -ux_root --password='' --file=$xtest_file -vCOMMAND=$command 2>&1
540
541 --let $command=ensure_collection
542 --exec $MYSQLXTEST -ux_root --password='' --file=$xtest_file_2 -vCOMMAND=$command 2>&1
543
544 ## Cleanup
545 --source ../include/xplugin_cleanup.inc