Merge remote-tracking branch 'origin/main' into taylor/load-data-tests

This commit is contained in:
Taylor Bantle
2023-06-06 10:01:18 -07:00
29 changed files with 534 additions and 155 deletions
+70
View File
@@ -0,0 +1,70 @@
#! /usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
teardown_common
}
get_staged_tables() {
dolt status | awk '
match($0, /new table:\ */) { print substr($0, RSTART+RLENGTH) }
/Untracked tables:/ { exit }
/Tables with conflicting dolt_ignore patterns:/ { exit }
'
}
get_working_tables() {
dolt status | awk '
BEGIN { working = 0 }
(working == 1) && match($0, /new table:\ */) { print substr($0, RSTART+RLENGTH) }
/Untracked tables:/ { working = 1 }
/Tables with conflicting dolt_ignore patterns:/ { working = 0 }
'
}
@test "add: add dot" {
dolt sql -q "create table testtable (pk int PRIMARY KEY)"
staged=$(get_staged_tables)
working=$(get_working_tables)
[[ ! -z $(echo "$working" | grep "testtable") ]] || false
[[ -z $(echo "$staged" | grep "testtable") ]] || false
dolt add .
staged=$(get_staged_tables)
working=$(get_working_tables)
[[ ! -z $(echo "$staged" | grep "testtable") ]] || false
[[ -z $(echo "$working" | grep "testtable") ]] || false
}
@test "add: add by name." {
dolt sql -q "create table addedTable (pk int PRIMARY KEY)"
dolt sql -q "create table notAddedTable (pk int PRIMARY KEY)"
staged=$(get_staged_tables)
working=$(get_working_tables)
[[ ! -z $(echo "$working" | grep "addedTable") ]] || false
[[ -z $(echo "$staged" | grep "addedTable") ]] || false
[[ ! -z $(echo "$working" | grep "notAddedTable") ]] || false
[[ -z $(echo "$staged" | grep "notAddedTable") ]] || false
dolt add addedTable
staged=$(get_staged_tables)
working=$(get_working_tables)
[[ ! -z $(echo "$staged" | grep "addedTable") ]] || false
[[ -z $(echo "$working" | grep "addedTable") ]] || false
[[ ! -z $(echo "$working" | grep "notAddedTable") ]] || false
[[ -z $(echo "$staged" | grep "notAddedTable") ]] || false
}
+21
View File
@@ -51,4 +51,25 @@ teardown() {
run dolt commit
[ $status -eq 1 ]
[[ "$output" =~ "Failed to open commit editor" ]] || false
}
@test "commit: --skip-empty correctly skips committing when no changes are staged" {
dolt sql -q "create table t(pk int primary key);"
dolt add t
original_head=$(get_head_commit)
# When --allow-empty and --skip-empty are both specified, the user should get an error
run dolt commit --allow-empty --skip-empty -m "commit message"
[ $status -eq 1 ]
[[ "$output" =~ 'error: cannot use both --allow-empty and --skip-empty' ]] || false
[ $original_head = $(get_head_commit) ]
# When changes are staged, --skip-empty has no effect
dolt commit --skip-empty -m "commit message"
new_head=$(get_head_commit)
[ $original_head != $new_head ]
# When no changes are staged, --skip-empty skips creating the commit
dolt commit --skip-empty -m "commit message"
[ $new_head = $(get_head_commit) ]
}
@@ -38,6 +38,11 @@ current_dolt_user_email() {
dolt config --global --get user.email
}
# get_head_commit returns the commit hash for the current HEAD
get_head_commit() {
dolt log -n 1 | grep -m 1 commit | cut -c 13-44
}
setup_no_dolt_init() {
export PATH=$PATH:~/go/bin
cd $BATS_TMPDIR
@@ -32,6 +32,7 @@ SKIP_SERVER_TESTS=$(cat <<-EOM
~sql-charsets-collations.bats~
~sql-cherry-pick.bats~
~sql-commit.bats~
~sql-local-remote.bats~
~primary-key-changes.bats~
~common.bash.bats~
~remotes-localbs.bats~
@@ -52,7 +52,7 @@ teardown() {
cd $BATS_TMPDIR
if ! [ "$DOLT_DEFAULT_BIN_FORMAT" = "__DOLT__" ]; then
dolt config --list | awk '{ print $1 }' | grep sqlserver.global | xargs dolt config --global --unset
dolt config --list | awk '{ print $1 }' | grep sqlserver.global | xargs -r dolt config --global --unset
fi
}
+17 -2
View File
@@ -453,6 +453,21 @@ SQL
[[ "$output" =~ 'error: no value for option `message' ]] || false
}
get_head_commit() {
dolt log -n 1 | grep -m 1 commit | cut -c 13-44
@test "sql-commit: --skip-empty correctly skips committing when no changes are staged" {
original_head=$(get_head_commit)
# When --allow-empty and --skip-empty are both specified, the user should get an error
run dolt sql -q "CALL DOLT_COMMIT('--allow-empty', '--skip-empty', '-m', 'commit message');"
[ $status -eq 1 ]
[[ "$output" =~ 'error: cannot use both --allow-empty and --skip-empty' ]] || false
[ $original_head = $(get_head_commit) ]
# When changes are staged, --skip-empty has no effect
dolt sql -q "CALL DOLT_COMMIT('--skip-empty', '-m', 'commit message');"
new_head=$(get_head_commit)
[ $original_head != $new_head ]
# When no changes are staged, --skip-empty skips creating the commit
dolt sql -q "CALL DOLT_COMMIT('--skip-empty', '-m', 'commit message');"
[ $new_head = $(get_head_commit) ]
}
@@ -11,6 +11,9 @@ make_repo() {
}
setup() {
if [ "$SQL_ENGINE" = "remote-engine" ]; then
skip "This test tests remote connections directly, SQL_ENGINE is not needed."
fi
setup_no_dolt_init
make_repo defaultDB
make_repo altDB
@@ -21,6 +24,14 @@ teardown() {
teardown_common
}
get_staged_tables() {
dolt status | awk '
match($0, /new table:\ */) { print substr($0, RSTART+RLENGTH) }
/Untracked tables:/ { exit }
/Tables with conflicting dolt_ignore patterns:/ { exit }
'
}
@test "sql-local-remote: test switch between server/no server" {
start_sql_server defaultDB
@@ -129,4 +140,21 @@ teardown() {
[ "$status" -eq 0 ]
[[ "$output" = $out ]] || false
}
@test "sql-local-remote: verify simple dolt add behavior." {
start_sql_server altDB
cd altDB
run dolt --verbose-engine-setup --user dolt sql -q "create table testtable (pk int PRIMARY KEY)"
[ "$status" -eq 0 ]
[[ "$output" =~ "starting remote mode" ]] || false
run dolt --verbose-engine-setup --user dolt add .
[ "$status" -eq 0 ]
[[ "$output" =~ "starting remote mode" ]] || false
stop_sql_server 1
staged=$(get_staged_tables)
[[ ! -z $(echo "$staged" | grep "testtable") ]] || false
}