From a6278667b74ff4d24da01cf8ebf3d54780e87307 Mon Sep 17 00:00:00 2001 From: jennifersp <44716627+jennifersp@users.noreply.github.com> Date: Fri, 27 Jan 2023 08:48:08 -0800 Subject: [PATCH] add bats tests for information schema tables (#5225) --- integration-tests/bats/create-views.bats | 5 + integration-tests/bats/foreign-keys.bats | 25 ++ .../bats/sql-charsets-collations.bats | 28 +- .../bats/sql-check-constraints.bats | 4 + .../bats/sql-create-database.bats | 6 + integration-tests/bats/sql-privs.bats | 21 +- integration-tests/bats/sql-spatial-types.bats | 4 + integration-tests/bats/sql.bats | 36 +++ integration-tests/bats/triggers.bats | 4 + integration-tests/bats/types.bats | 252 ++++++++++++++++++ 10 files changed, 373 insertions(+), 12 deletions(-) diff --git a/integration-tests/bats/create-views.bats b/integration-tests/bats/create-views.bats index c8fe32154b..42580205ef 100644 --- a/integration-tests/bats/create-views.bats +++ b/integration-tests/bats/create-views.bats @@ -107,6 +107,11 @@ SQL [[ "${lines[4]}" =~ ' 1 ' ]] || false [[ "${lines[5]}" =~ ' 2 ' ]] || false [[ "${lines[6]}" =~ ' 3 ' ]] || false + + # check information_schema.VIEWS table + # TODO: view_definition should be "select `mybin`.`my_users`.`id` AS `id` from `mybin`.`my_users` order by `mybin`.`my_users`.`id`" + run dolt sql -q "select * from information_schema.VIEWS;" -r csv + [[ "$output" =~ "def,dolt_repo_$$,my_users_view,select id from my_users order by id asc,NONE,YES,root@localhost,DEFINER,utf8mb4,utf8mb4_0900_bin" ]] || false } @test "create-views: view referencing table selects values inserted after it was created" { diff --git a/integration-tests/bats/foreign-keys.bats b/integration-tests/bats/foreign-keys.bats index 72e4ce7ff9..93d9e7be09 100644 --- a/integration-tests/bats/foreign-keys.bats +++ b/integration-tests/bats/foreign-keys.bats @@ -129,6 +129,27 @@ SQL dolt sql -q 'select * from objects' dolt add . dolt commit -m 'update 1' + + # check information_schema.CHECK_CONSTRAINTS table + run dolt sql -q "select constraint_name, table_name, column_name, ordinal_position, position_in_unique_constraint, referenced_table_name, referenced_column_name from information_schema.KEY_COLUMN_USAGE;" -r csv + [[ "$output" =~ "PRIMARY,colors,id,1,,," ]] || false + [[ "$output" =~ "PRIMARY,materials,id,1,,," ]] || false + [[ "$output" =~ "jb6i5huc,materials,color,1,1,colors,color" ]] || false + [[ "$output" =~ "PRIMARY,objects,id,1,,," ]] || false + [[ "$output" =~ "i5lsjmoo,objects,color,1,1,materials,color" ]] || false + [[ "$output" =~ "i5lsjmoo,objects,material,2,2,materials,material" ]] || false + [[ "$output" =~ "PRIMARY,child,id,1,,," ]] || false + [[ "$output" =~ "PRIMARY,parent,id,1,,," ]] || false + + # check information_schema.TABLE_CONSTRAINTS table + run dolt sql -q "select * from information_schema.TABLE_CONSTRAINTS where table_name = 'materials';" -r csv + [[ "$output" =~ "def,dolt_repo_$$,PRIMARY,dolt_repo_$$,materials,PRIMARY KEY,YES" ]] || false + [[ "$output" =~ "def,dolt_repo_$$,jb6i5huc,dolt_repo_$$,materials,FOREIGN KEY,YES" ]] || false + + # check information_schema.TABLE_CONSTRAINTS_EXTENSIONS table + run dolt sql -q "select constraint_name from information_schema.TABLE_CONSTRAINTS_EXTENSIONS where table_name = 'materials';" -r csv + [[ "$output" =~ "PRIMARY" ]] || false + [[ "$output" =~ "color_mat_index" ]] || false } @test "foreign-keys: ALTER TABLE Single Named FOREIGN KEY" { @@ -732,6 +753,10 @@ SQL run dolt sql -q "DELETE FROM one;" [ "$status" -eq "1" ] [[ "$output" =~ "violation" ]] || false + + # check information_schema.REFERENTIAL_CONSTRAINTS table + run dolt sql -q "select constraint_name, unique_constraint_name, match_option, update_rule, delete_rule, table_name, referenced_table_name from information_schema.REFERENTIAL_CONSTRAINTS;" -r csv + [[ "$output" =~ "fk_name_1,,NONE,RESTRICT,RESTRICT,two,one" ]] || false } @test "foreign-keys: SQL no reference options" { diff --git a/integration-tests/bats/sql-charsets-collations.bats b/integration-tests/bats/sql-charsets-collations.bats index c2acac923e..dee5e06d50 100644 --- a/integration-tests/bats/sql-charsets-collations.bats +++ b/integration-tests/bats/sql-charsets-collations.bats @@ -20,19 +20,27 @@ teardown() { } @test "sql-charsets-collations: define charset and collation on a column" { - dolt sql -q "create table german1 (c char(10) CHARACTER SET latin1 COLLATE latin1_german1_ci)" - run dolt sql -q "show create table german1"; - [ $status -eq 0 ] - [[ $output =~ "CHARACTER SET latin1" ]] || false - [[ $output =~ "COLLATE latin1_german1_ci" ]] || false + dolt sql -q "create table german1 (c char(10) CHARACTER SET latin1 COLLATE latin1_german1_ci)" + run dolt sql -q "show create table german1"; + [ $status -eq 0 ] + [[ $output =~ "CHARACTER SET latin1" ]] || false + [[ $output =~ "COLLATE latin1_german1_ci" ]] || false + + # check information_schema.COLUMNS table + run dolt sql -q "select table_name, column_name, character_set_name, collation_name from information_schema.COLUMNS;" -r csv + [[ "$output" =~ "german1,c,latin1,latin1_german1_ci" ]] || false } @test "sql-charsets-collations: define charset and collation on a table" { - dolt sql -q "create table german1 (c char(10)) CHARACTER SET latin1 COLLATE latin1_german1_ci" - run dolt sql -q "show create table german1"; - [ $status -eq 0 ] - [[ $output =~ "CHARACTER SET latin1" ]] || false - [[ $output =~ "COLLATE latin1_german1_ci" ]] || false + dolt sql -q "create table german1 (c char(10)) CHARACTER SET latin1 COLLATE latin1_german1_ci" + run dolt sql -q "show create table german1"; + [ $status -eq 0 ] + [[ $output =~ "CHARACTER SET latin1" ]] || false + [[ $output =~ "COLLATE latin1_german1_ci" ]] || false + + # check information_schema.TABLES table + run dolt sql -q "select table_name, table_type, table_collation from information_schema.TABLES where table_name = 'german1';" -r csv + [[ "$output" =~ "german1,BASE TABLE,latin1_german1_ci" ]] || false } @test "sql-charsets-collations: define charset and collation on a database" { diff --git a/integration-tests/bats/sql-check-constraints.bats b/integration-tests/bats/sql-check-constraints.bats index e62e6aab3a..425b7e9f35 100644 --- a/integration-tests/bats/sql-check-constraints.bats +++ b/integration-tests/bats/sql-check-constraints.bats @@ -78,6 +78,10 @@ SQL echo $output [[ "$output" =~ "CHECK" ]] || false [[ "$output" =~ "`c1` > 3" ]] || false + + # check information_schema.CHECK_CONSTRAINTS table + run dolt sql -q "select constraint_catalog, constraint_name, check_clause from information_schema.CHECK_CONSTRAINTS;" -r csv + [[ "$output" =~ "def,chk_eq3jn5ra,(c1 > 3)" ]] || false } @test "sql-check-constraints: check constraints survive renaming a column" { diff --git a/integration-tests/bats/sql-create-database.bats b/integration-tests/bats/sql-create-database.bats index 240ecfd94f..f575e738ba 100644 --- a/integration-tests/bats/sql-create-database.bats +++ b/integration-tests/bats/sql-create-database.bats @@ -313,4 +313,10 @@ SQL [[ "$output" =~ "dolt_repo_$$" ]] || false [[ "$output" =~ "information_schema" ]] || false [[ "$output" =~ "metabase" ]] || false + + cd metabase + # check information_schema.SCHEMATA table + run dolt sql -q "select * from information_schema.SCHEMATA where schema_name = 'metabase';" -r csv + [[ "$output" =~ "def,metabase,utf8mb4,utf8mb4_unicode_ci,,NO" ]] || false + cd .. } diff --git a/integration-tests/bats/sql-privs.bats b/integration-tests/bats/sql-privs.bats index e8be4dfb52..9817ebabc7 100644 --- a/integration-tests/bats/sql-privs.bats +++ b/integration-tests/bats/sql-privs.bats @@ -613,7 +613,11 @@ behavior: run dolt sql-client -P $PORT -u dolt --use-db test_db -q "show tables" [ $status -eq 0 ] [[ $output =~ t1 ]] || false - + + # check information_schema.SCHEMA_PRIVILEGES table + run dolt sql-client -P $PORT -u dolt --use-db test_db -q "select * from information_schema.SCHEMA_PRIVILEGES;" + [[ "$output" =~ "| 'test'@'%' | def | test_db | SELECT | NO |" ]] || false + # Revoke works as expected dolt sql-client -P $PORT -u dolt --use-db test_db -q "revoke select on test_db.* from test" run dolt sql-client -P $PORT -u test --use-db test_db -q "show tables" @@ -627,7 +631,20 @@ behavior: [ $status -eq 0 ] [[ $output =~ t1 ]] || false - + # check information_schema.SCHEMA_PRIVILEGES table + run dolt sql-client -P $PORT -u dolt --use-db test_db -q "select * from information_schema.SCHEMA_PRIVILEGES;" + [[ "$output" =~ "| 'test'@'127.0.0.1' | def | test_db | SELECT | NO |" ]] || false + + dolt sql-client -P $PORT -u dolt --use-db test_db -q "grant update on test_db.t1 to test@'127.0.0.1'" + # check information_schema.TABLE_PRIVILEGES table + run dolt sql-client -P $PORT -u dolt --use-db test_db -q "select * from information_schema.TABLE_PRIVILEGES;" + [[ "$output" =~ "| 'test'@'127.0.0.1' | def | test_db | t1 | UPDATE | NO |" ]] || false + + dolt sql-client -P $PORT -u dolt --use-db test_db -q "grant insert on *.* to test@'127.0.0.1'" + # check information_schema.USER_PRIVILEGES table + run dolt sql-client -P $PORT -u test -H 127.0.0.1 --use-db test_db -q "select * from information_schema.USER_PRIVILEGES;" + [[ "$output" =~ "| 'test'@'127.0.0.1' | def | INSERT | NO |" ]] || false + dolt sql-client -P $PORT -u dolt --use-db test_db -q "drop user test@'127.0.0.1'" dolt sql-client -P $PORT -u dolt --use-db test_db -q "create user test@'10.10.10.10'" dolt sql-client -P $PORT -u dolt --use-db test_db -q "grant select on test_db.* to test@'10.10.10.10'" diff --git a/integration-tests/bats/sql-spatial-types.bats b/integration-tests/bats/sql-spatial-types.bats index 3fa3c9cf12..b30054cf91 100644 --- a/integration-tests/bats/sql-spatial-types.bats +++ b/integration-tests/bats/sql-spatial-types.bats @@ -211,6 +211,10 @@ teardown() { run dolt sql -q "SELECT ST_ASWKT(p) FROM pt" [[ ! "$output" =~ "POINT(1 2)" ]] || false + + # check information_schema.ST_GEOMETRY_COLUMNS table + run dolt sql -q "select * from information_schema.ST_GEOMETRY_COLUMNS;" -r csv + [[ "$output" =~ "pt,p,\"\",0,point" ]] || false } @test "sql-spatial-types: SRID defined in column definition in ALTER TABLE" { diff --git a/integration-tests/bats/sql.bats b/integration-tests/bats/sql.bats index f99638dbf1..b741e84557 100755 --- a/integration-tests/bats/sql.bats +++ b/integration-tests/bats/sql.bats @@ -879,6 +879,22 @@ SQL [[ "$output" =~ foo ]] || false [[ "$output" =~ bar ]] || false [ "${#lines[@]}" -eq 8 ] + + # check information_schema.STATISTICS table + # TODO: caridnality here are all 0's as it's not supported yet + run dolt sql -q "select * from information_schema.STATISTICS;" -r csv + [[ "$output" =~ "has_datetimes,0,dolt_repo_$$,PRIMARY,1,pk,A,0,,,\"\",BTREE,\"\",\"\",YES," ]] || false + [[ "$output" =~ "one_pk,0,dolt_repo_$$,PRIMARY,1,pk,A,0,,,\"\",BTREE,\"\",\"\",YES," ]] || false + [[ "$output" =~ "two_pk,0,dolt_repo_$$,PRIMARY,1,pk1,A,0,,,\"\",BTREE,\"\",\"\",YES," ]] || false + [[ "$output" =~ "two_pk,0,dolt_repo_$$,PRIMARY,2,pk2,A,0,,,\"\",BTREE,\"\",\"\",YES," ]] || false + + skip "ALTER VIEW is unsupported" + # check cardinality on information_schema.STATISTICS table + run dolt sql -q "select table_name, column_name, cardinality from information_schema.STATISTICS;" -r csv + [[ "$output" =~ "has_datetimes,pk,1" ]] || false + [[ "$output" =~ "one_pk,pk,4" ]] || false + [[ "$output" =~ "two_pk,pk1,2" ]] || false + [[ "$output" =~ "two_pk,pk2,4" ]] || false } @test "sql: AS OF queries" { @@ -2400,6 +2416,26 @@ SQL [[ "${#lines[@]}" = "2" ]] || false } +@test "sql: check info_schema routines and parameters tables for stored procedures" { + dolt sql <