Files
dolt/bats/sql-shell.bats
Vinai Rachakonda cf037558dd Write to root on every loop of sql shell. (#1215)
This pr fixes a problem where autocommit was not turned on for every single iteration of the shell loop.
2021-01-19 16:07:38 -05:00

80 lines
2.2 KiB
Bash

#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
c2 BIGINT COMMENT 'tag:2',
c3 BIGINT COMMENT 'tag:3',
c4 BIGINT COMMENT 'tag:4',
c5 BIGINT COMMENT 'tag:5',
PRIMARY KEY (pk)
);
SQL
}
teardown() {
teardown_common
}
@test "run a query in sql shell" {
skiponwindows "Works on Windows command prompt but not the WSL terminal used during bats"
run bash -c "echo 'select * from test;' | dolt sql"
[ $status -eq 0 ]
[[ "$output" =~ "pk" ]] || false
}
@test "sql shell writes to disk after every iteration (autocommit)" {
skiponwindows "Need to install expect and make this script work on windows."
run $BATS_TEST_DIRNAME/sql-shell.expect
echo "$output"
# 2 tables are created. 1 from above and 1 in the expect file.
[[ "$output" =~ "+-------------+" ]] || false
[[ "$output" =~ "| Table |" ]] || false
[[ "$output" =~ "+-------------+" ]] || false
[[ "$output" =~ "| test |" ]] || false
[[ "$output" =~ "| test_expect |" ]] || false
[[ "$output" =~ "+-------------+" ]] || false
}
@test "bad sql in sql shell should error" {
run dolt sql <<< "This is bad sql"
[ $status -eq 1 ]
run dolt sql <<< "select * from test; This is bad sql; insert into test (pk) values (666); select * from test;"
[ $status -eq 1 ]
[[ ! "$output" =~ "666" ]] || false
}
@test "inline query with missing -q flag should error" {
run dolt sql "SELECT * FROM test;"
[ $status -eq 1 ]
[[ "$output" =~ "Invalid Argument:" ]] || false
}
@test "validate string formatting" {
dolt sql <<SQL
CREATE TABLE test2 (
str varchar(256) NOT NULL,
PRIMARY KEY (str)
);
SQL
TESTSTR='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()){}[]/=?+|,.<>;:_-_%d%s%f'
dolt sql -q "INSERT INTO test2 (str) VALUES ('$TESTSTR')"
run dolt sql -q "SELECT * FROM test2"
[ $status -eq 0 ]
[[ "$output" =~ "$TESTSTR" ]] || false
run dolt sql -q "SELECT * FROM test2" -r csv
[ $status -eq 0 ]
[[ "$output" =~ "$TESTSTR" ]] || false
run dolt sql -q "SELECT * FROM test2" -r json
[ $status -eq 0 ]
[[ "$output" =~ "$TESTSTR" ]] || false
}