Moved some bats tests around, and rewrote the use database tests to actually fail correctly

This commit is contained in:
Zach Musgrave
2023-02-27 15:45:23 -08:00
parent c1e54b1c35
commit 623f83cf27
3 changed files with 115 additions and 65 deletions

View File

@@ -83,6 +83,58 @@ teardown() {
[[ "$output" =~ "+---------------------" ]] || false
}
@test "sql-shell: shell works after failing query" {
skiponwindows "Need to install expect and make this script work on windows."
$BATS_TEST_DIRNAME/sql-works-after-failing-query.expect
}
@test "sql-shell: delimiter" {
skiponwindows "Need to install expect and make this script work on windows."
mkdir doltsql
cd doltsql
dolt init
run $BATS_TEST_DIRNAME/sql-delimiter.expect
[ "$status" -eq "0" ]
[[ ! "$output" =~ "Error" ]] || false
[[ ! "$output" =~ "error" ]] || false
run dolt sql -q "SELECT * FROM test ORDER BY 1" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1" ]] || false
[[ "$output" =~ "0,0" ]] || false
[[ "$output" =~ "1,1" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
run dolt sql -q "SHOW TRIGGERS"
[ "$status" -eq "0" ]
[[ "$output" =~ "SET NEW.v1 = NEW.v1 * 11" ]] || false
cd ..
rm -rf doltsql
}
@test "sql-shell: use databases" {
skiponwindows "Need to install expect and make this script work on windows."
mkdir doltsql
cd doltsql
dolt init
dolt sql -q "create database db1"
dolt sql -q "create database db2"
dolt branch test
run expect $BATS_TEST_DIRNAME/sql-use.expect
echo $output
[ "$status" -eq "0" ]
[[ ! "$output" =~ "Error" ]] || false
[[ ! "$output" =~ "error" ]] || false
cd ..
rm -rf doltsql
}
@test "sql-shell: default datadir, doltcfg, and privs" {
# remove config files
rm -rf .doltcfg

View File

@@ -1,41 +1,62 @@
#!/usr/bin/expect
#!/usr/bin/expect
set timeout 1000
set timeout 3
spawn dolt sql
# This script uses undefined variables in the failure case so that
# errors output includes the line of the failed test expectation
expect {
"doltsql> " { send "use `doltsql/test`;\r"; }
timeout { exit 1; }
"*doltsql> " { send -- "use `doltsql/test`;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"doltsql/test> " { send "show tables;\r"; }
timeout { exit 1; }
"*doltsql/test> " { send -- "show tables;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"doltsql/test> " { send "use information_schema;\r"; }
timeout { exit 1; }
"*doltsql/test> " { send -- "use information_schema;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"information_schema> " { send "show tables;\r"; }
timeout { exit 1; }
"*information_schema> " { send -- "show tables;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"information_schema> " { send "CREATE DATABASE mydb ;\r"; }
timeout { exit 1; }
"*information_schema> " { send -- "CREATE DATABASE mydb;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"information_schema> " { send "use mydb ;\r"; }
timeout { exit 1; }
"*information_schema> " { send -- "use db1;\r"; }
timeout { puts "$TESTFAILURE"; }
}
# TODO: The failed keyword seems to be triggering the connection_control_failed_login_attempts info_schema table. Not clear why the output
# of this table is comming all the way down to this command.
expect {
"mydb> " { send "exit ;\r"; }
timeout { exit 1; }
"*db1> " { send -- "select database();\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"|*db1*|*db1>" { send -- "use db2;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"*db2> " { send -- "select database();\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"|.*db2.*|.*\rdb2>" { send -- "use mydb;\r"; }
timeout { puts "$TESTFAILURE"; }
}
expect {
"mydb> " { send -- "exit ;\r"; }
timeout { puts "$TESTFAILURE"; }
}

View File

@@ -1406,6 +1406,30 @@ SQL
[[ "$output" =~ "exists" ]] || false
}
@test "sql: use database with multiple dbs" {
dolt sql -q "create database db1"
dolt sql -q "create database db2"
dolt sql <<SQL
use db1;
create table t1 (a int primary key);
insert into t1 values (10);
use db2;
create table t2 (a int primary key);
insert into t2 values (20);
SQL
cd db1
run dolt sql -q "select * from t1"
[ "$status" -eq 0 ]
[[ "$output" =~ "10" ]] || false
cd ../db2
run dolt sql -q "select * from t2"
[ "$status" -eq 0 ]
[[ "$output" =~ "20" ]] || false
}
@test "sql: dolt_show_branch_databases" {
mkdir new && cd new
@@ -2130,53 +2154,6 @@ SQL
[[ "$output" =~ "0" ]] || false
}
@test "sql: shell works after failing query" {
skiponwindows "Need to install expect and make this script work on windows."
$BATS_TEST_DIRNAME/sql-works-after-failing-query.expect
}
@test "sql: shell delimiter" {
skiponwindows "Need to install expect and make this script work on windows."
mkdir doltsql
cd doltsql
dolt init
run $BATS_TEST_DIRNAME/sql-delimiter.expect
[ "$status" -eq "0" ]
[[ ! "$output" =~ "Error" ]] || false
[[ ! "$output" =~ "error" ]] || false
run dolt sql -q "SELECT * FROM test ORDER BY 1" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1" ]] || false
[[ "$output" =~ "0,0" ]] || false
[[ "$output" =~ "1,1" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
run dolt sql -q "SHOW TRIGGERS"
[ "$status" -eq "0" ]
[[ "$output" =~ "SET NEW.v1 = NEW.v1 * 11" ]] || false
cd ..
rm -rf doltsql
}
@test "sql: use syntax on shell" {
skiponwindows "Need to install expect and make this script work on windows."
mkdir doltsql
cd doltsql
dolt init
dolt branch test
run expect $BATS_TEST_DIRNAME/sql-use.expect
[ "$status" -eq "0" ]
[[ ! "$output" =~ "Error" ]] || false
[[ ! "$output" =~ "error" ]] || false
cd ..
rm -rf doltsql
}
@test "sql: batch delimiter" {
dolt sql <<SQL