From ed2c00232b739ac8f2af801ed704a61b52013d04 Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Tue, 21 Jun 2022 13:27:32 +0300 Subject: [PATCH] [#2438] set @json_supported for a MySQL connection --- src/bin/admin/tests/mysql_tests.sh.in | 144 ++++++++++++++++++++++---- 1 file changed, 123 insertions(+), 21 deletions(-) diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index fceb7f9beb..0a01c2dc3b 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -408,16 +408,28 @@ mysql_upgrade_13_to_14_test() { # -- lease counting tests -- - # Clean up. + # Check that @json_supported is NULL by default. + query='SELECT @json_supported' run_command \ - mysql_execute 'DELETE FROM lease4; DELETE FROM lease6;' - assert_eq 0 "${EXIT_CODE}" 'DELETE FROM lease' + mysql_execute "${query}" + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "NULL" "${OUTPUT}" "${query}: expected output %s, returned %s" - # Populate the lease tables. + # Clean up. + query='DELETE FROM lease4; DELETE FROM lease6;' + run_command \ + mysql_execute "${query}" + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "" "${OUTPUT}" "${query}: expected output %s, returned %s" + + # Populate the lease tables. Also check that @json_supported is NULL at + # first, and then it is set after inserting leases. run_command \ mysql_execute " + SELECT @json_supported; INSERT INTO lease4 (address, subnet_id, state, user_context) VALUES (100,1,0, '{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }'); + SELECT @json_supported; INSERT INTO lease4 (address, subnet_id, state, user_context) VALUES (101,1,1, '{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }'); INSERT INTO lease4 (address, subnet_id, state, user_context) VALUES (102,1,2, @@ -444,8 +456,17 @@ mysql_upgrade_13_to_14_test() { '{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }'); INSERT INTO lease6 (address, lease_type, subnet_id, state, user_context) VALUES (107,2,1,1, '{\"ISC\": {\"client-classes\": [\"ALL\", \"KNOWN\", \"bar\", \"foo\"] } }'); + SELECT @json_supported; " assert_eq 0 "${EXIT_CODE}" 'INSERT INTO leases when upgrading from 13 to 14 failed. expected %d, returned %d' + one_line=$(printf '%s' "${OUTPUT}" | tr '\n' ' ') + json_supported=$(printf '%s' "${one_line}" | grep -Eo '[0-1]$') || true + if test "${json_supported}" != 0 && test "${json_supported}" != 1; then + assert_str_eq '[01]' "${json_supported}" "INSERT INTO leases when upgrading from 13 to 14 does not set @json_supported. expected '[01]', returned '${json_supported}'" + fi + if ! printf '%s' "${one_line}" | grep -E "NULL ${json_supported} ${json_supported}" > /dev/null; then + assert_str_eq 'NULL [01] [01]' "${one_line}" "INSERT INTO leases when upgrading from 13 to 14 does not set @json_supported. expected 'NULL [01] [01]', returned '${one_line}'" + fi for v in 4 6; do if test "${v}" = 4; then @@ -459,68 +480,148 @@ mysql_upgrade_13_to_14_test() { run_command \ mysql_execute "${query}" assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" - assert_str_eq 2 "${OUTPUT}" "${query}: expected output %s, returned %s" + if test "${json_supported}" = 1; then + assert_str_eq 2 "${OUTPUT}" "${query}: expected output %s, returned %s" + else + assert_str_eq 0 "${OUTPUT}" "${query}: expected output %s, returned %s" + fi # -- Verify some calls to checkLeaseXLimits(). -- + query="SELECT checkLease${v}Limits('');" + run_command \ + mysql_execute "${query}" + # Should fail with ERROR 4037 (HY000): Unexpected end of JSON text in argument 1 to function 'json_extract' + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" + + query="SELECT checkLease${v}Limits('{}');" + run_command \ + mysql_execute "${query}" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + fi + assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" + query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 1 } ] } } }');" run_command \ mysql_execute "${query}" - assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" - assert_str_eq "{\"limit-type\": \"client-class\", \"name\": \"foo\", \"lease-type\": \"${lease_type}\", \"limit\": 1, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "{\"limit-type\": \"client-class\", \"name\": \"foo\", \"lease-type\": \"${lease_type}\", \"limit\": 1, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" + fi query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"subnet\": { \"id\": 1, \"address-limit\": 1 } } } }');" run_command \ mysql_execute "${query}" - assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" - assert_str_eq "{\"limit-type\": \"subnet\", \"id\": 1, \"lease-type\": \"${lease_type}\", \"limit\": 1, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "{\"limit-type\": \"subnet\", \"id\": 1, \"lease-type\": \"${lease_type}\", \"limit\": 1, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" + fi query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 2 } ] } } }');" run_command \ mysql_execute "${query}" assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" - assert_str_eq "{\"limit-type\": \"client-class\", \"name\": \"foo\", \"lease-type\": \"${lease_type}\", \"limit\": 2, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "{\"limit-type\": \"client-class\", \"name\": \"foo\", \"lease-type\": \"${lease_type}\", \"limit\": 2, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" + fi query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"subnet\": { \"id\": 1, \"address-limit\": 2 } } } }');" run_command \ mysql_execute "${query}" - assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" - assert_str_eq "{\"limit-type\": \"subnet\", \"id\": 1, \"lease-type\": \"${lease_type}\", \"limit\": 2, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "{\"limit-type\": \"subnet\", \"id\": 1, \"lease-type\": \"${lease_type}\", \"limit\": 2, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" + fi query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 4 } ] } } }');" run_command \ mysql_execute "${query}" - assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + fi assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"subnet\": { \"id\": 1, \"address-limit\": 4 } } } }');" run_command \ mysql_execute "${query}" - assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + fi assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 1 }, { \"name\": \"bar\", \"address-limit\": 1 } ], \"subnet\": { \"id\": 1, \"address-limit\": 1 } } } }');" run_command \ mysql_execute "${query}" - assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" - assert_str_eq "{\"limit-type\": \"client-class\", \"name\": \"foo\", \"lease-type\": \"${lease_type}\", \"limit\": 1, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "{\"limit-type\": \"client-class\", \"name\": \"foo\", \"lease-type\": \"${lease_type}\", \"limit\": 1, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" + fi query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 2 }, { \"name\": \"bar\", \"address-limit\": 4 } ], \"subnet\": { \"id\": 1, \"address-limit\": 4 } } } }');" run_command \ mysql_execute "${query}" - assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" - assert_str_eq "{\"limit-type\": \"client-class\", \"name\": \"foo\", \"lease-type\": \"${lease_type}\", \"limit\": 2, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "{\"limit-type\": \"client-class\", \"name\": \"foo\", \"lease-type\": \"${lease_type}\", \"limit\": 2, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" + fi query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 4 }, { \"name\": \"bar\", \"address-limit\": 4 } ], \"subnet\": { \"id\": 1, \"address-limit\": 2 } } } }');" run_command \ mysql_execute "${query}" - assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" - assert_str_eq "{\"limit-type\": \"subnet\", \"id\": 1, \"lease-type\": \"${lease_type}\", \"limit\": 2, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "{\"limit-type\": \"subnet\", \"id\": 1, \"lease-type\": \"${lease_type}\", \"limit\": 2, \"count\": 2}" "${OUTPUT}" "${query}: expected output %s, returned %s" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" + fi query="SELECT checkLease${v}Limits('{ \"ISC\": { \"limits\": { \"client-classes\": [ { \"name\": \"foo\", \"address-limit\": 4 }, { \"name\": \"bar\", \"address-limit\": 4 } ], \"subnet\": { \"id\": 1, \"address-limit\": 4 } } } }');" run_command \ mysql_execute "${query}" - assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + if test "${json_supported}" = 1; then + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + else + # Should fail with ERROR 1305 (42000) at line 1: FUNCTION keatest.JSON_EXTRACT does not exist + assert_eq 1 "${EXIT_CODE}" "${query}: expected %d, returned %d" + fi assert_str_eq '' "${OUTPUT}" "${query}: expected output %s, returned %s" done @@ -529,6 +630,7 @@ mysql_upgrade_13_to_14_test() { run_command \ mysql_execute "${query}" assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq "" "${OUTPUT}" "${query}: expected output %s, returned %s" } mysql_upgrade_test() {