Debian Codegraph @

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

raw
1 ## Test validation errors when doing operations on collections
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;
9
10 --let $xtest_file= $MYSQL_TMP_DIR/validation_errors.xpl
11 --write_file $xtest_file
12 -->import validation_schema.macro
13 -->quiet
14
15 varlet %BASE_SCHEMA% {"type": "object", "properties":
16 {"size": {"type": "number", "minimum": 0, "maximum": 1000}},
17 "required": ["size"]};
18
19 -->macro Create_and_fill_test_collection
20 -->callmacro Create_coll_with_validation test_coll %BASE_SCHEMA% strict
21 -->callmacro Insert_value_to_collection test_coll '{"_id": "one", "size": 10}'
22 -->recvresult
23 -->callmacro Insert_value_to_collection test_coll '{"_id": "two", "size": 20}'
24 -->recvresult
25 -->callmacro Insert_value_to_collection test_coll '{"_id": "three", "size": 30}'
26 -->recvresult
27 -->endmacro
28
29 -->macro Assert_validation_error %REQUIREMENT%
30 recvmessage Mysqlx.Error {
31 severity: ERROR
32 code: 5180
33 msg: "Document is not valid according to the schema assigned to collection. The JSON document location \'#/size\' failed requirement \'%REQUIREMENT%\' at JSON Schema location \'#/properties/size\'."
34 sql_state: "HY000"
35 };
36 -->endmacro
37
38 -->echo
39 -->echo
40 -->echo ## I. Check validation errors on collection insert.
41 -->echo #
42 -->echo # 1. Insert one invalid value to an empty collection.
43 -->echo # 2. Insert one invalid value to a non-empty collection.
44 -->echo # 3. Insert multiple values where one is invalid.
45 -->echo # 4. Insert multiple invalid values.
46 -->echo
47 -->echo ## II. Check validation errors on collection update.
48 -->echo # 1. Update one element in a collection.
49 -->echo # 2. Update multiple elements in a collection.
50 -->echo
51 -->echo ## III. Check validation errors on schema enable.
52 -->echo # 1. Enable schema for collection with one element not matching the
53 -->echo # schema.
54 -->echo # 2. Enable schema for collection with multiple elements not matching
55 -->echo # the schema.
56 -->echo
57 -->echo ## IV. Check validation errors on schema update.
58 -->echo # 1. Update schema for collection with one element not matching the
59 -->echo # new schema.
60 -->echo # 2. Update schema for collection with multiple elements not matching
61 -->echo # the new schema.
62
63 -->echo
64 -->echo #
65 -->echo # I.1
66 -->callmacro Create_coll_with_validation test_coll %BASE_SCHEMA% strict
67 -->callmacro Insert_value_to_collection test_coll '{"_id": "one", "size": 1234}'
68 -->callmacro Assert_validation_error maximum
69 -->callmacro Drop_collection test_coll
70
71 -->echo
72 -->echo #
73 -->echo # I.2
74 -->callmacro Create_and_fill_test_collection
75 -->callmacro Insert_value_to_collection test_coll '{"_id": "four", "size": -1}'
76 -->callmacro Assert_validation_error minimum
77 -->callmacro Drop_collection test_coll
78
79 -->echo
80 -->echo #
81 -->echo # I.3
82 -->callmacro Create_coll_with_validation test_coll %BASE_SCHEMA% strict
83 Mysqlx.Crud.Insert {
84 collection {
85 name: "test_coll"
86 schema: "xtest"
87 }
88 data_model: DOCUMENT
89 row {
90 field {
91 type: LITERAL
92 literal {
93 type: V_STRING
94 v_string {
95 value: '{"_id": "one", "size": 34}'
96 }
97 }
98 }
99 }
100 row {
101 field {
102 type: LITERAL
103 literal {
104 type: V_STRING
105 v_string {
106 value: '{"_id": "two", "size": 72}'
107 }
108 }
109 }
110 }
111 row {
112 field {
113 type: LITERAL
114 literal {
115 type: V_STRING
116 v_string {
117 value: '{"_id": "x", "size": -2}'
118 }
119 }
120 }
121 }
122 row {
123 field {
124 type: LITERAL
125 literal {
126 type: V_STRING
127 v_string {
128 value: '{"_id": "four", "size": 172}'
129 }
130 }
131 }
132 }
133 }
134 -->callmacro Assert_validation_error minimum
135 -->callmacro Drop_collection test_coll
136
137 -->echo
138 -->echo #
139 -->echo # I.4
140 -->callmacro Create_coll_with_validation test_coll %BASE_SCHEMA% strict
141 Mysqlx.Crud.Insert {
142 collection {
143 name: "test_coll"
144 schema: "xtest"
145 }
146 data_model: DOCUMENT
147 row {
148 field {
149 type: LITERAL
150 literal {
151 type: V_STRING
152 v_string {
153 value: '{"_id": "one", "size": 34}'
154 }
155 }
156 }
157 }
158 row {
159 field {
160 type: LITERAL
161 literal {
162 type: V_STRING
163 v_string {
164 value: '{"_id": "x", "size": 1072}'
165 }
166 }
167 }
168 }
169 row {
170 field {
171 type: LITERAL
172 literal {
173 type: V_STRING
174 v_string {
175 value: '{"_id": "y", "size": -2}'
176 }
177 }
178 }
179 }
180 row {
181 field {
182 type: LITERAL
183 literal {
184 type: V_STRING
185 v_string {
186 value: '{"_id": "z", "size": 1072}'
187 }
188 }
189 }
190 }
191 }
192 -->callmacro Assert_validation_error maximum
193 -->callmacro Drop_collection test_coll
194
195 -->echo
196 -->echo #
197 -->echo # II.1
198 -->callmacro Create_and_fill_test_collection
199 callmacro Update_item test_coll
200 size
201 {type: V_SINT v_signed_int: 20}
202 {type: V_SINT v_signed_int: -20};
203 -->callmacro Assert_validation_error minimum
204 -->callmacro Drop_collection test_coll
205
206 -->echo
207 -->echo #
208 -->echo # II.2
209 -->callmacro Create_and_fill_test_collection
210 Mysqlx.Crud.Update {
211 collection { name: "test_coll" schema: "xtest"}
212 data_model: DOCUMENT
213 criteria {
214 type: OPERATOR
215 operator {
216 name: ">"
217 param {
218 type: IDENT
219 identifier {
220 document_path {
221 type: MEMBER
222 value: "size"
223 }
224 }
225 }
226 param {
227 type: LITERAL
228 literal {type: V_SINT v_signed_int: 0}
229 }
230 }
231 }
232 operation {
233 source {
234 document_path {type: MEMBER value: 'size'}
235 }
236 operation: ITEM_SET
237 value: {
238 type: LITERAL literal {type: V_SINT v_signed_int: -1}
239 }
240 }
241 }
242 -->callmacro Assert_validation_error minimum
243 -->callmacro Drop_collection test_coll
244
245 -->echo
246 -->echo #
247 -->echo # III.1
248 -->callmacro Create_coll_with_validation test_coll %BASE_SCHEMA% off
249 -->callmacro Insert_value_to_collection test_coll '{"_id": "one", "size": 10}'
250 -->recvresult
251 -->callmacro Insert_value_to_collection test_coll '{"_id": "two", "size": -1}'
252 -->recvresult
253 -->callmacro Insert_value_to_collection test_coll '{"_id": "three", "size": 30}'
254 -->recvresult
255 -->callmacro Modify_level test_coll strict
256 -->callmacro Assert_validation_error minimum
257 -->callmacro Drop_collection test_coll
258
259 -->echo
260 -->echo #
261 -->echo # III.2
262 -->callmacro Create_coll_with_validation test_coll %BASE_SCHEMA% off
263 -->callmacro Insert_value_to_collection test_coll '{"_id": "one", "size": 1200}'
264 -->recvresult
265 -->callmacro Insert_value_to_collection test_coll '{"_id": "two", "size": -1}'
266 -->recvresult
267 -->callmacro Insert_value_to_collection test_coll '{"_id": "three", "size": -1}'
268 -->recvresult
269 -->callmacro Modify_level test_coll strict
270 -->callmacro Assert_validation_error maximum
271 -->callmacro Drop_collection test_coll
272
273 -->echo
274 -->echo #
275 -->echo # IV.1
276 -->callmacro Create_and_fill_test_collection
277 varlet %SCHEMA% {"type": "object", "properties":
278 {"size": {"type": "number", "minimum": 25, "maximum": 1000}},
279 "required": ["size"]};
280 stmtadmin modify_collection_options {"schema": "xtest", "name": "test_coll",
281 "options": {
282 "validation": {
283 "schema": %SCHEMA%,
284 "level": "strict"
285 }
286 }
287 };
288 -->callmacro Assert_validation_error minimum
289 -->callmacro Drop_collection test_coll
290
291 -->echo
292 -->echo #
293 -->echo # IV.2
294 -->callmacro Create_and_fill_test_collection
295 varlet %SCHEMA% {"type": "object", "properties":
296 {"size": {"type": "number", "minimum": 100, "maximum": 1000}},
297 "required": ["size"]};
298 stmtadmin modify_collection_options {"schema": "xtest", "name": "test_coll",
299 "options": {
300 "validation": {
301 "schema": %SCHEMA%,
302 "level": "strict"
303 }
304 }
305 };
306 -->callmacro Assert_validation_error minimum
307 -->callmacro Drop_collection test_coll
308
309 -->noquiet
310
311 EOF
312
313 --exec $MYSQLXTEST -ux_root --password='' --file=$xtest_file 2>&1
314
315 ## Cleanup
316 --source ../include/xplugin_cleanup.inc