/integration-tests: move bats

This commit is contained in:
Dustin Brown
2021-03-15 14:03:22 -07:00
parent 567ee75165
commit 61b06450b1
260 changed files with 3 additions and 3 deletions

1
integration-tests/bats/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
helper/__pycache__

View File

@@ -0,0 +1,703 @@
#!/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() {
assert_feature_version
teardown_common
}
# Create a single primary key table and do stuff
@test "1pk5col-ints: create a table with a schema file and examine repo" {
run dolt ls
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "test" ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ pk[[:space:]]+\|[[:space:]]+c1[[:space:]]+\|[[:space:]]+c2[[:space:]]+\|[[:space:]]+c3[[:space:]]+\|[[:space:]]+c4[[:space:]]+\|[[:space:]]+c5 ]] || false
run dolt diff
[ "$status" -eq 0 ]
[ "${lines[0]}" = "diff --dolt a/test b/test" ]
[ "${lines[1]}" = "added table" ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Untracked files" ]]
[[ "$output" =~ new[[:space:]]table:[[:space:]]+test ]] || false
}
@test "1pk5col-ints: create a table, dolt add, dolt reset, and dolt commit" {
run dolt add test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed" ]]
[[ "$output" =~ "new table:" ]] || false
run dolt reset test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Untracked files" ]]
[[ "$output" =~ "new table:" ]] || false
run dolt add .
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed" ]]
[[ "$output" =~ "new table:" ]] || false
run dolt commit -m "test commit"
[ "$status" -eq 0 ]
[[ "$output" =~ "test commit" ]] || false
run dolt log
[ "$status" -eq 0 ]
[[ "$output" =~ "test commit" ]] || false
}
@test "1pk5col-ints: add a row to a created table using dolt table put-row" {
dolt add test
dolt commit -m "create table"
run dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
[ "$status" -eq 0 ]
run dolt diff
[ "$status" -eq 0 ]
[[ "$output" =~ \+[[:space:]]+\|[[:space:]]+0[[:space:]]+\|[[:space:]]+1 ]] || false
}
@test "1pk5col-ints: dolt sql all manner of inserts" {
run dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,6,6,6,6,6)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 1 row affected" ]] || false
run dolt sql -q "select * from test"
[[ "$output" =~ "6" ]] || false
run dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (1,7,7,7,7,7),(2,8,8,8,8,8)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 2 rows affected" ]] || false
run dolt sql -q "select * from test"
[[ "$output" =~ "7" ]] || false
[[ "$output" =~ "8" ]] || false
run dolt sql -q "insert into test (pk,c1,c3,c5) values (3,9,9,9)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 1 row affected" ]] || false
run dolt sql -q "select * from test"
[[ "$output" =~ "9" ]] || false
run dolt sql -q "insert into test (c1,c3,c5) values (50,55,60)"
[ "$status" -eq 1 ]
[ "$output" = "column name 'pk' is non-nullable but attempted to set default value of null" ]
run dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5,c6) values (10,1,1,1,1,1,1)"
[ "$status" -eq 1 ]
[ "$output" = "invalid column name c6" ]
run dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,6,6,6,6,6)"
[ "$status" -eq 1 ]
[[ "$output" =~ "duplicate primary key" ]] || false
}
@test "1pk5col-ints: dolt sql insert same column twice" {
run dolt sql -q "insert into test (pk,c1,c1) values (3,1,2)"
[ "$status" -eq 1 ]
[ "$output" = "duplicate column name c1" ]
}
@test "1pk5col-ints: dolt sql insert no columns specified" {
run dolt sql -q "insert into test values (0,0,0,0,0,0)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 1 row affected" ]] || false
run dolt sql -q "select * from test"
[[ "$output" =~ "0" ]] || false
run dolt sql -q "insert into test values (4,1,2)"
[ "$status" -eq 1 ]
[ "$output" = "number of values does not match number of columns provided" ]
}
@test "1pk5col-ints: dolt sql with insert ignore" {
skip "New engine does not support insert ignore"
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,6,6,6,6,6)"
run dolt sql -q "insert ignore into test (pk,c1,c2,c3,c4,c5) values (0,6,6,6,6,6),(11,111,111,111,111,111)"
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Rows inserted: 1" ]
[ "${lines[1]}" = "Errors ignored: 1" ]
run dolt sql -q "select * from test"
[[ "$output" =~ "111" ]] || false
}
@test "1pk5col-ints: dolt sql replace into" {
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,6,6,6,6,6)"
run dolt sql -q "replace into test (pk,c1,c2,c3,c4,c5) values (0,7,7,7,7,7),(1,8,8,8,8,8)"
[ "$status" -eq 0 ]
# No skip, but this is a bug in the output. Query produces the right result, but counts it incorrectly
[[ "$output" =~ "Query OK, 4 rows affected" ]] || false
## No skip, but this should report 3 but is reporting 4 [[ "${lines[3]}" =~ "3" ]] || false
run dolt sql -q "select * from test"
[[ "$output" =~ "7" ]] || false
[[ "$output" =~ "8" ]] || false
[[ ! "$output" =~ "6" ]] || false
skip "replace into output is incorrect"
}
@test "1pk5col-ints: dolt sql insert and dolt sql select" {
run dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,1,2,3,4,5)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 1 row affected" ]] || false
run dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (101,102,103,104,105,106),(1,6,7,8,9,10)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 2 rows affected" ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ \|[[:space:]]+c5 ]] || false
[[ "$output" =~ \|[[:space:]]+5 ]] || false
[[ "$output" =~ \|[[:space:]]+10 ]] || false
[[ "$output" =~ \|[[:space:]]+106 ]] || false
run dolt sql -q "select * from test where pk=1"
[ "$status" -eq 0 ]
[[ "$output" =~ \|[[:space:]]+c5 ]] || false
[[ "$output" =~ \|[[:space:]]+10 ]] || false
run dolt sql -q "select c5 from test where pk=1"
[ "$status" -eq 0 ]
[[ "$output" =~ \|[[:space:]]+c5 ]] || false
[[ "$output" =~ \|[[:space:]]+10 ]] || false
run dolt sql -q "select * from test limit 1"
[ "$status" -eq 0 ]
# All line number assertions are offset by 3 to allow for table separator lines
[ "${#lines[@]}" -eq 5 ]
run dolt sql -q "select * from test where c2 > 7"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
run dolt sql -q "select * from test where c2 >= 7"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 6 ]
run dolt sql -q "select * from test where c2 <> 7"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 6 ]
run dolt sql -q "select * from test where c2 > 3 and c1 < 10"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
run dolt sql -q "select c10 from test where pk=1"
[ "$status" -eq 1 ]
[ "$output" = "column \"c10\" could not be found in any table in scope" ]
run dolt sql -q "select * from test where c2=147"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 4 ]
}
@test "1pk5col-ints: dolt sql select as" {
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,1,2,3,4,5),(1,11,12,13,14,15),(2,21,22,23,24,25)"
run dolt sql -q "select c1 as column1, c2 as column2 from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "column1" ]] || false
[[ "$output" =~ "column2" ]] || false
[[ ! "$output" =~ "c1" ]] || false
[[ ! "$output" =~ "c2" ]] || false
run dolt sql -q "select c1 as column1 from test where c1=1"
[ "$status" -eq 0 ]
[[ "$output" =~ column1 ]] || false
[ "${#lines[@]}" -eq 5 ]
}
@test "1pk5col-ints: dolt sql select csv output" {
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,1,2,3,4,5),(1,11,12,13,14,15),(2,21,22,23,24,25)"
run dolt sql -q "select c1 as column1, c2 as column2 from test" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "column1,column2" ]] || false
[[ "$output" =~ "1,2" ]] || false
[[ "$output" =~ "11,12" ]] || false
run dolt sql -q "select c1 as column1 from test where c1=1" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ 'column1' ]] || false
[ "${#lines[@]}" -eq 2 ]
# Test that null values are properly output
dolt sql -q "insert into test (pk,c1) values (40,1)"
run dolt sql -q "select c1 as column1, c2 as column2, c3 as column3 from test where pk = 40" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "column1,column2,column3" ]] || false
[[ "$output" =~ "1,," ]] || false
}
@test "1pk5col-ints: dolt sql select json output" {
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,1,2,3,4,5),(1,11,12,13,14,15),(2,21,22,23,24,25)"
run dolt sql -q "select c1 as column1, c2 as column2 from test" -r json
[ "$status" -eq 0 ]
[ "$output" == '{"rows": [{"column1":1,"column2":2},{"column1":11,"column2":12},{"column1":21,"column2":22}]}' ]
run dolt sql -q "select c1 as column1 from test where c1=1" -r json
[ "$status" -eq 0 ]
[ "$output" == '{"rows": [{"column1":1}]}' ]
# Test that null values are properly handled
dolt sql -q "insert into test (pk,c1) values (40,1)"
run dolt sql -q "select c1 as column1, c2 as column2, c3 as column3 from test where pk = 40" -r json
[ "$status" -eq 0 ]
[ "$output" == '{"rows": [{"column1":1}]}' ]
}
@test "1pk5col-ints: dolt sql select with inverted where clause" {
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,1,2,3,4,5),(1,11,12,13,14,15),(2,21,22,23,24,25)"
run dolt sql -q "select * from test where 5 > c1"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
}
@test "1pk5col-ints: dolt sql update queries" {
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,1,2,3,4,5),(1,11,12,13,14,15),(2,21,22,23,24,25)"
run dolt sql -q "update test set c1=6,c2=7,c3=8,c4=9,c5=10 where pk=0"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 1 row affected" ]] || false
[[ "$output" =~ "Rows matched: 1 Changed: 1 Warnings: 0" ]] || false
run dolt sql -q "select * from test where pk=0"
[ "$status" -eq 0 ]
[[ "$output" =~ "10" ]] || false
[[ ! "$output" =~ "|5" ]] || false
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (4,11,12,13,14,15)"
run dolt sql -q "update test set c2=11,c3=11,c4=11,c5=11 where c1=11"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 2 rows affected" ]] || false
[[ "$output" =~ "Rows matched: 2 Changed: 2 Warnings: 0" ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "11" ]] || false
[[ ! "$output" =~ "12" ]] || false
run dolt sql -q "update test set c2=50,c3=50,c4=50,c5=50 where c1=50"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 0 rows affected" ]] || false
[[ "$output" =~ "Rows matched: 0 Changed: 0 Warnings: 0" ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ ! "$output" =~ "50" ]] || false
run dolt sql -q "update test set c12=11 where pk=0"
[ "$status" -eq 1 ]
[ "$output" = "column \"c12\" could not be found in any table in scope" ]
run dolt sql -q "update test set c1='foo' where pk=0"
[ "$status" -eq 1 ]
[ "$output" = "unable to cast \"foo\" of type string to int64" ]
run dolt sql -q "update test set c1=100,c2=100,c3=100,c4=100,c5=100 where pk>0"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 3 rows affected" ]] || false
[[ "$output" =~ "Rows matched: 3 Changed: 3 Warnings: 0" ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "100" ]] || false
[[ "$output" =~ "10" ]] || false
[[ ! "$output" =~ "11" ]] || false
}
@test "1pk5col-ints: dolt sql delete queries" {
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,1,2,3,4,5),(1,11,12,13,14,15),(2,21,22,23,24,25)"
run dolt sql -q "delete from test where pk=2"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 1 row affected" ]] || false
run dolt sql -q "delete from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 2 rows affected" ]] || false
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,1,2,3,4,5),(1,11,12,13,14,15),(2,21,22,23,24,25)"
run dolt sql -q "delete from test where pk>0"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 2 rows affected" ]] || false
run dolt sql -q "delete from test where c1=1"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 1 row affected" ]] || false
dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (0,1,2,3,4,5),(1,11,12,13,14,15),(2,21,22,23,24,25)"
run dolt sql -q "delete from test where c10=1"
[ "$status" -eq 1 ]
[ "$output" = "column \"c10\" could not be found in any table in scope" ]
run dolt sql -q "delete from test where c1='foo'"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 0 rows affected" ]] || false
}
@test "1pk5col-ints: dolt checkout to put a table back to its checked in state" {
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "Added table and test row"
dolt sql -q "replace into test values (0, 1, 2, 3, 4, 10)"
run dolt checkout test
[ "$status" -eq 0 ]
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "5" ]] || false
[[ ! "$output" =~ "10" ]] || false
}
@test "1pk5col-ints: dolt checkout branch and table name collision" {
dolt branch test
run dolt checkout test
[ "$status" -eq 0 ]
# Checks out branch "test" table "test" unaltered. Matches git behavior for:
#
# git init
# git commit --allow-empty -m "create"
# touch test
# git branch test
# git checkout test
}
@test "1pk5col-ints: make a change on a different branch, commit, and merge to master" {
dolt branch test-branch
dolt checkout test-branch
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "added test row"
dolt checkout master
run dolt merge test-branch
[ "$status" -eq 0 ]
[[ "$output" =~ "Fast-forward" ]] || false
run dolt log
[ "$status" -eq 0 ]
[[ "$output" =~ "added test row" ]] || false
}
@test "1pk5col-ints: create a branch off an older commit than HEAD" {
dolt add test
dolt commit -m "first commit"
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "added test row"
run dolt checkout -b older-branch HEAD^
[ "$status" -eq 0 ]
[ "$output" = "Switched to branch 'older-branch'" ]
run dolt log
[[ ! "$output" =~ "added test row" ]] || false
[[ "$output" =~ "first commit" ]] || false
}
@test "1pk5col-ints: delete an unmerged branch" {
dolt checkout -b test-branch
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "added test row"
run dolt branch -d test-branch
[ "$status" -ne 0 ]
[ "$output" = "error: Cannot delete checked out branch 'test-branch'" ]
dolt checkout master
run dolt branch -d test-branch
[ "$status" -ne 0 ]
run dolt branch -d -f test-branch
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
@test "1pk5col-ints: generate a merge conflict and resolve with ours" {
dolt add test
dolt commit -m "added test table"
dolt branch test-branch
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "added test row"
dolt checkout test-branch
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 6)"
dolt add test
dolt commit -m "added conflicting test row"
dolt checkout master
run dolt merge test-branch
[ "$status" -eq 0 ]
[[ "$output" =~ "CONFLICT (content)" ]]
run dolt conflicts cat test
[ "$status" -eq 0 ]
[[ "$output" =~ \+[[:space:]]+\|[[:space:]]+ours[[:space:]] ]] || false
[[ "$output" =~ \+[[:space:]]+\|[[:space:]]+theirs[[:space:]] ]] || false
EXPECTED=$(echo -e "table,num_conflicts\ntest,1")
run dolt sql -r csv -q 'SELECT * FROM dolt_conflicts'
[ "$status" -eq 0 ]
[[ "$output" =~ "$EXPECTED" ]] || false
run dolt conflicts resolve --ours test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ \|[[:space:]]+5 ]] || false
[[ ! "$output" =~ \|[[:space:]]+6 ]] || false
run dolt conflicts cat test
[[ ! "$output" =~ "ours" ]] || false
[[ ! "$output" =~ "theirs" ]] || false
dolt add test
dolt commit -m "merged and resolved conflict"
run dolt log
[[ "$output" =~ "added test row" ]] || false
[[ "$output" =~ "added conflicting test row" ]] || false
[[ "$output" =~ "merged and resolved conflict" ]] || false
[[ "$output" =~ "Merge:" ]] || false
}
@test "1pk5col-ints: generate a merge conflict and try to roll back using dolt merge --abort" {
dolt add test
dolt commit -m "added test table"
dolt branch test-branch
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "added test row"
dolt checkout test-branch
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 6)"
dolt add test
dolt commit -m "added conflicting test row"
dolt checkout master
dolt merge test-branch
run dolt checkout test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt sql -q "select * from test"
[[ "$output" =~ \|[[:space:]]+5 ]] || false
run dolt conflicts cat test
[[ ! "$output" =~ "ours" ]] || false
[[ ! "$output" =~ "theirs" ]] || false
run dolt status
[[ "$output" =~ "All conflicts fixed but you are still merging." ]] || false
run dolt merge --abort
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
}
@test "1pk5col-ints: generate a merge conflict and resolve with theirs" {
dolt add test
dolt commit -m "added test table"
dolt branch test-branch
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "added test row"
dolt checkout test-branch
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 6)"
dolt add test
dolt commit -m "added conflicting test row"
dolt checkout master
dolt merge test-branch
run dolt conflicts resolve --theirs test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt sql -q "select * from test"
[[ "$output" =~ \|[[:space:]]+6 ]] || false
[[ ! "$output" =~ "|5" ]] || false
}
@test "1pk5col-ints: put a row that violates the schema" {
run dolt sql -q "insert into test values (0, 1, 2, 3, 4, 'foo')"
[ "$status" -ne 0 ]
}
@test "1pk5col-ints: put a row that has a column not in the schema" {
run dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5, 10)"
[ "$status" -ne 0 ]
}
@test "1pk5col-ints: import data from a csv file after table created" {
run dolt table import test -u `batshelper 1pk5col-ints.csv`
[ "$status" -eq 0 ]
[[ "$output" =~ "Import completed successfully." ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
# Number of lines offset by 3 for table printing style
[ "${#lines[@]}" -eq 6 ]
}
@test "1pk5col-ints: import data from a csv file with a bad line" {
cat <<DELIM > badline.csv
pk,c1,c2,c3,c4,c5
0,1,2,3,4,5
1,1,2,3,4,5
2
DELIM
run dolt table import test -u badline.csv
[ "$status" -eq 1 ]
[[ "${lines[0]}" =~ "Additions" ]] || false
[[ "${lines[1]}" =~ "A bad row was encountered" ]] || false
[[ "${lines[2]}" =~ "expects 6 fields" ]] || false
[[ "${lines[2]}" =~ "line only has 1 value" ]] || false
}
@test "1pk5col-ints: import data from a csv file with a bad header" {
cat <<DELIM > bad.csv
,c1,c2,c3,c4,c5
0,1,2,3,4,5
DELIM
run dolt table import test -u bad.csv
[ "$status" -eq 1 ]
[[ "$output" =~ "bad header line: column cannot be NULL or empty string" ]] || false
[[ ! "$output" =~ "panic" ]] || false
cat <<DELIM > bad.csv
pk,c1, ,c3,c4,c5
0,1,2,3,4,5
DELIM
run dolt table import test -u bad.csv
[ "$status" -eq 1 ]
[[ "$output" =~ "bad header line: column cannot be NULL or empty string" ]] || false
[[ ! "$output" =~ "panic" ]] || false
cat <<DELIM > bad.csv
pk,c1,"",c3,c4,c5
0,1,2,3,4,5
DELIM
run dolt table import test -u bad.csv
[ "$status" -eq 1 ]
[[ "$output" =~ "bad header line: column cannot be NULL or empty string" ]] || false
[[ ! "$output" =~ "panic" ]] || false
cat <<DELIM > bad.csv
pk,c1," ",c3,c4,c5
0,1,2,3,4,5
DELIM
run dolt table import test -u bad.csv
[ "$status" -eq 1 ]
[[ "$output" =~ "bad header line: column cannot be NULL or empty string" ]] || false
[[ ! "$output" =~ "panic" ]] || false
}
@test "1pk5col-ints: import data from a psv file after table created" {
cat <<DELIM > 1pk5col-ints.psv
pk|c1|c2|c3|c4|c5
0|1|2|3|4|5
1|1|2|3|4|5
DELIM
run dolt table import test -u 1pk5col-ints.psv
[ "$status" -eq 0 ]
[[ "$output" =~ "Import completed successfully." ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
# Number of lines offset by 3 for table printing style
[ "${#lines[@]}" -eq 6 ]
}
@test "1pk5col-ints: overwrite a row. make sure it updates not inserts" {
dolt table import test -u `batshelper 1pk5col-ints.csv`
run dolt sql -q "replace into test values (1, 2, 4, 6, 8, 10)"
[ "$status" -eq 0 ]
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
# Number of lines offset by 3 for table printing style
[ "${#lines[@]}" -eq 6 ]
}
@test "1pk5col-ints: dolt schema show" {
run dolt schema show
[ "$status" -eq 0 ]
[[ "$output" =~ "test @ working" ]] || false
[[ "$output" =~ "CREATE TABLE \`test\`" ]] || false
[[ "$output" =~ "\`pk\` bigint NOT NULL" ]] || false
[[ "$output" =~ "\`c1\` bigint" ]] || false
[[ "$output" =~ "\`c2\` bigint" ]] || false
[[ "$output" =~ "\`c3\` bigint" ]] || false
[[ "$output" =~ "\`c4\` bigint" ]] || false
[[ "$output" =~ "\`c5\` bigint" ]] || false
[[ "$output" =~ "PRIMARY KEY (\`pk\`)" ]] || false
run dolt schema show test
[ "$status" -eq 0 ]
[[ "$output" =~ "test @ working" ]] || false
[[ "$output" =~ "CREATE TABLE \`test\`" ]] || false
[[ "$output" =~ "\`pk\` bigint NOT NULL" ]] || false
[[ "$output" =~ "\`c1\` bigint" ]] || false
[[ "$output" =~ "\`c2\` bigint" ]] || false
[[ "$output" =~ "\`c3\` bigint" ]] || false
[[ "$output" =~ "\`c4\` bigint" ]] || false
[[ "$output" =~ "\`c5\` bigint" ]] || false
[[ "$output" =~ "PRIMARY KEY (\`pk\`)" ]] || false
}
@test "1pk5col-ints: dolt schema show on non existant table" {
run dolt schema show foo
[ "$status" -eq 0 ]
[ "$output" = "foo not found" ]
}
@test "1pk5col-ints: rm a staged but uncommitted table" {
run dolt add test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt table rm test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt add test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt status
[ "${lines[0]}" = "On branch master" ]
[ "${lines[1]}" = "nothing to commit, working tree clean" ]
}
@test "1pk5col-ints: create and view a table with NULL values" {
dolt sql -q "insert into test (pk) values (0)"
dolt sql -q "insert into test (pk) values (1)"
dolt sql -q "insert into test (pk) values (2)"
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "NULL" ]] || false
doltsqloutput=$output
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "NULL" ]] || false
[ "$output" = "$doltsqloutput" ]
# Make sure we don't get a table with no spaces because that bug was
# generated when making changes to NULL printing
[[ ! "$output" =~ "|||||" ]] || false
}
@test "1pk5col-ints: using dolt sql to select rows with NULL values" {
dolt sql -q "insert into test (pk) values (0)"
dolt sql -q "insert into test (pk) values (1)"
dolt sql -q "insert into test values (2, 0, 0, 0, 0, 0)"
run dolt sql -q "select * from test where c1 is null"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 6 ]
[[ "$output" =~ "NULL" ]] || false
}
@test "1pk5col-ints: display correct merge stats" {
dolt checkout -b test-branch
dolt add test
dolt commit -m "added test table"
dolt checkout master
dolt branch test-branch-m
dolt branch test-branch-alt
dolt checkout test-branch-m
dolt merge test-branch
dolt checkout test-branch-alt
dolt sql -q "CREATE TABLE test_alt (pk BIGINT NOT NULL, c1 BIGINT, PRIMARY KEY (pk));"
dolt add test_alt
dolt commit -m 'add test_alt'
dolt checkout test-branch-m
dolt merge test-branch-alt
dolt add test_alt
dolt commit -m 'merge test_alt'
dolt checkout test-branch
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "added row to test"
dolt checkout test-branch-m
run dolt merge test-branch
echo $output
[ "$status" -eq 0 ]
[ "${lines[1]}" = "test | 1 +" ]
[ "${lines[2]}" = "1 tables changed, 1 rows added(+), 0 rows modified(*), 0 rows deleted(-)" ]
}
@test "1pk5col-ints: checkout table with branch of same name" {
dolt checkout -b test
dolt add .
dolt commit -m "added test table"
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
run dolt checkout test
skip "Should distinguish between branch name and table name" [ "$status" -eq 0 ]
[ "${lines[0]}" != "Already on branch 'test'" ]
run dolt status
[ "$status" -eq 0 ]
[ "${lines[4]}" != " modified: test" ]
}

View File

@@ -0,0 +1,98 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
dolt sql <<SQL
CREATE TABLE test (
pk LONGTEXT NOT NULL COMMENT 'tag:0',
c1 LONGTEXT COMMENT 'tag:1',
c2 LONGTEXT COMMENT 'tag:2',
c3 LONGTEXT COMMENT 'tag:3',
c4 LONGTEXT COMMENT 'tag:4',
c5 LONGTEXT COMMENT 'tag:5',
PRIMARY KEY (pk)
);
SQL
}
teardown() {
assert_feature_version
teardown_common
}
@test "1pk5col-strings: dolt sql with string comparison operators" {
dolt sql -q "insert into test values ('tim', 'is', 'super', 'duper', 'rad', 'fo sho')"
dolt sql -q "insert into test values ('zach', 'is', 'super', 'duper', 'not', 'rad')"
dolt sql -q "insert into test values ('this', 'test', 'is', 'a', 'good', 'test')"
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
# All row counts are offset by 4 to account for table printing
[ "${#lines[@]}" -eq 7 ]
run dolt sql -q "select * from test where pk='tim'"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
run dolt sql -q "select * from test where pk>'tim'"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
run dolt sql -q "select * from test where pk>='tim'"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 6 ]
run dolt sql -q "select * from test where pk<>'tim'"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 6 ]
run dolt sql -q "select * from test where pk='bob'"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 4 ]
}
@test "1pk5col-strings: interact with a strings type table with sql" {
run dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values ('tim','is','super','duper','rad','fo sho')"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 1 row affected" ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "c5" ]] || false
[[ "$output" =~ "tim" ]] || false
run dolt sql -q "select pk,c1,c4 from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "c4" ]] || false
[[ "$output" =~ "tim" ]] || false
[[ ! "$output" =~ "super" ]] || false
}
@test "1pk5col-strings: insert must use quoted strings" {
run dolt sql -q "insert into test (pk,c1,c2,c3,c4,c5) values (tim,is,super,duper,rad,'fo sho')"
[ "$status" -eq 1 ]
[[ "$output" =~ "Error parsing SQL" ]] || false
}
@test "1pk5col-strings: create and view a table with NULL and empty string values" {
dolt sql -q "insert into test values ('tim', '', '', '', '', '')"
dolt sql -q "insert into test (pk) values ('aaron')"
dolt sql -q "insert into test (pk) values ('brian')"
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
# select orders by primary key right now so aaron, brian, tim
[[ "${lines[4]}" =~ "NULL" ]] || false
[[ ! "${lines[5]}" =~ "NULL" ]] || false
doltselectoutput=$output
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "NULL" ]] || false
[ "$output" = "$doltselectoutput" ]
# Make sure we don't get a table with no spaces because that bug was
# generated when making changes to NULL printing
[[ ! "$output" =~ "|||||" ]] || false
}
@test "1pk5col-strings: semicolons in quoted sql statements" {
run dolt sql -q "insert into test (pk,c1) values ('test', 'this; should; work')"
[ "$status" -eq 0 ]
run dolt sql <<< "insert into test (pk,c1) values ('test2', 'this; should; work')"
[ "$status" -eq 0 ]
[[ "$output" =~ "Rows inserted: 1" ]]
run dolt sql <<< "insert into test (pk,c1) values ('test3', 'this \\\\'' should \\\\'' work')"
[ "$status" -eq 0 ]
[[ "$output" =~ "Rows inserted: 1" ]]
}

View File

@@ -0,0 +1,59 @@
#!/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',
\`int\` BIGINT COMMENT 'tag:1',
\`string\` LONGTEXT COMMENT 'tag:2',
\`boolean\` BOOLEAN COMMENT 'tag:3',
\`float\` DOUBLE COMMENT 'tag:4',
\`uint\` BIGINT UNSIGNED COMMENT 'tag:5',
\`uuid\` CHAR(36) CHARACTER SET ascii COLLATE ascii_bin COMMENT 'tag:6',
PRIMARY KEY (pk)
);
SQL
}
teardown() {
assert_feature_version
teardown_common
}
@test "1pksupportedtypes: dolt table put-row with all types then examine table" {
run dolt sql -q "insert into test values (0, 1, 'foo', true, 1.11111111111111, 346, '123e4567-e89b-12d3-a456-426655440000')"
[ "$status" -eq 0 ]
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
}
@test "1pksupportedtypes: boolean 1,0,true,false inserts and examine table" {
run dolt sql -q "insert into test values (0, 1, 'foo', 1, 1.11111111111111, 346, '123e4567-e89b-12d3-a456-426655440000')"
[ "$status" -eq 0 ]
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "boolean" ]] || false
[[ "${lines[3]}" =~ "1" ]] || false
run dolt sql -q "replace into test values (0, 1, 'foo', 0, 1.11111111111111, 346, '123e4567-e89b-12d3-a456-426655440000')"
[ "$status" -eq 0 ]
run dolt sql -q "select * from test"
[[ "${lines[3]}" =~ "0" ]] || false
run dolt sql -q "replace into test values (0, 1, 'foo', true, 1.11111111111111, 346, '123e4567-e89b-12d3-a456-426655440000')"
[ "$status" -eq 0 ]
run dolt sql -q "select * from test"
[[ "${lines[3]}" =~ "1" ]] || false
run dolt sql -q "replace into test values (0, 1, 'foo', false, 1.11111111111111, 346, '123e4567-e89b-12d3-a456-426655440000')"
[ "$status" -eq 0 ]
run dolt sql -q "select * from test"
[[ "${lines[3]}" =~ "0" ]] || false
}
@test "1pksupportedtypes: attempt to insert some schema violations" {
run dolt sql -q "insert into test values (0, 1, 'foo', true, 1.11111111111111, -346, '123e4567-e89b-12d3-a456-426655440000')"
[ "$status" -eq 1 ]
run dolt sql -q "insert into test values (0, 1, 'foo', 'foo', 1.11111111111111, 346, 'not_a_uuid')"
[ "$status" -eq 1 ]
}

View File

@@ -0,0 +1,104 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
dolt sql <<SQL
CREATE TABLE test (
pk1 BIGINT NOT NULL COMMENT 'tag:0',
pk2 BIGINT NOT NULL COMMENT 'tag:1',
c1 BIGINT COMMENT 'tag:2',
c2 BIGINT COMMENT 'tag:3',
c3 BIGINT COMMENT 'tag:4',
c4 BIGINT COMMENT 'tag:5',
c5 BIGINT COMMENT 'tag:6',
PRIMARY KEY (pk1,pk2)
);
SQL
}
teardown() {
assert_feature_version
teardown_common
}
@test "2pk5cols-ints: create a table with a schema file and examine repo" {
run dolt ls
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "test" ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ pk1[[:space:]]+\|[[:space:]]+pk2[[:space:]]+\|[[:space:]]+c1[[:space:]]+\|[[:space:]]+c2[[:space:]]+\|[[:space:]]+c3[[:space:]]+\|[[:space:]]+c4[[:space:]]+\|[[:space:]]+c5 ]] || false
run dolt diff
[ "$status" -eq 0 ]
[ "${lines[0]}" = "diff --dolt a/test b/test" ]
[ "${lines[1]}" = "added table" ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Untracked files" ]] || false
[[ "$output" =~ "new table:" ]] || false
}
@test "2pk5cols-ints: add a row to a two primary table using dolt table put-row" {
dolt add test
dolt commit -m "added test table"
run dolt sql -q "insert into test values (0, 0, 1, 2, 3, 4, 5)"
[ "$status" -eq 0 ]
run dolt diff
[ "$status" -eq 0 ]
[[ "$output" =~ \+[[:space:]]+\|[[:space:]]+0[[:space:]]+\|[[:space:]]+0 ]] || false
}
@test "2pk5cols-ints: add a row where one of the primary keys is different, not both" {
dolt sql -q "insert into test values (0, 0, 1, 2, 3, 4, 5)"
run dolt sql -q "insert into test values (0, 1, 1, 2, 3, 4, 10)"
[ "$status" -eq 0 ]
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 6 ]
[[ "$output" =~ \|[[:space:]]+5 ]] || false
[[ "$output" =~ \|[[:space:]]+10 ]] || false
}
@test "2pk5cols-ints: overwrite a row with two primary keys" {
dolt sql -q "insert into test values (0, 0, 1, 2, 3, 4, 5)"
run dolt sql -q "replace into test values (0, 0, 1, 2, 3, 4, 10)"
[ "$status" -eq 0 ]
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
[[ ! "$output" =~ \|[[:space:]]+5 ]] || false
[[ "$output" =~ \|[[:space:]]+10 ]] || false
}
@test "2pk5cols-ints: interact with a multiple primary key table with sql" {
run dolt sql -q "insert into test (pk1,pk2,c1,c2,c3,c4,c5) values (0,0,6,6,6,6,6)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 1 row affected" ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "c5" ]] || false
[[ "$output" =~ "6" ]] || false
run dolt sql -q "insert into test (pk1,pk2,c1,c2,c3,c4,c5) values (0,1,7,7,7,7,7),(1,0,8,8,8,8,8)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Query OK, 2 rows affected" ]] || false
run dolt sql -q "select * from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "c5" ]] || false
[[ "$output" =~ "7" ]] || false
[[ "$output" =~ "8" ]] || false
run dolt sql -q "select * from test where pk1=1"
[ "$status" -eq 0 ]
[[ "$output" =~ "c5" ]] || false
[[ "$output" =~ "8" ]] || false
[[ ! "$output" =~ "6" ]] || false
run dolt sql -q "insert into test (pk1,pk2,c1,c2,c3,c4,c5) values (0,1,7,7,7,7,7)"
[ "$status" -eq 1 ]
[[ "$output" =~ "duplicate primary key" ]] || false
run dolt sql -q "insert into test (pk1,c1,c2,c3,c4,c5) values (0,6,6,6,6,6)"
[ "$status" -eq 1 ]
[ "$output" = "column name 'pk2' is non-nullable but attempted to set default value of null" ] || false
run dolt sql -q "insert into test (c1,c2,c3,c4,c5) values (6,6,6,6,6)"
[ "$status" -eq 1 ]
[ "$output" = "column name 'pk1' is non-nullable but attempted to set default value of null" ] || false
}

View File

@@ -0,0 +1,63 @@
# BATS - Bash Automated Testing System #
BATS is used to integration test `dolt`. Our BATS tests started as a humble suite of integration tests. Over two years
of development the suite has grown to over 1,000 tests. When we find a customer facing bug in the `dolt` command line or
SQL implementation, we cover it with a BATS test. These tests are run on every `dolt` PR on Windows and Linux using
GitHub Actions.
These tests are also useful documentation. If you are wondering how a certain command or feature works in practice,
using `grep` to find the appropriate BATS test can give you some simple examples of happy path and error case behavior.
The naming conventions for the test files have evolved over time. Generally, the files are named after the feature the
file intends to test. However, some of the early tests are named after the schema of the table they implement
ie. `1pk5col-ints.bats`. These files were implemented to reuse setup and teardown logic. This scheme was quickly
abandoned but the legacy remains.
If you find a bug in `dolt`, we would love a skipped bats test PR in addition to a GutHub issue.
# Running for yourself
First you need to install bats.
```
npm install -g bats
```
Then, go to the directory with the bats tests and run:
```
bats .
```
This will run all the tests. Specify a particular .bats file to run only those tests.
## Here Docs
BATS tests in Dolt make extensive use of [Here Docs](https://en.wikipedia.org/wiki/Here_document).
Common patterns include piping SQL scripts to `dolt sql`:
```sql
dolt sql <<SQL
CREATE TABLE my_table (pk int PRIMARY KEY);
SQL
```
And creating data files for import:
```sql
cat <<DELIM > data.csv
pk,c1,c2
1,1,1
2,2,2
DELIM
dolt table import -c -pk=pk my_table data.csv
```
## Skipped BATS
Various tests are skipped as TODOs and/or as documentation of known bugs. Eg:
```sql
@test "..." {
...
skip "this test is currently failing because..."
}
```
Skipped BATS can still be partially useful for testing as they execute normally up to `skip` statement.
## More Information
We published a [blog entry](https://www.dolthub.com/blog/2020-03-23-testing-dolt-bats/) on BATS with
more information and some useful tips and tricks.

View File

@@ -0,0 +1,63 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
assert_feature_version
teardown_common
}
@test "arg-parsing: dolt supports Nix style argument parsing" {
dolt checkout -b this-should-work
run dolt branch
[ $status -eq 0 ]
[[ "$output" =~ "this-should-work" ]] || false
dolt checkout master
dolt branch -d this-should-work
dolt checkout -b "this-should-work"
run dolt branch
[ $status -eq 0 ]
[[ "$output" =~ "this-should-work" ]] || false
dolt checkout master
dolt branch -d "this-should-work"
dolt checkout --b "this-should-work"
run dolt branch
[ $status -eq 0 ]
[[ "$output" =~ "this-should-work" ]] || false
dolt checkout master
dolt branch --d "this-should-work"
run dolt checkout -bthis-should-work
[ $status -eq 0 ]
run dolt branch
[ $status -eq 0 ]
[[ "$output" =~ "this-should-work" ]] || false
dolt checkout master
dolt branch -dthis-should-work
cat <<DELIM > ints.csv
pk,c1
0,0
DELIM
dolt table import -cpk=pk this-should-work ints.csv
}
@test "arg-parsing: dolt supports chaining of modal arguments" {
dolt sql -q "create table test(pk int, primary key (pk))"
dolt table import -fc -pk=pk test `batshelper 1pk5col-ints.csv`
}
@test "arg-parsing: dolt checkout with empty string returns error" {
run dolt checkout ""
[[ "$output" =~ "error: cannot checkout empty string" ]] || false
[ $status -ne 0 ]
run dolt checkout -b ""
[[ "$output" =~ "error: cannot checkout empty string" ]] || false
[ $status -ne 0 ]
}

View File

@@ -0,0 +1,322 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
dolt sql <<SQL
CREATE TABLE test (
pk int NOT NULL PRIMARY KEY AUTO_INCREMENT,
c0 int
);
SQL
}
teardown() {
assert_feature_version
teardown_common
}
@test "auto_increment: insert into auto_increment table" {
dolt sql -q "INSERT INTO test VALUES (1,11),(2,22),(3,33);"
run dolt sql -q "INSERT INTO test (c0) VALUES (44);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM test WHERE c0 = 44;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "4,44" ]] || false
run dolt sql -q "INSERT INTO test (c0) VALUES (55),(66);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM test WHERE c0 > 50;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "5,55" ]] || false
[[ "$output" =~ "6,66" ]] || false
}
@test "auto_increment: create auto_increment table with out-of-line PK def" {
run dolt sql <<SQL
CREATE TABLE ai (
pk int AUTO_INCREMENT,
c0 int,
PRIMARY KEY(pk)
);
INSERT INTO ai VALUES (NULL,1),(NULL,2),(NULL,3);
SQL
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM ai;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "3,3" ]] || false
}
@test "auto_increment: insert into empty auto_increment table" {
run dolt sql -q "INSERT INTO test (c0) VALUES (1);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM test WHERE c0 = 1;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "1,1" ]] || false
}
@test "auto_increment: insert into auto_increment table with skipped keys" {
dolt sql -q "INSERT INTO test VALUES (1,1),(100,100);"
run dolt sql -q "INSERT INTO test (c0) VALUES (101);"
[ "$status" -eq 0 ]
run dolt sql -q "INSERT INTO test VALUES (2,2);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM test;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "100,100" ]] || false
[[ "$output" =~ "101,101" ]] || false
}
@test "auto_increment: insert into auto_increment table with NULL" {
dolt sql -q "INSERT INTO test VALUES (1,1);"
run dolt sql -q "INSERT INTO test (pk,c0) VALUES (NULL,2);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM test WHERE c0 > 1;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2,2" ]] || false
run dolt sql -q "INSERT INTO test VALUES (NULL,3), (10,10), (NULL,11);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM test WHERE c0 > 2;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "3,3" ]] || false
[[ "$output" =~ "10,10" ]] || false
[[ "$output" =~ "11,11" ]] || false
}
@test "auto_increment: insert into auto_increment table with 0" {
dolt sql -q "INSERT INTO test VALUES (1,1);"
run dolt sql -q "INSERT INTO test (pk,c0) VALUES (0,2);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM test WHERE c0 > 1;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2,2" ]] || false
run dolt sql -q "INSERT INTO test VALUES (0,3), (10,10), (0,11);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM test WHERE c0 > 2;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "3,3" ]] || false
[[ "$output" =~ "10,10" ]] || false
[[ "$output" =~ "11,11" ]] || false
}
@test "auto_increment: insert into auto_increment table via batch mode" {
run dolt sql <<SQL
INSERT INTO test (c0) VALUES (1);
INSERT INTO test (c0) VALUES (2);
INSERT INTO test (pk,c0) VALUES (19,19);
INSERT INTO test (c0) VALUES (20);
INSERT INTO test (c0) VALUES (21);
SQL
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM test;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "19,19" ]] || false
[[ "$output" =~ "20,20" ]] || false
[[ "$output" =~ "21,21" ]] || false
}
@test "auto_increment: insert into table via batch mode" {
# asserts proper batch mode handling
run dolt sql <<SQL
CREATE TABLE test2 (
pk int PRIMARY KEY,
c0 int
);
INSERT INTO test2 VALUES (1,1),(2,2),(3,3);
INSERT INTO test2 SELECT (pk + 10), c0 FROM test2;
INSERT INTO test2 SELECT (pk + 20), c0 FROM test2;
SQL
[ "$status" -eq 0 ]
run dolt sql -q "select * from test2 order by pk" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "3,3" ]] || false
[[ "$output" =~ "11,1" ]] || false
[[ "$output" =~ "12,2" ]] || false
[[ "$output" =~ "13,3" ]] || false
[[ "$output" =~ "21,1" ]] || false
[[ "$output" =~ "22,2" ]] || false
[[ "$output" =~ "23,3" ]] || false
}
@test "auto_increment: insert into auto_increment table with correct floating point rounding" {
dolt sql <<SQL
CREATE TABLE auto_float (
pk float NOT NULL PRIMARY KEY AUTO_INCREMENT,
c0 int
);
SQL
dolt sql -q "INSERT INTO auto_float (c0) VALUES (1);"
dolt sql -q "INSERT INTO auto_float (pk, c0) VALUES (2.1,2);"
dolt sql -q "INSERT INTO auto_float (c0) VALUES (3);"
dolt sql -q "INSERT INTO auto_float (pk, c0) VALUES (3.9,4);"
dolt sql -q "INSERT INTO auto_float (c0) VALUES (5);"
run dolt sql -q "SELECT * FROM auto_float;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "2.1,2" ]] || false
[[ "$output" =~ "3,3" ]] || false
[[ "$output" =~ "3.9,4" ]] || false
[[ "$output" =~ "5,5" ]] || false
}
@test "auto_increment: create auto_increment tables with all numeric types" {
# signed integer types and floating point
for TYPE in TINYINT SMALLINT MEDIUMINT INT BIGINT FLOAT DOUBLE
do
dolt sql <<SQL
CREATE TABLE auto_$TYPE (
pk $TYPE NOT NULL PRIMARY KEY AUTO_INCREMENT,
c0 int
);
INSERT INTO auto_$TYPE VALUES (1,1);
SQL
echo "$TYPE"
run dolt sql -q "INSERT INTO auto_$TYPE (c0) VALUES (2);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM auto_$TYPE WHERE c0 > 1;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2,2" ]] || false
done
# unsigned integer types
for TYPE in TINYINT SMALLINT MEDIUMINT INT BIGINT
do
dolt sql <<SQL
CREATE TABLE auto2_$TYPE (
pk $TYPE UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
c0 int
);
INSERT INTO auto2_$TYPE VALUES (1,1);
SQL
echo "$TYPE"
run dolt sql -q "INSERT INTO auto2_$TYPE (c0) VALUES (2);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT * FROM auto2_$TYPE WHERE c0 > 1;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2,2" ]] || false
done
}
@test "auto_increment: invalid AUTO_INCREMENT definitions fail" {
run dolt sql -q "CREATE TABLE bad (pk int PRIMARY KEY, c0 int AUTO_INCREMENT);"
[ "$status" -ne 0 ]
[[ "$output" =~ "there can be only one auto_increment column and it must be defined as a key" ]] || false
run dolt sql -q "CREATE TABLE bad (pk1 int AUTO_INCREMENT, pk2 int AUTO_INCREMENT, PRIMARY KEY (pk1,pk2));"
[ "$status" -ne 0 ]
[[ "$output" =~ "there can be only one auto_increment column and it must be defined as a key" ]] || false
run dolt sql -q "CREATE TABLE bad (pk1 int AUTO_INCREMENT DEFAULT 10, c0 int);"
[ "$status" -ne 0 ]
[[ "$output" =~ "there can be only one auto_increment column and it must be defined as a key" ]] || false
}
@test "auto_increment: AUTO_INCREMENT merge master branch ahead" {
dolt sql -q "INSERT INTO test (c0) VALUES (0),(1),(2)"
dolt add -A
dolt commit -m "made some inserts"
dolt checkout -b other
dolt sql -q "INSERT INTO test VALUES (10,10),(NULL,11);"
dolt add -A
dolt commit -m "inserted 10 & 11 on other"
dolt checkout master
dolt sql -q "INSERT INTO test VALUES (20,20),(NULL,21);"
dolt add -A
dolt commit -m "inserted 20 & 21 on master"
dolt merge other
dolt sql -q "INSERT INTO test VALUES (NULL,22);"
run dolt sql -q "SELECT pk FROM test WHERE c0 = 22;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "22" ]] || false
}
@test "auto_increment: AUTO_INCREMENT merge other branch ahead" {
dolt sql -q "INSERT INTO test (c0) VALUES (0),(1),(2)"
dolt add -A
dolt commit -m "made some inserts"
dolt branch other
dolt sql -q "INSERT INTO test VALUES (10,10),(NULL,11);"
dolt add -A
dolt commit -m "inserted 10 & 11 on master"
dolt checkout other
dolt sql -q "INSERT INTO test VALUES (20,20),(NULL,21);"
dolt add -A
dolt commit -m "inserted 20 & 21 on other"
dolt checkout master
dolt merge other
dolt sql -q "INSERT INTO test VALUES (NULL,22);"
run dolt sql -q "SELECT pk FROM test WHERE c0 = 22;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "22" ]] || false
}
@test "auto_increment: AUTO_INCREMENT with ALTER TABLE" {
run dolt sql -q "ALTER TABLE test AUTO_INCREMENT = 10;"
[ "$status" -eq 0 ]
dolt sql -q "INSERT INTO test VALUES (NULL,10);"
run dolt sql -q "SELECT * FROM test;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "10,10" ]] || false
dolt sql <<SQL
ALTER TABLE test AUTO_INCREMENT = 20;
INSERT INTO test VALUES (NULL,20),(30,30),(NULL,31);
SQL
run dolt sql -q "SELECT * FROM test;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "10,10" ]] || false
[[ "$output" =~ "20,20" ]] || false
[[ "$output" =~ "30,30" ]] || false
[[ "$output" =~ "31,31" ]] || false
}
@test "auto_increment: adding index to AUTO_INCREMENT doesn't reset sequence" {
dolt sql <<SQL
CREATE TABLE index_test (
pk int PRIMARY KEY AUTO_INCREMENT,
c0 int
);
INSERT INTO index_test (c0) VALUES (1),(2),(3);
ALTER TABLE index_test ADD INDEX (c0);
INSERT INTO index_test (c0) VALUES (4),(5),(6);
SQL
run dolt sql -q "select * from index_test" -r csv
[ "$status" -eq 0 ]
[[ "${lines[0]}" =~ "pk,c0" ]] || false
[[ "${lines[1]}" =~ "1,1" ]] || false
[[ "${lines[2]}" =~ "2,2" ]] || false
[[ "${lines[3]}" =~ "3,3" ]] || false
[[ "${lines[4]}" =~ "4,4" ]] || false
[[ "${lines[5]}" =~ "5,5" ]] || false
[[ "${lines[6]}" =~ "6,6" ]] || false
}

View File

@@ -0,0 +1,75 @@
# Simple smoke tests verifying the AWS remotes work as advertised.
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
teardown_common
}
skip_if_no_aws_tests() {
if [ -z "$DOLT_BATS_AWS_TABLE" -o -z "$DOLT_BATS_AWS_BUCKET" -o -z "$DOLT_BATS_AWS_EXISTING_REPO" ]; then
skip "skipping aws tests; set DOLT_BATS_AWS_TABLE, DOLT_BATS_AWS_BUCKET and DOLT_BATS_AWS_EXISTING_REPO to run"
fi
}
@test "aws-remotes: can add remote with aws url" {
dolt remote add origin 'aws://[dynamo_db_table:s3_bucket]/repo_name'
}
@test "aws-remotes: can fetch existing aws remote" {
skip_if_no_aws_tests
dolt remote add origin 'aws://['"$DOLT_BATS_AWS_TABLE"':'"$DOLT_BATS_AWS_BUCKET"']/'"$DOLT_BATS_AWS_EXISTING_REPO"
dolt fetch origin
}
@test "aws-remotes: fetch with non-existant dynamo table fails" {
skip_if_no_aws_tests
dolt remote add origin 'aws://['"this_dynamodb_table_does_not_exist_b612c34f055f4b458"':'"$DOLT_BATS_AWS_BUCKET"']/'"$DOLT_BATS_AWS_EXISTING_REPO"
run dolt fetch origin
[ "$status" -eq 1 ]
}
@test "aws-remotes: fetch with non-existant s3 bucket fails" {
skip_if_no_aws_tests
dolt remote add origin 'aws://['"$DOLT_BATS_AWS_TABLE"':'"this_s3_bucket_does_not_exist_5883eaaa20a4797bb"']/'"$DOLT_BATS_AWS_EXISTING_REPO"
run dolt fetch origin
[ "$status" -eq 1 ]
}
@test "aws-remotes: can clone an existing aws remote" {
skip_if_no_aws_tests
rm -rf .dolt
dolt clone 'aws://['"$DOLT_BATS_AWS_TABLE"':'"$DOLT_BATS_AWS_BUCKET"']/'"$DOLT_BATS_AWS_EXISTING_REPO"
cd "$DOLT_BATS_AWS_EXISTING_REPO"
dolt sql -q 'show tables'
}
# Matches behavior of other remote types
@test "aws-remotes: clone empty aws remote fails" {
skip_if_no_aws_tests
rm -rf .dolt
random_repo=`openssl rand -hex 32`
run dolt clone 'aws://['"$DOLT_BATS_AWS_TABLE"':'"$DOLT_BATS_AWS_BUCKET"']/'"$random_repo"
[ "$status" -eq 1 ]
[[ "$output" =~ "error: clone failed" ]] || false
[[ "$output" =~ "cause: remote at that url contains no Dolt data" ]] || false
}
@test "aws-remotes: can push to new remote" {
skip_if_no_aws_tests
random_repo=`openssl rand -hex 32`
dolt remote add origin 'aws://['"$DOLT_BATS_AWS_TABLE"':'"$DOLT_BATS_AWS_BUCKET"']/'"$random_repo"
dolt sql -q 'create table a_test_table (id int primary key)'
dolt sql -q 'insert into a_test_table values (1), (2), (47)'
dolt add .
dolt commit -m 'creating a test table'
dolt push origin master:master
dolt fetch origin
dolt push origin :master
dolt push origin master:another-branch
dolt push origin :another-branch
}

View File

@@ -0,0 +1,162 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
cp -a $BATS_TEST_DIRNAME/helper/testdata/. ./
}
teardown() {
teardown_common
}
@test "back-compat: data check" {
for testdir in */; do
cd "$testdir"
dolt status
run dolt migrate
[ "$status" -eq "0" ]
[[ "$output" =~ "Migrating repository to the latest format" ]] || false
run dolt branch
[ "$status" -eq "0" ]
[[ "$output" =~ "master" ]] || false
[[ "$output" =~ "conflict" ]] || false
[[ "$output" =~ "newcolumn" ]] || false
run dolt schema show
[ "$status" -eq "0" ]
[[ "$output" =~ "\`pk\` bigint NOT NULL" ]] || false
[[ "$output" =~ "\`a\` longtext" ]] || false
[[ "$output" =~ "\`b\` datetime" ]] || false
run dolt sql -q "select * from abc order by pk asc"
[ "$status" -eq "0" ]
[[ "${lines[3]}" =~ " 1 " ]] || false
[[ "${lines[3]}" =~ " data " ]] || false
[[ "${lines[3]}" =~ " 2020-01-13 20:45:18.53558 " ]] || false
dolt checkout conflict
run dolt schema show
[ "$status" -eq "0" ]
[[ "$output" =~ "\`pk\` bigint NOT NULL" ]] || false
[[ "$output" =~ "\`a\` longtext" ]] || false
[[ "$output" =~ "\`b\` datetime" ]] || false
run dolt sql -q "select * from abc order by pk asc"
[ "$status" -eq "0" ]
[[ "${lines[3]}" =~ " 1 " ]] || false
[[ "${lines[3]}" =~ " data " ]] || false
[[ "${lines[3]}" =~ " 2020-01-13 20:45:18.53558 " ]] || false
[[ "${lines[4]}" =~ " 2 " ]] || false
[[ "${lines[4]}" =~ " something " ]] || false
[[ "${lines[4]}" =~ " 2020-01-14 20:48:37.13061 " ]] || false
dolt checkout newcolumn
run dolt schema show
[ "$status" -eq "0" ]
[[ "$output" =~ "\`pk\` bigint NOT NULL" ]] || false
[[ "$output" =~ "\`a\` longtext" ]] || false
[[ "$output" =~ "\`b\` datetime" ]] || false
[[ "$output" =~ "\`c\` bigint unsigned" ]] || false
run dolt sql -q "select * from abc order by pk asc"
[ "$status" -eq "0" ]
[[ "${lines[3]}" =~ " 1 " ]] || false
[[ "${lines[3]}" =~ " data " ]] || false
[[ "${lines[3]}" =~ " 2020-01-13 20:45:18.53558 " ]] || false
[[ "${lines[3]}" =~ " 2133" ]] || false
[[ "${lines[4]}" =~ " 2 " ]] || false
[[ "${lines[4]}" =~ " something " ]] || false
[[ "${lines[4]}" =~ " 2020-01-13 20:48:37.13061 " ]] || false
[[ "${lines[4]}" =~ " 1132020" ]] || false
cd ..
done
}
@test "back-compat: table operations" {
for testdir in */; do
cd "$testdir"
dolt table cp abc copy
dolt table mv abc move
run dolt ls
[ "$status" -eq "0" ]
[[ "$output" =~ "copy" ]] || false
[[ "$output" =~ "move" ]] || false
cd ..
done
}
@test "back-compat: adding commits" {
for testdir in */; do
cd "$testdir"
run dolt migrate
[ "$status" -eq "0" ]
[[ "$output" =~ "Migrating repository to the latest format" ]] || false
dolt sql -q "insert into abc values (2, 'text', '2020-01-15 20:49:22.28427')"
dolt add .
dolt commit -m "Add value during test"
run dolt sql -q "select * from abc order by pk asc"
[ "$status" -eq "0" ]
[[ "${lines[4]}" =~ " 2 " ]] || false
[[ "${lines[4]}" =~ " text " ]] || false
[[ "${lines[4]}" =~ " 2020-01-15 20:49:22.28427 " ]] || false
dolt checkout newcolumn
dolt checkout -b testaddcommit
dolt sql -q "insert into abc values (3, 'text', '2020-01-15 20:49:22.28427', 9241)"
dolt add .
dolt commit -m "Add value during test"
run dolt sql -q "select * from abc order by pk asc"
[ "$status" -eq "0" ]
[[ "${lines[5]}" =~ " 3 " ]] || false
[[ "${lines[5]}" =~ " text " ]] || false
[[ "${lines[5]}" =~ " 2020-01-15 20:49:22.28427 " ]] || false
[[ "${lines[5]}" =~ " 9241 " ]] || false
cd ..
done
}
@test "back-compat: merging" {
for testdir in */; do
cd "$testdir"
run dolt migrate
[ "$status" -eq "0" ]
run dolt merge newcolumn
[ "$status" -eq "0" ]
[[ "$output" =~ "Fast-forward" ]] || false
cd ..
done
}
@test "back-compat: resolving conflicts" {
skip https://github.com/dolthub/dolt/issues/773
for testdir in */; do
cd "$testdir"
run dolt migrate
[ "$status" -eq "0" ]
[[ "$output" =~ "Migrating repository to the latest format" ]] || false
dolt checkout conflict
run dolt merge newcolumn
[ "$status" -eq "0" ]
[[ "$output" =~ "CONFLICT" ]] || false
run dolt conflicts cat abc
[ "$status" -eq "0" ]
[[ "${lines[3]}" =~ " ours " ]] || false
[[ "${lines[3]}" =~ " 2 " ]] || false
[[ "${lines[3]}" =~ " something " ]] || false
[[ "${lines[3]}" =~ " 2020-01-14 20:48:37.13061 " ]] || false
[[ "${lines[3]}" =~ " NULL " ]] || false
[[ "${lines[4]}" =~ " theirs " ]] || false
[[ "${lines[4]}" =~ " 2 " ]] || false
[[ "${lines[4]}" =~ " something " ]] || false
[[ "${lines[4]}" =~ " 2020-01-13 20:48:37.13061 " ]] || false
[[ "${lines[4]}" =~ " 1132020 " ]] || false
dolt conflicts resolve --theirs abc
dolt add .
dolt commit -m "Merged newcolumn into conflict"
run dolt sql -q "select * from abc order by pk asc"
[ "$status" -eq "0" ]
[[ "${lines[3]}" =~ " 1 " ]] || false
[[ "${lines[3]}" =~ " data " ]] || false
[[ "${lines[3]}" =~ " 2020-01-13 20:45:18.53558 " ]] || false
[[ "${lines[3]}" =~ " 2133" ]] || false
[[ "${lines[4]}" =~ " 2 " ]] || false
[[ "${lines[4]}" =~ " something " ]] || false
[[ "${lines[4]}" =~ " 2020-01-13 20:48:37.13061 " ]] || false
[[ "${lines[4]}" =~ " 1132020" ]] || false
cd ..
done
}

View File

@@ -0,0 +1,138 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
setup_repository
}
teardown() {
assert_feature_version
teardown_common
}
setup_repository() {
stash_current_dolt_user
set_dolt_user "Thomas Foolery", "bats-1@email.fake"
dolt sql <<SQL
CREATE TABLE blame_test (
pk BIGINT NOT NULL COMMENT 'tag:0',
name LONGTEXT COMMENT 'tag:1',
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into blame_test (pk,name) values (1, \"Tom\")"
dolt add blame_test
dolt commit -m "create blame_test table"
set_dolt_user "Richard Tracy", "bats-2@email.fake"
dolt sql -q "insert into blame_test (pk,name) values (2, \"Richard\")"
dolt add blame_test
dolt commit -m "add richard to blame_test"
set_dolt_user "Harry Wombat", "bats-3@email.fake"
dolt sql -q "update blame_test set name = \"Harry\" where pk = 2"
dolt add blame_test
dolt commit -m "replace richard with harry"
set_dolt_user "Johnny Moolah", "bats-4@email.fake"
dolt sql -q "insert into blame_test (pk,name) values (3, \"Alan\"), (4, \"Betty\")"
dolt add blame_test
dolt commit -m "add more people to blame_test"
restore_stashed_dolt_user
}
@test "blame: no arguments shows usage" {
run dolt blame
[ "$status" -eq 1 ]
[[ "$output" =~ "usage" ]] || false
}
@test "blame: annotates a small table with simple history" {
# should be the same as dolt blame HEAD blame_test
run dolt blame -- blame_test
[ "$status" -eq 0 ]
# TODO: Make these assertions better
[[ "$output" =~ "Thomas Foolery" ]] || false
[[ "$output" =~ "create blame_test table" ]] || false
[[ ! "$output" =~ "Richard Tracy" ]] || false
[[ ! "$output" =~ "add richard to blame_test" ]] || false
[[ "$output" =~ "Harry Wombat" ]] || false
[[ "$output" =~ "replace richard" ]] || false
[[ "$output" =~ "Johnny Moolah" ]] || false
[[ "$output" =~ "add more people" ]] || false
}
@test "blame: blames HEAD when commit ref omitted" {
run dolt blame blame_test
[ "$status" -eq 0 ]
[[ "$output" =~ "Thomas Foolery" ]] || false
[[ "$output" =~ "create blame_test table" ]] || false
[[ ! "$output" =~ "Richard Tracy" ]] || false
[[ ! "$output" =~ "add richard to blame_test" ]] || false
[[ "$output" =~ "Harry Wombat" ]] || false
[[ "$output" =~ "replace richard" ]] || false
[[ "$output" =~ "Johnny Moolah" ]] || false
[[ "$output" =~ "add more people" ]] || false
}
@test "blame: works with HEAD as the commit ref" {
run dolt blame HEAD blame_test
[ "$status" -eq 0 ]
[[ "$output" =~ "Thomas Foolery" ]] || false
[[ "$output" =~ "create blame_test table" ]] || false
[[ ! "$output" =~ "Richard Tracy" ]] || false
[[ ! "$output" =~ "add richard to blame_test" ]] || false
[[ "$output" =~ "Harry Wombat" ]] || false
[[ "$output" =~ "replace richard" ]] || false
[[ "$output" =~ "Johnny Moolah" ]] || false
[[ "$output" =~ "add more people" ]] || false
}
@test "blame: works with HEAD~1 as the commit ref" {
run dolt blame HEAD~1 blame_test
[ "$status" -eq 0 ]
[[ "$output" =~ "Thomas Foolery" ]] || false
[[ "$output" =~ "create blame_test table" ]] || false
[[ ! "$output" =~ "Richard Tracy" ]] || false
[[ ! "$output" =~ "add richard to blame_test" ]] || false
[[ "$output" =~ "Harry Wombat" ]] || false
[[ "$output" =~ "replace richard" ]] || false
[[ ! "$output" =~ "Johnny Moolah" ]] || false
[[ ! "$output" =~ "add more people" ]] || false
}
@test "blame: works with HEAD~2 as the commit ref" {
run dolt blame HEAD~2 blame_test
[ "$status" -eq 0 ]
[[ "$output" =~ "Thomas Foolery" ]] || false
[[ "$output" =~ "create blame_test table" ]] || false
[[ "$output" =~ "Richard Tracy" ]] || false
[[ "$output" =~ "add richard to blame_test" ]] || false
[[ ! "$output" =~ "Harry Wombat" ]] || false
[[ ! "$output" =~ "replace richard" ]] || false
[[ ! "$output" =~ "Johnny Moolah" ]] || false
[[ ! "$output" =~ "add more people" ]] || false
}
@test "blame: works with HEAD~3 as the commit ref" {
run dolt blame HEAD~3 blame_test
[ "$status" -eq 0 ]
[[ "$output" =~ "Thomas Foolery" ]] || false
[[ "$output" =~ "create blame_test table" ]] || false
[[ ! "$output" =~ "Richard Tracy" ]] || false
[[ ! "$output" =~ "add richard to blame_test" ]] || false
[[ ! "$output" =~ "Harry Wombat" ]] || false
[[ ! "$output" =~ "replace richard" ]] || false
[[ ! "$output" =~ "Johnny Moolah" ]] || false
[[ ! "$output" =~ "add more people" ]] || false
}
@test "blame: returns an error when the table is not found in the given revision" {
run dolt blame HEAD~4 blame_test
[ "$status" -eq 1 ]
[[ "$output" =~ "no table named blame_test found" ]] || false
}

View File

@@ -0,0 +1,110 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
cat <<SQL > capital-letter-column-names-schema.sql
CREATE TABLE test (
Aaa INT NOT NULL,
Bbb VARCHAR(20),
Ccc VARCHAR(20),
PRIMARY KEY (Aaa)
);
SQL
cat <<DELIM > capital-letter-column-names.csv
Aaa,Bbb,Ccc
1,aaa,AAA
2,bbb,BBB
DELIM
dolt table import -c -s capital-letter-column-names-schema.sql test capital-letter-column-names.csv
}
teardown() {
assert_feature_version
teardown_common
}
@test "case-sensitivity: capital letter col names. sql select with a where clause" {
run dolt sql -q "select * from test where Aaa = 2"
[ "$status" -eq 0 ]
[[ "$output" =~ "BBB" ]] || false
}
@test "case-sensitivity: capital letter col names. dolt schema show" {
run dolt schema show
[ "$status" -eq 0 ]
[[ "$output" =~ "Aaa" ]] || false
[[ "$output" =~ "Bbb" ]] || false
[[ "$output" =~ "Ccc" ]] || false
}
@test "case-sensitivity: capital letter col names. sql select" {
run dolt sql -q "select Bbb from test where Aaa=2"
[ "$status" -eq 0 ]
[[ "$output" =~ "bbb" ]] || false
[[ "$output" =~ "Bbb" ]] || false
[[ ! "$output" =~ "Aaa" ]] || false
[[ ! "$output" =~ "aaa" ]] || false
}
@test "case-sensitivity: capital letter col names. dolt table export" {
run dolt table export test export.csv
[ "$status" -eq 0 ]
[[ "$output" =~ "Successfully exported data" ]] || false
run cat export.csv
[ "$status" -eq 0 ]
[[ "$output" =~ "bbb" ]] || false
[[ "$output" =~ "Bbb" ]] || false
[[ "$output" =~ "Aaa" ]] || false
[[ "$output" =~ "aaa" ]] || false
}
@test "case-sensitivity: capital letter col names. dolt table copy" {
run dolt table cp test test2
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt sql -q "select * from test2"
[ "$status" -eq 0 ]
[[ "$output" =~ "bbb" ]] || false
[[ "$output" =~ "Bbb" ]] || false
[[ "$output" =~ "Aaa" ]] || false
[[ "$output" =~ "aaa" ]] || false
}
@test "case-sensitivity: capital letter column names. select with an as" {
run dolt sql -q "select Aaa as AAA from test"
[ "$status" -eq 0 ]
[[ "$output" =~ "AAA" ]] || false
}
@test "case-sensitivity: select table case insensitive, table and column" {
run dolt sql -r csv -q "select aaa as AAA from TEST order by 1 limit 1"
[ "$status" -eq 0 ]
[[ "$output" =~ "AAA" ]] || false
run dolt sql -r csv -q "select Test.aaa as AAA from TEST order by 1 limit 1"
[ "$status" -eq 0 ]
[[ "$output" =~ "AAA" ]] || false
[[ "$output" =~ "1" ]] || false
}
@test "case-sensitivity: select table alias case insensitive" {
run dolt sql -r csv -q "select t.aaA as AaA from TEST T order by 1 limit 1"
[ "$status" -eq 0 ]
[[ "$output" =~ "AaA" ]] || false
[[ "$output" =~ "1" ]] || false
}
@test "case-sensitivity: select reserved word, preserve case" {
run dolt sql -q "select 1 as DaTe"
[ "$status" -eq 0 ]
[[ "$output" =~ "DaTe" ]] || false
}
@test "case-sensitivity: select column with different case" {
run dolt sql -q "select AaA from Test order by 1 limit 1"
[ "$status" -eq 0 ]
[[ "$output" =~ "1" ]] || false
[[ "$output" =~ "Aaa" ]] || false
}

View File

@@ -0,0 +1,239 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
assert_feature_version
teardown_common
}
@test "column_tags: Renaming a column should preserve the tag number" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
PRIMARY KEY (pk));
SQL
run dolt schema tags -r=csv
[ $status -eq 0 ]
[[ "$output" =~ "test,c1,8201" ]] || false
dolt sql -q "alter table test rename column c1 to c0"
run dolt schema tags -r=csv
[ $status -eq 0 ]
[[ "$output" =~ "test,c0,8201" ]] || false
}
@test "column_tags: Renaming a table should preserve the tag number" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
PRIMARY KEY (pk));
SQL
run dolt schema tags -r=csv
[ $status -eq 0 ]
[[ "$output" =~ "test,pk,3228" ]] || false
[[ "$output" =~ "test,c1,8201" ]] || false
dolt sql -q "alter table test rename to new_name"
run dolt schema tags -r=csv
[ $status -eq 0 ]
[[ "$output" =~ "new_name,pk,3228" ]] || false
[[ "$output" =~ "new_name,c1,8201" ]] || false
}
@test "column_tags: Schema tags should be case insensitive to tables" {
dolt sql <<SQL
CREATE TABLE TeSt (
pk BIGINT NOT NULL,
c1 BIGINT,
PRIMARY KEY (pk));
SQL
run dolt schema tags test -r=csv
[ $status -eq 0 ]
[[ "$output" =~ "TeSt,pk,3228" ]] || false
[[ "$output" =~ "TeSt,c1,8201" ]] || false
}
@test "column_tags: Merging two branches that added same tag, name, type, and constraints" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
PRIMARY KEY (pk));
SQL
dolt add test
dolt commit -m "Committed test table"
dolt branch branch1
dolt branch branch2
dolt checkout branch1
dolt sql -q "alter table test add column c2 bigint"
dolt add test
dolt commit -m "Added column c2 bigint"
dolt checkout branch2
dolt sql -q "alter table test add column c2 bigint"
dolt add test
dolt commit -m "Added column c2 bigint"
dolt checkout master
dolt merge branch1
dolt merge branch2
}
@test "column_tags: Merging branches that use the same tag referring to different schema fails" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:1234',
c1 BIGINT COMMENT 'tag:5678',
PRIMARY KEY (pk));
SQL
dolt add test
dolt commit -m "Committed test table"
dolt branch branch1
dolt branch branch2
dolt checkout branch1
dolt sql -q "alter table test add column c2 bigint"
dolt add test
dolt commit -m "Added column c2 bigint"
dolt checkout branch2
dolt sql -q "alter table test add column c2 longtext"
dolt add test
dolt commit -m "Added column c2 longtext"
dolt checkout master
dolt merge branch1
run dolt merge branch2
[ $status -ne 0 ]
}
@test "column_tags: Merging branches that use the same tag referring to different column names fails" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:1234',
c1 BIGINT COMMENT 'tag:5678',
PRIMARY KEY (pk));
SQL
dolt add test
dolt commit -m "Committed test table"
dolt branch branch1
dolt branch branch2
dolt checkout branch1
dolt sql -q "alter table test add column c2 bigint"
dolt add test
dolt commit -m "Added column c2 bigint"
dolt checkout branch2
dolt sql -q "alter table test add column c2 bigint"
dolt sql -q "alter table test rename column c2 to c0"
dolt add test
dolt commit -m "Added column c0 bigint"
dolt checkout master
dolt merge branch1
run dolt merge branch2
[ $status -eq 1 ]
}
@test "column_tags: Merging branches that both created the same column succeeds" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
PRIMARY KEY (pk));
SQL
dolt add test
dolt commit -m "Committed test table"
dolt branch branch1
dolt branch branch2
dolt checkout branch1
dolt sql -q "alter table test add column c2 bigint"
dolt sql -q "alter table test add column c3 double"
dolt add test
dolt commit -m "Added columns c2 bigint and c3 double to branch1"
dolt checkout branch2
dolt sql -q "alter table test add column c2 bigint"
# column c3 will have the same tag on both branches due to deterministic tag generation
dolt sql -q "alter table test add column c3 double"
dolt add test
dolt commit -m "Added columns c2 bigint and c3 double to branch2"
dolt checkout master
dolt merge branch1
run dolt merge branch2
[ $status -eq 0 ]
run dolt schema show
[[ "${lines[2]}" =~ "\`pk\` bigint NOT NULL" ]] || false
[[ "${lines[3]}" =~ "\`c1\` bigint" ]] || false
[[ "${lines[4]}" =~ "\`c2\` bigint" ]] || false
[[ "${lines[5]}" =~ "\`c3\` double" ]] || false
}
@test "column_tags: Merging branches that both created the same table succeeds" {
dolt branch branch1
dolt branch branch2
dolt checkout branch1
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
PRIMARY KEY (pk));
SQL
dolt add test
dolt commit -m "Committed test table"
dolt checkout branch2
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
PRIMARY KEY (pk));
SQL
dolt add test
# pk and c1 will have the same tags on both branches due to deterministic tag generation
dolt commit -m "Committed test table"
dolt checkout master
dolt merge branch1
run dolt merge branch2
[ $status -eq 0 ]
run dolt schema show
[[ "${lines[2]}" =~ "\`pk\` bigint NOT NULL" ]] || false
[[ "${lines[3]}" =~ "\`c1\` bigint" ]] || false
}
@test "column_tags: Deterministic tag generation produces consistent results" {
dolt branch other
dolt sql <<SQL
CREATE TABLE test1 (
pk1 BIGINT NOT NULL,
c1 BIGINT,
c2 DOUBLE,
c3 LONGTEXT,
PRIMARY KEY (pk1));
SQL
dolt add test1
dolt commit -m "Committed test table"
# If anything changes to deterministic tag generation, this will break
run dolt schema tags -r=csv
[ $status -eq 0 ]
[[ "$output" =~ "test1,pk1,10458" ]] || false
[[ "$output" =~ "test1,c1,5951" ]] || false
[[ "$output" =~ "test1,c2,10358" ]] || false
[[ "$output" =~ "test1,c3,11314" ]] || false
}
@test "column_tags: dolt table import -c uses deterministic tag generation" {
cat <<DELIM > data.csv
pk,c1,c2,c3,c4,c5
0,1,2,3,4,5
a,b,c,d,e,f
DELIM
run dolt table import -c -pk=pk ints_table data.csv
[ $status -eq 0 ]
run dolt schema tags -r=csv
[ $status -eq 0 ]
[[ "$output" =~ "ints_table,pk,6302" ]] || false
[[ "$output" =~ "ints_table,c1,12880" ]] || false
[[ "$output" =~ "ints_table,c2,15463" ]] || false
[[ "$output" =~ "ints_table,c3,14526" ]] || false
[[ "$output" =~ "ints_table,c4,5634" ]] || false
[[ "$output" =~ "ints_table,c5,12796" ]] || false
}

View File

@@ -0,0 +1,139 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
dolt sql <<SQL
CREATE TABLE test (
pk int primary key
);
INSERT INTO test VALUES (0),(1),(2);
SQL
dolt add .
dolt commit -m "created table test"
dolt sql <<SQL
DELETE FROM test WHERE pk = 0;
INSERT INTO test VALUES (3);
SQL
dolt add .
dolt commit -m "made changes"
}
teardown() {
assert_feature_version
teardown_common
}
@test "commit_tags: create a tag with a explicit ref" {
run dolt tag v1 HEAD^
[ $status -eq 0 ]
run dolt tag
[ $status -eq 0 ]
[[ "$output" =~ "v1" ]] || false
}
@test "commit_tags: create a tag with implicit head ref" {
run dolt tag v1
[ $status -eq 0 ]
run dolt tag
[ $status -eq 0 ]
[[ "$output" =~ "v1" ]] || false
}
@test "commit_tags: create tag v1.2.3" {
skip "Noms doesn't support '.' in dataset names"
run dolt tag v1.2.3
[ $status -eq 0 ]
}
@test "commit_tags: delete a tag" {
dolt tag v1
dolt tag -d v1
run dolt tag
[ $status -eq 0 ]
[ "$output" = "" ]
}
@test "commit_tags: checkout a tag" {
dolt branch comp HEAD^
dolt tag v1 HEAD^
skip "need to implelement detached head first"
run dolt checkout v1
[ $status -eq 0 ]
run dolt diff comp
[ $status -eq 0 ]
[ "$output" = "" ]
}
@test "commit_tags: commit onto checked out tag" {
dolt tag v1 HEAD^
skip "need to implement detached head first"
dolt checkout v1
run dolt sql -q "insert into test values (8),(9)"
[ $status -eq 0 ]
dolt add -A
run dolt commit -m "msg"
[ $status -eq 0 ]
}
@test "commit_tags: use a tag as ref for diff" {
dolt tag v1 HEAD^
run dolt diff v1
[ $status -eq 0 ]
[[ "$output" =~ "- | 0" ]]
[[ "$output" =~ "+ | 3" ]]
}
@test "commit_tags: use a tag as a ref for merge" {
dolt tag v1 HEAD
dolt checkout -b other HEAD^
dolt sql -q "insert into test values (8),(9)"
dolt add -A && dolt commit -m 'made changes'
run dolt merge v1
[ $status -eq 0 ]
run dolt sql -q "select * from test"
[ $status -eq 0 ]
[[ "$output" =~ "1" ]]
[[ "$output" =~ "2" ]]
[[ "$output" =~ "3" ]]
[[ "$output" =~ "8" ]]
[[ "$output" =~ "9" ]]
}
@test "commit_tags: push/pull tags to/from a remote" {
# reset env
rm -rf .dolt
mkdir repo remote
cd repo
dolt init
dolt sql -q "create table test (pk int primary key);"
dolt sql -q "insert into test values (0),(1),(2);"
dolt add -A && dolt commit -m "table test"
dolt sql -q "insert into test values (7),(8),(9);"
dolt add -A && dolt commit -m "more rows"
dolt remote add origin file://../remote
dolt push origin master
cd .. && dolt clone file://remote repo_clone && cd repo
run dolt tag v1 HEAD^
[ $status -eq 0 ]
run dolt tag v2 HEAD -m "SAMO"
[ $status -eq 0 ]
skip "todo"
run dolt push origin master
[ $status -eq 0 ]
cd ../repo_clone
run dolt pull
[ $status -eq 0 ]
run dolt tag
[ $status -eq 0 ]
[[ "$output" =~ "v1" ]] || false
[[ "$output" =~ "v2" ]] || false
run dolt tag -v
[ $status -eq 0 ]
[[ "$output" =~ "SAMO" ]] || false
}

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
teardown_common
}
@test "common: stashing, setting, and restoring dolt users" {
stash_current_dolt_user
[ "$STASHED_DOLT_USER_NAME" = "Bats Tests" ]
[ "$STASHED_DOLT_USER_EMAIL" = "bats@email.fake" ]
set_dolt_user "Bats Tests 1" "bats-1@email.fake"
NAME=`current_dolt_user_name`
EMAIL=`current_dolt_user_email`
[ "$NAME" = "Bats Tests 1" ]
[ "$EMAIL" = "bats-1@email.fake" ]
restore_stashed_dolt_user
NAME=`current_dolt_user_name`
EMAIL=`current_dolt_user_email`
[ "$NAME" = "Bats Tests" ]
[ "$EMAIL" = "bats@email.fake" ]
}

View File

@@ -0,0 +1,23 @@
## Compatibility Tests
These tests attempt to ensure forward and backward compatibility for Dolt versions.
The testing script `runner.sh` checks out and builds older Dolt release versions to ensure that they can read data from
newer repositories and vice-versa.
A test directory `/env_test` is created outside of source control to preserve the environment across
`git checkout` commands.
For each Dolt release version listed in `versions.txt`, `runner.sh` creates a legacy Dolt repository using the
`/test_files/setup_repo.sh` script in a directory named with the corresponding version.
An additional Dolt repository is created using Dolt built from the initial git branch.
BATS tests, located in `test_files/bats/`, are used to verify the forward and backward compatibility of all Dolt versions
and the repositories created with those versions.
### Updating
The BATS tests used to verify compatibility are inherently fragile.
Our primary integration tests in `/dolt/bats/` setup and tear down their environment for each test.
Because the tests rely on creating a repo with one version of Dolt and running BATS tests with a different version,
we cannot isolate their environment without building Dolt twice per test or setting up a different Dolt repo per test.
The initial version of these tests does all write operations in the `setup_repo.sh` script, and limits state modifications
within the BATS test to `dolt checkout` branch changes. Take care when editing the BATS tests to follow this pattern.

View File

@@ -0,0 +1,105 @@
#!/bin/bash
set -eo pipefail
function download_release() {
ver=$1
dirname=binaries/"$ver"
mkdir "$dirname"
basename=dolt-"$PLATFORM_TUPLE"
filename="$basename".tar.gz
filepath=binaries/"$ver"/"$filename"
url="https://github.com/dolthub/dolt/releases/download/$ver/$filename"
curl -L -o "$filepath" "$url"
cd "$dirname" && tar zxf "$filename"
echo "$dirname"/"$basename"/bin
}
get_platform_tuple() {
OS=$(uname)
ARCH=$(uname -m)
if [ "$OS" != Linux -a "$OS" != Darwin ]; then
echo "tests only support linux or macOS." 1>&2
exit 1
fi
if [ "$ARCH" != x86_64 -a "$ARCH" != i386 -a "$ARCH" != i686 ]; then
echo "tests only support x86_64 or x86." 1>&2
exit 1
fi
if [ "$OS" == Linux ]; then
PLATFORM_TUPLE=linux
else
PLATFORM_TUPLE=darwin
fi
if [ "$ARCH" == x86_64 ]; then
PLATFORM_TUPLE="$PLATFORM_TUPLE"-amd64
else
PLATFORM_TUPLE="$PLATFORM_TUPLE"-386
fi
echo "$PLATFORM_TUPLE"
}
PLATFORM_TUPLE=`get_platform_tuple`
function export_tables() {
dv=`dolt version`
echo "exporting tables with dolt version $dv"
for table in \
case_details \
cases \
characteristics_age \
characteristics_case_severity \
characteristics_comorbid_condition \
characteristics_occupation \
characteristics_onset_date_range \
characteristics_province \
characteristics_sex \
characteristics_wuhan_exposed \
dolt_query_catalog \
dolt_schemas \
places
do
dolt table export "$table" "$table$1.csv"
dolt sql -r csv -q "select * from $table" | sed 's/NULL//g' > "$table$1.sql.csv"
done
}
function diff_tables() {
for table in \
case_details \
cases \
characteristics_age \
characteristics_case_severity \
characteristics_comorbid_condition \
characteristics_occupation \
characteristics_onset_date_range \
characteristics_province \
characteristics_sex \
characteristics_wuhan_exposed \
dolt_query_catalog \
dolt_schemas \
places
do
diff "$table-pre.csv" "$table-post.csv"
diff "$table-pre.sql.csv" "$table-post.sql.csv"
done
}
function cleanup() {
popd
rm -rf binaries
rm -rf "corona-virus"
}
mkdir binaries
trap cleanup "EXIT"
bin=`download_release "v0.15.0"`
local_bin="`pwd`"/"$bin"
PATH="$local_bin":"$PATH" dolt clone Liquidata/corona-virus
pushd "corona-virus"
PATH="$local_bin":"$PATH" export_tables "-pre"
time dolt migrate
export_tables "-post"
diff_tables
echo "success!"

View File

@@ -0,0 +1,16 @@
load helper/windows-compat
if [ -z "$BATS_TMPDIR" ]; then
export BATS_TMPDIR=$HOME/batstmp/
mkdir $BATS_TMPDIR
fi
setup_common() {
echo "setup" > /dev/null
}
teardown_common() {
echo "teardown" > /dev/null
}
dolt config --global --add metrics.disabled true > /dev/null 2>&1

View File

@@ -0,0 +1,24 @@
nativepath() { echo "$1"; }
nativevar() { eval export "$1"="$2"; }
skiponwindows() { :; }
IS_WINDOWS=false
if [ -d /mnt/c/Windows/System32 ]; then
IS_WINDOWS=true
if [ ! -d /mnt/c/batstmp ]; then
mkdir /mnt/c/batstmp
fi
BATS_TMPDIR=`TMPDIR=/mnt/c/batstmp mktemp -d -t dolt-bats-tests-XXXXXX`
export BATS_TMPDIR
nativepath() {
wslpath -w "$1"
}
nativevar() {
eval export "$1"="$2"
export WSLENV="$1$3"
}
skiponwindows() {
skip "$1"
}
fi

View File

@@ -0,0 +1,69 @@
#!/bin/bash
set -eo pipefail
function download_release() {
ver=$1
dirname=binaries/"$ver"
mkdir "$dirname"
basename=dolt-"$PLATFORM_TUPLE"
filename="$basename".tar.gz
filepath=binaries/"$ver"/"$filename"
url="https://github.com/dolthub/dolt/releases/download/$ver/$filename"
curl -L -o "$filepath" "$url"
cd "$dirname" && tar zxf "$filename"
echo "$dirname"/"$basename"/bin
}
get_platform_tuple() {
OS=$(uname)
ARCH=$(uname -m)
if [ "$OS" != Linux -a "$OS" != Darwin ]; then
echo "tests only support linux or macOS." 1>&2
exit 1
fi
if [ "$ARCH" != x86_64 -a "$ARCH" != i386 -a "$ARCH" != i686 ]; then
echo "tests only support x86_64 or x86." 1>&2
exit 1
fi
if [ "$OS" == Linux ]; then
PLATFORM_TUPLE=linux
else
PLATFORM_TUPLE=darwin
fi
if [ "$ARCH" == x86_64 ]; then
PLATFORM_TUPLE="$PLATFORM_TUPLE"-amd64
else
PLATFORM_TUPLE="$PLATFORM_TUPLE"-386
fi
echo "$PLATFORM_TUPLE"
}
PLATFORM_TUPLE=`get_platform_tuple`
setup_test_repos() {
./setup_repo.sh "$1"
mkdir "$1-remote"
pushd "$1"
dolt remote add origin "file://../$1-remote"
# branches created in setup_repo.sh
dolt push origin init
dolt push origin master
dolt push origin other
popd
dolt clone "file://$1-remote" "$1-clone"
}
TOP_DIR=`pwd`
function cleanup() {
pushd $TOP_DIR
rm -rf binaries
rm -rf repo*
popd
}
mkdir binaries
trap cleanup "EXIT"
bin=`download_release "v0.15.2"`
PATH="`pwd`"/"$bin":"$PATH" setup_test_repos "repo"
TEST_REPO="repo" bats migrate.bats

View File

@@ -0,0 +1,59 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
teardown_common
}
@test "dolt migrate --push & dolt migrate --pull" {
pushd "$TEST_REPO"
run dolt migrate --pull
[ "$status" -ne "0" ]
[[ "$output" =~ "Local repo must be migrated before pulling, run 'dolt migrate'" ]] || false
run dolt migrate --push
[ "$status" -ne "0" ]
[[ "$output" =~ "Local repo must be migrated before pushing, run 'dolt migrate'" ]] || false
run dolt migrate
[ "$status" -eq "0" ]
[[ "$output" =~ "Migrating repository to the latest format" ]] || false
run dolt migrate --pull
[ "$status" -ne "0" ]
[[ "$output" =~ "Remote origin has not been migrated" ]] || false
[[ "$output" =~ "Run 'dolt migrate --push origin' to push migration" ]] || false
run dolt migrate --push
[ "$status" -eq "0" ]
popd
pushd "$TEST_REPO-clone"
run dolt migrate --pull
[ "$status" -ne "0" ]
[[ "$output" =~ "Local repo must be migrated before pulling, run 'dolt migrate'" ]] || false
run dolt migrate --push
[ "$status" -ne "0" ]
[[ "$output" =~ "Local repo must be migrated before pushing, run 'dolt migrate'" ]] || false
run dolt migrate
[ "$status" -eq "0" ]
[[ "$output" =~ "Migrating repository to the latest format" ]] || false
run dolt migrate --push
[ "$status" -ne "0" ]
[[ "$output" =~ "Remote origin has been migrated" ]] || false
[[ "$output" =~ "Run 'dolt migrate --pull' to update refs" ]] || false
run dolt migrate --pull
[ "$status" -eq "0" ]
popd
}

View File

@@ -0,0 +1,67 @@
#!/bin/bash
set -eo pipefail
mkdir "$1"
cd "$1"
dolt init
dolt sql <<SQL
CREATE TABLE abc (
pk BIGINT NOT NULL COMMENT 'tag:0',
a LONGTEXT COMMENT 'tag:100',
b DOUBLE COMMENT 'tag:101',
w BIGINT COMMENT 'tag:102',
x BIGINT COMMENT 'tag:103',
PRIMARY KEY (pk)
);
INSERT INTO abc VALUES (0, 'asdf', 1.1, 0, 0);
INSERT INTO abc VALUES (1, 'asdf', 1.1, 0, 0);
INSERT INTO abc VALUES (2, 'asdf', 1.1, 0, 0);
SQL
dolt add .
dolt commit -m "initialized data"
dolt branch init
dolt branch other
dolt sql <<SQL
DELETE FROM abc WHERE pk=1;
INSERT INTO abc VALUES (3, 'data', 1.1, 0, 0);
ALTER TABLE abc DROP COLUMN w;
ALTER TABLE abc ADD COLUMN y BIGINT COMMENT 'tag:104';
SQL
dolt add .
dolt commit -m "made changes to master"
dolt checkout other
dolt sql <<SQL
DELETE FROM abc WHERE pk=2;
INSERT INTO abc VALUES (4, 'data', 1.1, 0, 0);
ALTER TABLE abc DROP COLUMN x;
ALTER TABLE abc ADD COLUMN z BIGINT COMMENT 'tag:105';
SQL
dolt add .
dolt commit -m "made changes to other"
dolt checkout master
dolt table export abc abc.csv
dolt schema export abc abc_schema.json
# add info to the log
echo
echo "dolt status"
dolt status
echo
echo "dolt branch"
dolt branch
echo
echo "dolt schema show"
dolt schema show
echo
echo "dolt sql -q 'select * from abc;'"
dolt sql -q 'select * from abc;'

View File

@@ -0,0 +1,76 @@
#!/bin/bash
set -eo pipefail
function download_release() {
ver=$1
dirname=binaries/"$ver"
mkdir "$dirname"
basename=dolt-"$PLATFORM_TUPLE"
filename="$basename".tar.gz
filepath=binaries/"$ver"/"$filename"
url="https://github.com/dolthub/dolt/releases/download/$ver/$filename"
curl -L -o "$filepath" "$url"
cd "$dirname" && tar zxf "$filename"
echo "$dirname"/"$basename"/bin
}
get_platform_tuple() {
OS=$(uname)
ARCH=$(uname -m)
if [ "$OS" != Linux -a "$OS" != Darwin ]; then
echo "tests only support linux or macOS." 1>&2
exit 1
fi
if [ "$ARCH" != x86_64 -a "$ARCH" != i386 -a "$ARCH" != i686 ]; then
echo "tests only support x86_64 or x86." 1>&2
exit 1
fi
if [ "$OS" == Linux ]; then
PLATFORM_TUPLE=linux
else
PLATFORM_TUPLE=darwin
fi
if [ "$ARCH" == x86_64 ]; then
PLATFORM_TUPLE="$PLATFORM_TUPLE"-amd64
else
PLATFORM_TUPLE="$PLATFORM_TUPLE"-386
fi
echo "$PLATFORM_TUPLE"
}
PLATFORM_TUPLE=`get_platform_tuple`
function list_dolt_versions() {
grep -v '^ *#' < test_files/dolt_versions.txt
}
function cleanup() {
rm -rf repos binaries
}
mkdir repos binaries
trap cleanup "EXIT"
function setup_repo() {
dir=repos/"$1"
./test_files/setup_repo.sh "$dir"
}
setup_repo HEAD
function test_dolt_version() {
ver=$1
bin=`download_release "$ver"`
echo testing "$ver" at "$bin"
PATH="`pwd`"/"$bin":"$PATH" setup_repo "$ver"
# Run the bats tests with old dolt version hitting repositories from new dolt version
PATH="`pwd`"/"$bin":"$PATH" REPO_DIR="`pwd`"/repos/HEAD bats ./test_files/bats
# Run the bats tests with new dolt version hitting repositories from old dolt version
REPO_DIR="`pwd`"/repos/"$ver" bats ./test_files/bats
}
list_dolt_versions | while IFS= read -r ver; do
test_dolt_version "$ver"
done

View File

@@ -0,0 +1,196 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
cp -Rpf $REPO_DIR bats_repo
cd bats_repo
}
teardown() {
teardown_common
cd ..
rm -rf bats_repo
}
@test "dolt version" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
run dolt version
[ "$status" -eq 0 ]
regex='dolt version [0-9]+.[0-9]+.[0-9]+'
[[ "$output" =~ $regex ]] || false
}
@test "dolt status" {
skip "These compatibility tests fail now due to a backwards incompatibility with the dolt_docs table. Before v0.16.0 dolt_docs used tags 0 and 1, and these values were hard coded in the logic that syncs the docs table with the file system."
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch master" ]] || false
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
}
@test "dolt ls" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
run dolt ls
[ "$status" -eq 0 ]
[[ "${lines[0]}" =~ "Tables in working set:" ]] || false
}
@test "dolt branch" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
run dolt branch
[ "$status" -eq 0 ]
}
@test "dolt diff" {
skip "These compatibility tests fail now due to a backwards incompatibility with the dolt_docs table. Before v0.16.0 dolt_docs used tags 0 and 1, and these values were hard coded in the logic that syncs the docs table with the file system."
run dolt diff
[ "$status" -eq 0 ]
}
@test "dolt schema show on branch init" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
dolt checkout init
run dolt schema show abc
[ "$status" -eq 0 ]
output=`echo $output | tr '[:upper:]' '[:lower:]'` # lowercase the output
[[ "${output}" =~ "abc @ working" ]] || false
[[ "${output}" =~ "create table \`abc\` (" ]] || false
[[ "${output}" =~ "\`pk\` bigint not null" ]] || false
[[ "${output}" =~ "\`a\` longtext" ]] || false
[[ "${output}" =~ "\`b\` double" ]] || false
[[ "${output}" =~ "\`w\` bigint" ]] || false
[[ "${output}" =~ "\`x\` bigint" ]] || false
[[ "${output}" =~ "primary key (\`pk\`)" ]] || false
}
@test "dolt sql 'select * from abc' on branch init" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
dolt checkout init
run dolt sql -q 'select * from abc;'
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "| pk | a | b | w | x |" ]] || false
[[ "${lines[2]}" =~ "+----+------+-----+---+---+" ]] || false
[[ "${lines[3]}" =~ "| 0 | asdf | 1.1 | 0 | 0 |" ]] || false
[[ "${lines[4]}" =~ "| 1 | asdf | 1.1 | 0 | 0 |" ]] || false
[[ "${lines[5]}" =~ "| 2 | asdf | 1.1 | 0 | 0 |" ]] || false
}
@test "dolt schema show on branch master" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
run dolt schema show abc
[ "$status" -eq 0 ]
output=`echo $output | tr '[:upper:]' '[:lower:]'` # lowercase the output
[[ "${output}" =~ "abc @ working" ]] || false
[[ "${output}" =~ "create table \`abc\` (" ]] || false
[[ "${output}" =~ "\`pk\` bigint not null" ]] || false
[[ "${output}" =~ "\`a\` longtext" ]] || false
[[ "${output}" =~ "\`b\` double" ]] || false
[[ "${output}" =~ "\`x\` bigint" ]] || false
[[ "${output}" =~ "\`y\` bigint" ]] || false
[[ "${output}" =~ "primary key (\`pk\`)" ]] || false
}
@test "dolt sql 'select * from abc' on branch master" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
run dolt sql -q 'select * from abc;'
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "| pk | a | b | x | y |" ]] || false
[[ "${lines[2]}" =~ "+----+------+-----+---+-----+" ]] || false
[[ "${lines[3]}" =~ "| 0 | asdf | 1.1 | 0 | 121 |" ]] || false
[[ "${lines[4]}" =~ "| 2 | asdf | 1.1 | 0 | 121 |" ]] || false
[[ "${lines[5]}" =~ "| 3 | data | 1.1 | 0 | 121 |" ]] || false
}
@test "dolt schema show on branch other" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
dolt checkout other
run dolt schema show abc
[ "$status" -eq 0 ]
echo $output
output=`echo $output | tr '[:upper:]' '[:lower:]'` # lowercase the output
[[ "${output}" =~ "abc @ working" ]] || false
[[ "${output}" =~ "create table \`abc\` (" ]] || false
[[ "${output}" =~ "\`pk\` bigint not null" ]] || false
[[ "${output}" =~ "\`a\` longtext" ]] || false
[[ "${output}" =~ "\`b\` double" ]] || false
[[ "${output}" =~ "\`w\` bigint" ]] || false
[[ "${output}" =~ "\`z\` bigint" ]] || false
[[ "${output}" =~ "primary key (\`pk\`)" ]] || false
}
@test "dolt sql 'select * from abc' on branch other" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
dolt checkout other
run dolt sql -q 'select * from abc;'
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "| pk | a | b | w | z |" ]] || false
[[ "${lines[2]}" =~ "+----+------+-----+---+-----+" ]] || false
[[ "${lines[3]}" =~ "| 0 | asdf | 1.1 | 0 | 122 |" ]] || false
[[ "${lines[4]}" =~ "| 1 | asdf | 1.1 | 0 | 122 |" ]] || false
[[ "${lines[5]}" =~ "| 4 | data | 1.1 | 0 | 122 |" ]] || false
dolt checkout master
}
@test "dolt table import" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
run dolt table import -c -pk=pk abc2 abc.csv
[ "$status" -eq 0 ]
[[ "$output" =~ "Import completed successfully." ]] || false
dolt sql -q 'drop table abc2'
}
@test "dolt migrate no-data" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
dolt checkout no-data
run dolt sql -q 'show tables;'
[ "$status" -eq 0 ]
[[ "$output" =~ "+-------+" ]] || false
[[ "$output" =~ "| Table |" ]] || false
[[ "$output" =~ "+-------+" ]] || false
[[ "$output" =~ "+-------+" ]] || false
}
@test "dolt_schemas" {
# this will fail for older dolt versions but BATS will swallow the error
run dolt migrate
run dolt sql -q "select * from dolt_schemas"
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "| type | name | fragment |" ]] || false
[[ "${lines[2]}" =~ "+------+-------+----------------------+" ]] || false
[[ "${lines[3]}" =~ "| view | view1 | SELECT 2+2 FROM dual |" ]] || false
run dolt sql -q 'select * from view1'
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "| 2 + 2 |" ]] || false
[[ "${lines[2]}" =~ "+-------+" ]] || false
[[ "${lines[3]}" =~ "| 4 |" ]] || false
}

View File

@@ -0,0 +1,16 @@
load helper/windows-compat
if [ -z "$BATS_TMPDIR" ]; then
export BATS_TMPDIR=$HOME/batstmp/
mkdir $BATS_TMPDIR
fi
setup_common() {
echo "setup" > /dev/null
}
teardown_common() {
echo "teardown" > /dev/null
}
dolt config --global --add metrics.disabled true > /dev/null 2>&1

View File

@@ -0,0 +1,24 @@
nativepath() { echo "$1"; }
nativevar() { eval export "$1"="$2"; }
skiponwindows() { :; }
IS_WINDOWS=false
if [ -d /mnt/c/Windows/System32 ]; then
IS_WINDOWS=true
if [ ! -d /mnt/c/batstmp ]; then
mkdir /mnt/c/batstmp
fi
BATS_TMPDIR=`TMPDIR=/mnt/c/batstmp mktemp -d -t dolt-bats-tests-XXXXXX`
export BATS_TMPDIR
nativepath() {
wslpath -w "$1"
}
nativevar() {
eval export "$1"="$2"
export WSLENV="$1$3"
}
skiponwindows() {
skip "$1"
}
fi

View File

@@ -0,0 +1,11 @@
v0.13.0
v0.14.0
v0.15.0
v0.16.0
v0.17.0
v0.18.0
v0.19.0
v0.20.0
v0.21.0
v0.22.0
v0.22.7

View File

@@ -0,0 +1,76 @@
#!/bin/bash
set -eo pipefail
mkdir "$1"
cd "$1"
dolt init
dolt branch no-data
dolt sql <<SQL
CREATE TABLE abc (
pk BIGINT NOT NULL,
a LONGTEXT,
b DOUBLE,
w BIGINT,
x BIGINT,
PRIMARY KEY (pk)
);
INSERT INTO abc VALUES (0, 'asdf', 1.1, 0, 0);
INSERT INTO abc VALUES (1, 'asdf', 1.1, 0, 0);
INSERT INTO abc VALUES (2, 'asdf', 1.1, 0, 0);
CREATE VIEW view1 AS SELECT 2+2 FROM dual;
SQL
dolt add .
dolt commit -m "initialized data"
dolt branch init
dolt branch other
dolt sql <<SQL
DELETE FROM abc WHERE pk=1;
INSERT INTO abc VALUES (3, 'data', 1.1, 0, 0);
ALTER TABLE abc DROP COLUMN w;
ALTER TABLE abc ADD COLUMN y BIGINT;
UPDATE abc SET y = 121;
SQL
dolt add .
dolt commit -m "made changes to master"
dolt checkout other
dolt sql <<SQL
DELETE FROM abc WHERE pk=2;
INSERT INTO abc VALUES (4, 'data', 1.1, 0, 0);
ALTER TABLE abc DROP COLUMN x;
ALTER TABLE abc ADD COLUMN z BIGINT;
UPDATE abc SET z = 122;
SQL
dolt add .
dolt commit -m "made changes to other"
dolt checkout master
dolt table export abc abc.csv
dolt schema export abc abc_schema.json
# add info to the log
echo
echo "dolt status"
dolt status
echo
echo "dolt branch"
dolt branch
echo
echo "dolt schema show"
dolt schema show
echo
echo "dolt sql -q 'select * from abc;'"
dolt sql -q 'select * from abc;'
echo
echo "dolt_schemas"
dolt sql -q "select * from dolt_schemas"

View File

@@ -0,0 +1,166 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_no_dolt_init
mkdir $BATS_TMPDIR/config-test$$
nativevar DOLT_ROOT_PATH $BATS_TMPDIR/config-test$$ /p
cd $BATS_TMPDIR/dolt-repo-$$
}
teardown() {
teardown_common
rm -rf "$BATS_TMPDIR/config-test$$"
}
@test "config: make sure no dolt configuration for simulated fresh user" {
run dolt config --list
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
@test "config: try to initialize a repository with no configuration" {
run dolt init
[ "$status" -eq 1 ]
[[ "$output" =~ "Could not determine user.name" ]] || false
}
@test "config: set a global config variable" {
run dolt config --global --add test test
[ "$status" -eq 0 ]
# Need to make this a regex because of the coloring
[[ "$output" =~ "Config successfully updated" ]] || false
[ -f `nativepath ~/.dolt/config_global.json` ]
run dolt config --list
[ "$status" -eq 0 ]
[ "$output" = "test = test" ]
run dolt config --get test
[ "$status" -eq 0 ]
[ "$output" = "test" ]
run dolt config --global --add test
[ "$status" -eq 1 ]
[[ "$output" =~ "wrong number of arguments" ]] || false
run dolt config --global --add
[ "$status" -eq 1 ]
[[ "$output" =~ "wrong number of arguments" ]] || false
}
@test "config: delete a config variable" {
dolt config --global --add test test
run dolt config --global --unset test
[ "$status" -eq 0 ]
[[ "$output" =~ "Config successfully updated" ]] || false
run dolt config --list
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt config --get test
[ "$status" -eq 1 ]
[ "$output" = "" ]
}
@test "config: set and delete multiple config variables" {
dolt config --global --add test1 test1
dolt config --global --add test2 test2
dolt config --global --add test3 test3
run dolt config --list
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 3 ]
run dolt config --global --unset test1 test2 test3
[ "$status" -eq 0 ]
[[ "$output" =~ "Config successfully updated" ]]
run dolt config --list
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
@test "config: set a user and email and init a repo" {
dolt config --global --add user.name "bats tester"
run dolt init
[ "$status" -eq 1 ]
[[ "$output" =~ "Could not determine user.email" ]] || false
dolt config --global --add user.email "bats-tester@liquidata.co"
run dolt init
[ "$status" -eq 0 ]
[[ "$output" =~ "Successfully initialized dolt data repository." ]] || false
}
@test "config: set a local config variable" {
dolt config --global --add user.name "bats tester"
dolt config --global --add user.email "bats-tester@liquidata.co"
dolt init
run dolt config --local --add testlocal testlocal
[ "$status" -eq 0 ]
[[ "$output" =~ "Config successfully updated" ]] || false
[ -f .dolt/config.json ]
run dolt config --list
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 3 ]
[[ "$output" =~ "testlocal = testlocal" ]] || false
run dolt config --get testlocal
[ "$status" -eq 0 ]
[ "$output" = "testlocal" ]
}
@test "config: override a global config variable with a local config variable" {
dolt config --global --add user.name "bats tester"
dolt config --global --add user.email "bats-tester@liquidata.co"
dolt init
dolt config --global --add test global
dolt config --local --add test local
run dolt config --local --get test
[ "$status" -eq 0 ]
[ "$output" = "local" ]
# will list both global and local values in list output
run dolt config --list
[ "$status" -eq 0 ]
[[ "$output" =~ "test = local" ]] || false
[[ "$output" =~ "test = global" ]] || false
# will get the local value explicitly
run dolt config --get --local test
[ "$status" -eq 0 ]
[[ "$output" =~ "local" ]] || false
[[ ! "$output" =~ "global" ]] || false
# will get the global value explicitly
run dolt config --get --global test
[ "$status" -eq 0 ]
[[ "$output" =~ "global" ]] || false
[[ ! "$output" =~ "local" ]] || false
# will get the local value implicitly
run dolt config --get test
[ "$status" -eq 0 ]
[[ "$output" =~ "local" ]] || false
[[ ! "$output" =~ "global" ]] || false
}
@test "config: Commit to repo w/ ---author and without config vars sets" {
dolt config --global --add user.name "bats tester"
dolt config --global --add user.email "joshn@doe.com"
dolt init
dolt sql -q "
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)
);"
dolt config --global --unset user.name
dolt config --global --unset user.email
run dolt config --list
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
dolt add .
run dolt commit --author="John Doe <john@doe.com>" -m="Commit1"
[ "$status" -eq 0 ]
run dolt log
[ "$status" -eq 0 ]
regex='John Doe <john@doe.com>'
[[ "$output" =~ "$regex" ]] || false
}

View File

@@ -0,0 +1,979 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
teardown_common
}
@test "conflict-detection: merge non-existant branch errors" {
run dolt merge batmans-parents
[ $status -eq 1 ]
[[ "$output" =~ "unknown branch" ]] || false
[[ ! "$output" =~ "panic" ]] || false
}
@test "conflict-detection: cannot merge into dirty working table" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "table created"
dolt checkout -b other
dolt sql -q "replace into test values (1, 1, 1, 1, 1, 11)"
dolt add test
dolt commit -m "changed pk=1 c5 to 11"
dolt checkout master
dolt sql -q "replace into test values (0, 11, 0, 0, 0, 0)"
run dolt merge other
[ "$status" -ne 0 ]
[[ "$output" =~ "error: Your local changes to the following tables would be overwritten by merge:" ]] || false
[[ "$output" =~ "test" ]] || false
[[ "$output" =~ "Please commit your changes before you merge." ]] || false
dolt add test
dolt commit -m "changes pk=0 c1 t0 11"
run dolt merge other
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ "$output" =~ "1 tables changed" ]] || false
[[ "$output" =~ "1 rows modified" ]] || false
}
@test "conflict-detection: two branches modify different cell different row. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "table created"
dolt branch change-cell
dolt sql -q "replace into test values (0, 11, 0, 0, 0, 0)"
dolt add test
dolt commit -m "changed pk=0 c1 to 11"
dolt checkout change-cell
dolt sql -q "replace into test values (1, 1, 1, 1, 1, 11)"
dolt add test
dolt commit -m "changed pk=1 c5 to 11"
dolt checkout master
run dolt merge change-cell
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ "$output" =~ "1 tables changed" ]] || false
[[ "$output" =~ "1 rows modified" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
run dolt status
[[ "$output" =~ "All conflicts fixed" ]] || false
[[ "$output" =~ "Changes to be committed:" ]] || false
}
@test "conflict-detection: two branches modify different cell same row. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt add test
dolt commit -m "table created"
dolt branch change-cell
dolt sql -q "replace into test values (0, 11, 0, 0, 0, 0)"
dolt add test
dolt commit -m "changed pk=0 c1 to 11"
dolt checkout change-cell
dolt sql -q "replace into test values (0, 0, 0, 0, 0, 11)"
dolt add test
dolt commit -m "changed pk=0 c5 to 11"
dolt checkout master
run dolt merge change-cell
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ "$output" =~ "1 tables changed" ]] || false
[[ "$output" =~ "1 rows modified" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
run dolt status
[[ "$output" =~ "All conflicts fixed" ]] || false
[[ "$output" =~ "Changes to be committed:" ]] || false
}
@test "conflict-detection: two branches modify same cell. merge. conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt add test
dolt commit -m "table created"
dolt branch change-cell
dolt sql -q "replace into test values (0, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "changed pk=0 all cells to 1"
dolt checkout change-cell
dolt sql -q "replace into test values (0, 11, 11, 11, 11, 11)"
dolt add test
dolt commit -m "changed pk=0 all cells to 11"
dolt checkout master
run dolt merge change-cell
[ "$status" -eq 0 ]
[[ "$output" =~ "CONFLICT" ]] || false
run dolt status
[[ "$output" =~ "You have unmerged tables." ]] || false
[[ "$output" =~ "Unmerged paths:" ]] || false
}
@test "conflict-detection: two branches add a different row. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt add test
dolt commit -m "table created"
dolt branch add-row
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt add test
dolt commit -m "added pk=0 row"
dolt checkout add-row
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "added pk=1 row"
dolt checkout master
run dolt merge add-row
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ "$output" =~ "1 tables changed" ]] || false
[[ "$output" =~ "1 rows added" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches add same row. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt add test
dolt commit -m "table created"
dolt branch add-row
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt add test
dolt commit -m "added pk=0 row"
dolt checkout add-row
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt add test
dolt commit -m "added pk=0 row"
dolt checkout master
run dolt merge add-row
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: one branch add table, other modifies table. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt add test
dolt commit -m "table created"
dolt branch add-table
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt add test
dolt commit -m "added row"
dolt checkout add-table
dolt sql <<SQL
CREATE TABLE test2 (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt add test2
dolt commit -m "added new table test2"
dolt checkout master
run dolt merge add-table
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
skip "should have a merge summary section that says 1 table changed"
[[ "$output" =~ "1 tables changed" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches add same column. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt add test
dolt commit -m "table created"
dolt branch add-column
dolt sql -q "alter table test add c0 bigint"
dolt add test
dolt commit -m "added column c0"
dolt checkout add-column
dolt sql -q "alter table test add c0 bigint"
dolt add test
dolt commit -m "added same column c0"
dolt checkout master
run dolt merge add-column
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches add different column. merge. no conflict" {
skip https://github.com/dolthub/dolt/issues/773
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt sql -q 'insert into test (pk, c1, c2, c3, c4, c5) values (0,1,2,3,4,5);'
dolt add test
dolt commit -m "table created"
dolt branch add-column
dolt sql -q "alter table test add c0 bigint"
dolt add test
dolt commit -m "added column c0"
dolt checkout add-column
dolt sql -q "alter table test add c6 bigint"
dolt add test
dolt commit -m "added column c6"
dolt checkout master
run dolt merge add-column
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ "$output" =~ "1 tables changed" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
run dolt sql -q 'select * from test;'
[ $status -eq 0 ]
[[ "${lines[3]}" =~ "| 0 | 1 | 2 | 3 | 4 | 5 | NULL | NULL |" ]] || false
}
@test "conflict-detection: two branches add same column, different types. merge. conflict" {
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
dolt add test
dolt commit -m "table created"
dolt branch add-column
dolt sql -q "alter table test add c0 longtext"
dolt add test
dolt commit -m "added column c0 as string"
dolt checkout add-column
dolt sql -q "alter table test add c0 bigint"
dolt add test
dolt commit -m "added column c0 as int"
dolt checkout master
skip "This created two c0 columns with different types and tag numbers. Bug I think."
run dolt merge add-column
[ $status -eq 0 ]
[[ "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches delete same column. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt add test
dolt commit -m "table created"
dolt branch delete-column
dolt sql -q "alter table test drop column c5"
dolt add test
dolt commit -m "deleted c5 column"
dolt checkout delete-column
dolt sql -q "alter table test drop column c5"
dolt add test
dolt commit -m "deleted c5 again"
dolt checkout master
run dolt merge delete-column
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches delete different column. merge. no conflict" {
skip https://github.com/dolthub/dolt/issues/773
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
dolt add test
dolt commit -m "table created"
dolt checkout -b one
dolt sql -q "alter table test drop column c5"
dolt add test
dolt commit -m "deleted column c5"
dolt checkout master
dolt checkout -b two
dolt sql -q "alter table test drop column c4"
dolt add test
dolt commit -m "deleted column c4"
run dolt merge one
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
run dolt schema show
[[ "${lines[0]}" =~ "test @ working" ]] || false
[[ "${lines[1]}" =~ "CREATE TABLE \`test\` (" ]] || false
[[ "${lines[2]}" =~ "\`pk\` BIGINT NOT NULL COMMENT 'tag:0'," ]] || false
[[ "${lines[3]}" =~ "\`c1\` BIGINT COMMENT 'tag:1'," ]] || false
[[ "${lines[4]}" =~ "\`c2\` BIGINT COMMENT 'tag:2'," ]] || false
[[ "${lines[5]}" =~ "\`c3\` BIGINT COMMENT 'tag:3'," ]] || false
[[ "${lines[6]}" =~ "PRIMARY KEY (\`pk\`)" ]] || false
[[ "${lines[7]}" =~ ");" ]] || false
}
@test "conflict-detection: two branches rename same column to same name. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt add test
dolt commit -m "table created"
dolt branch rename-column
dolt sql -q "alter table test rename column c5 to c0"
dolt add test
dolt commit -m "renamed c5 to c0"
dolt checkout rename-column
dolt sql -q "alter table test rename column c5 to c0"
dolt add test
dolt commit -m "renamed c5 to c0 again"
dolt checkout master
run dolt merge rename-column
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches rename same column to different name. merge. conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
skip "This currently is a failed merge. I think it should be a conflict that you can resolve by modifying the schema. Basically choose a column name for the tag. The data is the same."
dolt add test
dolt commit -m "table created"
dolt branch rename-column
dolt sql -q "alter table test rename column c5 to c0"
dolt add test
dolt commit -m "renamed c5 to c0"
dolt checkout rename-column
dolt sql -q "alter table test rename column c5 to c6"
dolt add test
dolt commit -m "renamed c5 to c6"
dolt checkout master
run dolt merge rename-column
[ $status -eq 1 ]
[[ "$output" =~ "Bad merge" ]] || false
[ $status -eq 0 ]
[[ "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches rename different column to same name. merge. conflict" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
skip "Same as test above. This case needs some thought. My initial instinct was that this generates a tag conflict. Pick one tag and then you have a data conflict because the schemas are the same on both branches."
dolt add test
dolt commit -m "table created"
dolt branch rename-column
dolt sql -q "alter table test rename column c5 to c0"
dolt add test
dolt commit -m "renamed c5 to c0"
dolt checkout rename-column
dolt sql -q "alter table test rename column c4 to c0"
dolt add test
dolt commit -m "renamed c5 to c6"
dolt checkout master
run dolt merge rename-column
[ $status -eq 1 ]
[[ "$output" =~ "Bad merge" ]] || false
[ $status -eq 0 ]
[[ "$output" =~ "CONFLICT" ]] || false
}
# Altering types and properties of the schema are not really supported by the
# command line. Have to upload schema files for these next few tests.
@test "conflict-detection: two branches change type of same column to same type. merge. no conflict" {
skip "type changes are not allowed without changing tag"
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
dolt add test
dolt commit -m "table created"
dolt branch change-types
dolt table rm test
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT UNSIGNED 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
dolt add test
dolt commit -m "changed c1 to type uint"
dolt checkout change-types
dolt table rm test
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT UNSIGNED 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
dolt add test
dolt commit -m "changed c1 to type uint again"
dolt checkout master
run dolt merge change-types
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches change type of same column to different type. merge. conflict" {
skip "type changes are not allowed without changing tag"
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
dolt add test
dolt commit -m "table created"
dolt branch change-types
dolt table rm test
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT UNSIGNED 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
dolt add test
dolt commit -m "changed c1 to type uint"
dolt checkout change-types
dolt table rm test
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 DOUBLE 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
skip "I think changing a type to two different types should throw a conflict"
dolt add test
dolt commit -m "changed c1 to type float"
dolt checkout master
run dolt merge change-types
[ $status -eq 1 ]
[[ "$output" =~ "Bad merge" ]] || false
[ $status -eq 0 ]
[[ "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches make same column primary key. merge. no conflict" {
skip "cannot resuse tags on table drop/add"
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
dolt add test
dolt commit -m "table created"
dolt branch add-pk
dolt table rm test
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,c1)
);
SQL
dolt add test
dolt commit -m "made c1 a pk"
dolt checkout add-pk
dolt table rm test
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,c1)
);
SQL
dolt add test
dolt commit -m "made c1 a pk again"
dolt checkout master
run dolt merge add-pk
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches add same primary key column. merge. no conflict" {
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
dolt add test
dolt commit -m "table created"
dolt branch add-pk
dolt table rm test
skip "cannot add change primary keys"
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
pk1 BIGINT NOT NULL COMMENT 'tag:6',
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,pk1)
);
SQL
dolt add test
dolt commit -m "added pk pk1"
dolt checkout add-pk
dolt table rm test
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
pk1 BIGINT NOT NULL COMMENT 'tag:6',
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,pk1)
);
SQL
dolt add test
dolt commit -m "added pk pk1 again"
dolt checkout master
run dolt merge add-pk
[ $status -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches make different columns primary key. merge. conflict" {
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
dolt add test
dolt commit -m "table created"
dolt branch add-pk
dolt table rm test
skip "cannot change primary keys"
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
pk1 BIGINT NOT NULL COMMENT 'tag:6',
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,pk1)
);
SQL
dolt add test
dolt commit -m "added pk pk1"
dolt checkout add-pk
dolt table rm test
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
pk2 BIGINT NOT NULL COMMENT 'tag:7',
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,pk2)
);
SQL
dolt add test
dolt commit -m "added pk pk2"
dolt checkout master
run dolt merge add-pk
[ $status -eq 0 ]
skip "This merges fine right now. Should throw conflict."
[[ "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches both create different tables. merge. no conflict" {
dolt branch table1
dolt branch table2
dolt checkout table1
dolt sql <<SQL
CREATE TABLE table1 (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt add table1
dolt commit -m "first table"
dolt checkout table2
dolt sql <<SQL
CREATE TABLE table2 (
pk1 BIGINT NOT NULL,
pk2 BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk1,pk2)
);
SQL
dolt add table2
dolt commit -m "second table"
dolt checkout master
run dolt merge table1
[ "$status" -eq 0 ]
[[ "$output" =~ "Fast-forward" ]] || false
run dolt merge table2
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches drop different tables. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE foo (
pk BIGINT NOT NULL PRIMARY KEY
);
CREATE TABLE bar (
pk BIGINT NOT NULL PRIMARY KEY
);
SQL
dolt add .
dolt commit -m "created two tables"
dolt branch other
dolt sql -q 'drop table foo'
dolt add .
dolt commit -m "dropped table foo"
dolt checkout other
dolt sql -q 'drop table bar'
dolt add .
dolt commit -m "dropped table bar"
dolt checkout master
skip "test currently panics on merge at doltcore/env/actions/merge.go:79"
run dolt merge other
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branch rename different tables. merge. no conflict" {
dolt sql <<SQL
CREATE TABLE foo (
pk BIGINT NOT NULL PRIMARY KEY
);
CREATE TABLE bar (
pk BIGINT NOT NULL PRIMARY KEY
);
SQL
dolt add .
dolt commit -m "created two tables"
dolt branch other
dolt sql -q 'alter table foo rename to foofoo;'
dolt add .
dolt commit -m "renamed table foo to foofoo"
dolt checkout other
dolt sql -q 'alter table bar rename to barbar'
dolt add .
dolt commit -m "renamed table bar to barbar"
dolt checkout master
skip "test currently panics on merge at doltcore/env/actions/merge.go:79"
run dolt merge other
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating" ]] || false
[[ ! "$output" =~ "CONFLICT" ]] || false
}
@test "conflict-detection: two branches, one deletes rows, one modifies those same rows. merge. conflict" {
dolt sql <<SQL
CREATE TABLE foo (
pk INT PRIMARY KEY,
val INT
);
INSERT INTO foo VALUES (1, 1), (2, 1), (3, 1), (4, 1), (5, 1);
SQL
dolt add foo
dolt commit -m 'initial commit.'
dolt checkout -b deleter
dolt sql -q 'delete from foo'
dolt add foo
dolt commit -m 'delete commit.'
dolt checkout -b modifier master
dolt sql -q 'update foo set val = val + 1 where pk in (1, 3, 5);'
dolt add foo
dolt commit -m 'modify commit.'
dolt checkout -b merge-into-modified modifier
run dolt merge deleter
[ "$status" -eq 0 ]
[[ "$output" =~ "CONFLICT" ]] || false
dolt merge --abort
# Accept theirs deletes all rows.
dolt checkout master
dolt branch -d -f merge-into-modified
dolt checkout -b merge-into-modified modifier
dolt merge deleter
# Test resolve nonexistant key
run dolt conflicts resolve foo 999
[ "$status" -eq 1 ]
[[ "$output" =~ "not the primary key of a conflicting row" ]] || false
dolt conflicts resolve --theirs foo
run dolt sql -q 'select count(*) from foo'
[ "$status" -eq 0 ]
[[ "$output" =~ "| 0 |" ]] || false
dolt merge --abort
dolt reset --hard
# Accept ours deletes two rows.
dolt checkout master
dolt branch -d -f merge-into-modified
dolt checkout -b merge-into-modified modifier
dolt merge deleter
dolt conflicts resolve --ours foo
run dolt sql -q 'select count(*) from foo'
[ "$status" -eq 0 ]
[[ "$output" =~ "| 3 |" ]] || false
dolt merge --abort
dolt reset --hard
dolt checkout -b merge-into-deleter deleter
run dolt merge modifier
[ "$status" -eq 0 ]
[[ "$output" =~ "CONFLICT" ]] || false
dolt merge --abort
# Accept ours deletes all rows.
dolt checkout master
dolt branch -d -f merge-into-deleter
dolt checkout -b merge-into-deleter deleter
dolt merge modifier
dolt conflicts resolve --ours foo
run dolt sql -q 'select count(*) from foo'
[ "$status" -eq 0 ]
[[ "$output" =~ "| 0 |" ]] || false
dolt merge --abort
dolt reset --hard
# Accept theirs adds modified.
dolt checkout master
dolt branch -d -f merge-into-deleter
dolt checkout -b merge-into-deleter deleter
dolt merge modifier
dolt conflicts resolve --theirs foo
run dolt sql -q 'select count(*) from foo'
[ "$status" -eq 0 ]
[[ "$output" =~ "| 3 |" ]] || false
dolt merge --abort
dolt reset --hard
}

View File

@@ -0,0 +1,136 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
dolt sql <<SQL
CREATE TABLE test1 (
pk BIGINT NOT NULL,
c1 BIGINT,
PRIMARY KEY (pk)
);
INSERT INTO test1 VALUES(1,1);
SQL
dolt sql <<SQL
CREATE TABLE test2 (
pk BIGINT NOT NULL,
c1 BIGINT,
PRIMARY KEY (pk)
);
INSERT INTO test2 VALUES(2,2);
SQL
}
teardown() {
assert_feature_version
teardown_common
}
@test "cp-and-mv: cp table" {
run dolt table cp test1 test_new
[ "$status" -eq 0 ]
run dolt sql -q 'show tables';
[ "$status" -eq 0 ]
[[ "$output" =~ "test1" ]] || false
[[ "$output" =~ "test_new" ]] || false
run dolt sql -q 'select * from test_new' -r csv;
[ "$status" -eq 0 ]
[[ "$output" =~ "1,1" ]] || false
[ "${#lines[@]}" -eq 2 ]
}
@test "cp-and-mv: mv table" {
run dolt table mv test1 test_new
[ "$status" -eq 0 ]
run dolt sql -q 'show tables';
[ "$status" -eq 0 ]
! [[ "$output" =~ "test1" ]] || false
[[ "$output" =~ "test_new" ]] || false
run dolt sql -q 'select * from test_new' -r csv;
[ "$status" -eq 0 ]
[[ "$output" =~ "1,1" ]] || false
[ "${#lines[@]}" -eq 2 ]
}
@test "cp-and-mv: cp table with the existing name" {
run dolt table cp test1 test2
[ "$status" -ne 0 ]
[[ "$output" =~ "already exists" ]] || false
}
@test "cp-and-mv: mv table with the existing name" {
run dolt table mv test1 test2
[ "$status" -ne 0 ]
[[ "$output" =~ "already exists" ]] || false
}
@test "cp-and-mv: cp nonexistent table" {
run dolt table cp not_found test2
[ "$status" -ne 0 ]
[[ "$output" =~ "not found" ]] || false
}
@test "cp-and-mv: mv non_existent table" {
run dolt table mv not_found test2
[ "$status" -ne 0 ]
[[ "$output" =~ "not found" ]] || false
}
@test "cp-and-mv: cp table with invalid name" {
run dolt table cp test1 123
[ "$status" -eq 1 ]
[[ "$output" =~ "Invalid table name" ]] || false
run dolt table cp test1 dolt_docs
[ "$status" -eq 1 ]
[[ "$output" =~ "Invalid table name" ]] || false
[[ "$output" =~ "reserved" ]] || false
run dolt table cp test1 dolt_query_catalog
[ "$status" -eq 1 ]
[[ "$output" =~ "Invalid table name" ]] || false
[[ "$output" =~ "reserved" ]] || false
run dolt table cp test1 dolt_reserved
[ "$status" -eq 1 ]
[[ "$output" =~ "Invalid table name" ]] || false
[[ "$output" =~ "reserved" ]] || false
}
@test "cp-and-mv: mv table with invalid name" {
run dolt table mv test1 123
[ "$status" -eq 1 ]
[[ "$output" =~ "Invalid table name" ]] || false
run dolt table mv test1 dolt_docs
[ "$status" -eq 1 ]
[[ "$output" =~ "Invalid table name" ]] || false
[[ "$output" =~ "reserved" ]] || false
run dolt table mv test1 dolt_query_catalog
[ "$status" -eq 1 ]
[[ "$output" =~ "Invalid table name" ]] || false
[[ "$output" =~ "reserved" ]] || false
run dolt table mv test1 dolt_reserved
[ "$status" -eq 1 ]
[[ "$output" =~ "Invalid table name" ]] || false
[[ "$output" =~ "reserved" ]] || false
}
@test "cp-and-mv: rm table" {
run dolt table rm test1
[ "$status" -eq 0 ]
run dolt sql -q 'show tables';
[ "$status" -eq 0 ]
! [[ "$output" =~ "test1" ]] || false
[[ "$output" =~ "test2" ]] || false
}
@test "cp-and-mv: rm tables" {
run dolt table rm test1 test2
[ "$status" -eq 0 ]
run dolt ls;
[ "$status" -eq 0 ]
[[ "$output" =~ "No tables" ]] || false
}
@test "cp-and-mv: rm nonexistent table" {
run dolt table rm abcdefz
[ "$status" -eq 1 ]
[[ "$output" =~ "not found" ]] || false
}

View File

@@ -0,0 +1,237 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
assert_feature_version
teardown_common
}
@test "create-views: create a single view" {
run dolt sql <<SQL
create view four as select 2+2 as res from dual;
select * from four;
SQL
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 6 ]
[[ "${lines[1]}" =~ ' res ' ]] || false
[[ "${lines[3]}" =~ ' 4 ' ]] || false
}
@test "create-views: drop a single view" {
run dolt sql <<SQL
create view four as select 2+2 as res from dual;
drop view four;
SQL
[ "$status" -eq 0 ]
}
@test "create-views: can't drop dolt_schemas" {
run dolt sql -q "create view four as select 2+2 as res from dual;"
[ "$status" -eq 0 ]
run dolt sql -q "select name from dolt_schemas" -r csv
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ 'four' ]] || false
run dolt sql -q "drop table dolt_schemas"
skip "dropping dolt_schemas is currently unprotected"
[ "$status" -ne 0 ]
run dolt sql -q "select name from dolt_schemas" -r csv
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ 'four' ]] || false
}
@test "create-views: join two views" {
run dolt sql <<SQL
create view four as select 2+2 as res from dual;
create view now as select now() from dual;
select * from four, now;
SQL
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 6 ]
[[ "${lines[1]}" =~ ' res ' ]] || false
[[ "${lines[3]}" =~ ' 4 ' ]] || false
}
@test "create-views: cannot create view referencing non-existant table" {
run dolt sql <<SQL
create view broken as select id from my_users;
SQL
[ "$status" -eq 1 ]
[[ "$output" =~ "table not found: my_users" ]] || false
}
@test "create-views: can create view with escaped name" {
run dolt sql -q 'create table `my-users` (id int primary key);'
[ "$status" -eq 0 ]
dolt sql -q 'insert into `my-users` (id) values (0);'
run dolt sql -q 'create view `will-work` as select id from `my-users`;'
[ "$status" -eq 0 ]
run dolt sql -q 'select * from `will-work`;'
[ "$status" -eq 0 ]
[[ ! "$output" =~ "panic" ]] || false
}
@test "create-views: can create view referencing table" {
run dolt sql <<SQL
create table my_users (id int primary key);
create view will_work as select id from my_users;
SQL
[ "$status" -eq 0 ]
}
@test "create-views: can drop table with view referencing it" {
run dolt sql <<SQL
create table my_users (id int primary key);
create view will_be_broken as select id from my_users;
drop table my_users;
SQL
[ "$status" -eq 0 ]
}
@test "create-views: view referencing table selects values present when it was created" {
run dolt sql <<SQL
create table my_users (id int primary key);
insert into my_users values (1), (2), (3);
create view my_users_view as select id from my_users order by id asc;
select * from my_users_view;
SQL
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 8 ]
[[ "${lines[1]}" =~ ' id ' ]] || false
[[ "${lines[3]}" =~ ' 1 ' ]] || false
[[ "${lines[4]}" =~ ' 2 ' ]] || false
[[ "${lines[5]}" =~ ' 3 ' ]] || false
}
@test "create-views: view referencing table selects values inserted after it was created" {
run dolt sql <<SQL
create table my_users (id int primary key);
insert into my_users values (1), (2), (3);
create view my_users_view as select id from my_users order by id asc;
insert into my_users values (4), (5), (6);
select * from my_users_view;
SQL
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 11 ]
[[ "${lines[1]}" =~ ' id ' ]] || false
[[ "${lines[3]}" =~ ' 1 ' ]] || false
[[ "${lines[4]}" =~ ' 2 ' ]] || false
[[ "${lines[5]}" =~ ' 3 ' ]] || false
[[ "${lines[6]}" =~ ' 4 ' ]] || false
[[ "${lines[7]}" =~ ' 5 ' ]] || false
[[ "${lines[8]}" =~ ' 6 ' ]] || false
}
@test "create-views: select view with alias" {
run dolt sql <<SQL
create table my_users (id int primary key);
insert into my_users values (1), (2), (3);
create view my_users_view as select id from my_users order by id asc;
insert into my_users values (4), (5), (6);
select v.* from my_users_view as V;
SQL
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 11 ]
[[ "${lines[1]}" =~ ' id ' ]] || false
[[ "${lines[3]}" =~ ' 1 ' ]] || false
[[ "${lines[4]}" =~ ' 2 ' ]] || false
[[ "${lines[5]}" =~ ' 3 ' ]] || false
[[ "${lines[6]}" =~ ' 4 ' ]] || false
[[ "${lines[7]}" =~ ' 5 ' ]] || false
[[ "${lines[8]}" =~ ' 6 ' ]] || false
}
@test "create-views: selecting from broken view fails" {
run dolt sql <<SQL
create table my_users (id int primary key);
create view will_be_broken as select id from my_users;
drop table my_users;
select * from will_be_broken;
SQL
[ "$status" -eq 1 ]
}
@test "create-views: creating view creates creates dolt_schemas table" {
run dolt sql -q 'create view testing as select 2+2 from dual'
[ "$status" -eq 0 ]
run dolt status
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 4 ]
[[ "${lines[3]}" =~ 'new table:' ]] || false
[[ "${lines[3]}" =~ ' dolt_schemas' ]] || false
run dolt sql -q "select * from dolt_schemas"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
[[ "$output" =~ "select 2+2 from dual" ]] || false
}
@test "create-views: created view is queryable from next session" {
run dolt sql -q 'create view testing as select 2+2 from dual'
[ "$status" -eq 0 ]
run dolt sql -q 'select * from testing'
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
[[ "${lines[1]}" =~ '2 + 2' ]] || false
[[ "${lines[3]}" =~ ' 4 ' ]] || false
}
@test "create-views: created view is droppable from next session" {
run dolt sql -q 'create view testing as select 2+2 from dual'
[ "$status" -eq 0 ]
run dolt sql -q 'drop view testing'
[ "$status" -eq 0 ]
run dolt sql -q 'select * from testing'
[ "$status" -eq 1 ]
}
@test "create-views: database with broken view can be used" {
run dolt sql -q 'create table users (id longtext primary key)'
[ "$status" -eq 0 ]
run dolt sql -q 'create view all_users as select * from users'
[ "$status" -eq 0 ]
run dolt sql -q 'select * from all_users'
[ "$status" -eq 0 ]
run dolt sql -q 'drop table users'
[ "$status" -eq 0 ]
run dolt sql -q 'select 2+2 from dual'
[ "$status" -eq 0 ]
run dolt sql -q 'select * from all_users'
[ "$status" -eq 1 ]
[[ "${lines[0]}" =~ "table not found: users" ]] || false
run dolt sql -q 'drop view all_users'
[ "$status" -eq 0 ]
}
@test "create-views: Use a committed view" {
dolt sql -q "create view four as select 2+2 as res from dual"
dolt add .
dolt commit -m "Checked in a view"
run dolt sql -q "select * from four"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
[[ "${lines[1]}" =~ ' res ' ]] || false
[[ "${lines[3]}" =~ ' 4 ' ]] || false
run dolt sql -q "select * from dolt_schemas"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
[[ "$output" =~ "four" ]] || false
dolt sql -q "create view five as select 2+3 as res from dual"
run dolt sql -q "select * from dolt_schemas"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 6 ]
[[ "$output" =~ "five" ]] || false
dolt reset --hard
run dolt sql -q "select * from dolt_schemas"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 5 ]
[[ ! "$output" =~ "five" ]] || false
run dolt sql -q "select * from five"
[ "$status" -eq 1 ]
[[ "${lines[0]}" =~ "table not found: five" ]] || false
}

View File

@@ -0,0 +1,129 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
teardown_common
}
@test "creds: ls empty creds" {
run dolt creds ls
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
}
@test "creds: ls new cred" {
dolt creds new
run dolt creds ls
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 1 ]
[[ "${lines[0]}" =~ (^\*\ ) ]] || false
cred=`echo "${lines[0]}" | awk '{print $2}'`
dolt creds new
run dolt creds ls
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 2 ]
# Initially chosen credentials is still the chosen one.
[[ "`echo "$output"|grep "$cred"`" =~ (^\*\ ) ]] || false
}
@test "creds: ls -v new creds" {
dolt creds new
dolt creds new
run dolt creds ls -v
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 4 ]
[[ "${lines[0]}" =~ (public\ key) ]] || false
[[ "${lines[0]}" =~ (key\ id) ]] || false
}
@test "creds: rm removes a cred" {
dolt creds new
run dolt creds ls
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 1 ]
cred=`echo "${lines[0]}" | awk '{print $2}'`
dolt creds rm $cred
run dolt creds ls
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
}
@test "creds: use can use a new credential by pub key" {
dolt creds new
dolt creds new
run dolt creds ls -v
[ "$status" -eq 0 ]
unusedpk=`echo "$output"|sed -n '3,$p'|grep '^ '|awk '{print $1}'`
dolt creds use "$unusedpk"
run dolt creds ls
[ "$status" -eq 0 ]
[[ "`echo "$output"|grep "$unusedpk"`" =~ (^\*\ ) ]] || false
}
@test "creds: use can use a new credential by key id" {
dolt creds new
dolt creds new
run dolt creds ls -v
[ "$status" -eq 0 ]
unusedpk=`echo "$output"|sed -n '3,$p'|grep '^ '|awk '{print $1}'`
unusedkid=`echo "$output"|sed -n '3,$p'|grep '^ '|awk '{print $2}'`
dolt creds use "$unusedkid"
run dolt creds ls
[ "$status" -eq 0 ]
[[ "`echo "$output"|grep "$unusedpk"`" =~ (^\*\ ) ]] || false
}
@test "creds: use fails with bad arguments" {
run dolt creds use qv7bnud1t4fo9qo6nq8l44cbrjlh33hn6h22a2c4thr0m454lp4g
[ "$status" -eq 1 ]
run dolt creds use ir3vamrck6e6e8gl4s51t94k0i7eo92ccr0st3mc6keau
[ "$status" -eq 1 ]
run dolt creds use invalid-format-for-parameter
[ "$status" -eq 1 ]
run dolt creds use
[ "$status" -eq 1 ]
}
@test "creds: creds file created with right permissions" {
skiponwindows "Need to investigate the permissions results on windows."
dolt creds new
file=$(echo ${DOLT_ROOT_PATH}/.dolt/creds/`dolt creds ls -v | grep '*' | awk '{print $3}'`.jwk)
perms=$(ls -l "$file" | awk '{print $1}')
[ "$perms" == "-rw-------" ]
}
@test "creds: can import cred from good jwk file" {
dolt creds import `batshelper known-good.jwk`
}
@test "creds: can import cred from good jwk stdin" {
dolt creds import <"$BATS_TEST_DIRNAME/helper/known-good.jwk"
}
@test "creds: import cred of corrupted jwk from file fails" {
run dolt creds import `batshelper known-truncated.jwk`
[ "$status" -eq 1 ]
run dolt creds import `batshelper known-decapitated.jwk`
[ "$status" -eq 1 ]
run dolt creds import does-not-exist
[ "$status" -eq 1 ]
}
@test "creds: import cred of corrupted jwk from stdin fails" {
run dolt creds import <"$BATS_TEST_DIRNAME/helper/known-truncated.jwk"
[ "$status" -eq 1 ]
run dolt creds import <"$BATS_TEST_DIRNAME/helper/known-decapitated.jwk"
[ "$status" -eq 1 ]
run dolt creds import </dev/null
[ "$status" -eq 1 ]
}
@test "creds: import cred with already used cred does not replace used cred" {
pubkey=`dolt creds new | grep 'pub key:' | awk '{print $3}'`
dolt creds import `batshelper known-good.jwk`
dolt creds ls -v | grep '*' | grep "$pubkey"
}

View File

@@ -0,0 +1,456 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
dolt sql <<SQL
CREATE TABLE parent (
id int PRIMARY KEY,
v1 int,
v2 int,
INDEX v1 (v1),
INDEX v2 (v2)
);
CREATE TABLE child (
id int primary key,
v1 int,
v2 int
);
SQL
}
teardown() {
teardown_common
}
@test "default-values: Standard default literal" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT 2)"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1" ]] || false
[[ "$output" =~ "1,2" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Default expression with function and referenced column" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 SMALLINT DEFAULT (GREATEST(pk, 2)))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2), (3)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1" ]] || false
[[ "$output" =~ "1,2" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "3,3" ]] || false
[[ "${#lines[@]}" = "4" ]] || false
}
@test "default-values: Default expression converting to proper column type" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 VARCHAR(20) DEFAULT (GREATEST(pk, 2)))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2), (3)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1" ]] || false
[[ "$output" =~ "1,2" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "3,3" ]] || false
[[ "${#lines[@]}" = "4" ]] || false
}
@test "default-values: Default literal of different type but implicitly converts" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT '4')"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1" ]] || false
[[ "$output" =~ "1,4" ]] || false
[[ "$output" =~ "2,4" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Back reference to default literal" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2), v2 BIGINT DEFAULT 7)"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1,v2" ]] || false
[[ "$output" =~ "1,7,7" ]] || false
[[ "$output" =~ "2,7,7" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Forward reference to default literal" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT 9, v2 BIGINT DEFAULT (v1))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1,v2" ]] || false
[[ "$output" =~ "1,9,9" ]] || false
[[ "$output" =~ "2,9,9" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Forward reference to default expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (8), v2 BIGINT DEFAULT (v1))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1,v2" ]] || false
[[ "$output" =~ "1,8,8" ]] || false
[[ "$output" =~ "2,8,8" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Back reference to value" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2 + 1), v2 BIGINT)"
dolt sql -q "INSERT INTO test (pk, v2) VALUES (1, 4), (2, 6)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1,v2" ]] || false
[[ "$output" =~ "1,5,4" ]] || false
[[ "$output" =~ "2,7,6" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: TEXT expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 LONGTEXT DEFAULT (77))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1" ]] || false
[[ "$output" =~ "1,77" ]] || false
[[ "$output" =~ "2,77" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: REPLACE INTO with default expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 SMALLINT DEFAULT (GREATEST(pk, 2)))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
dolt sql -q "REPLACE INTO test (pk) VALUES (2), (3)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1" ]] || false
[[ "$output" =~ "1,2" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "3,3" ]] || false
[[ "${#lines[@]}" = "4" ]] || false
}
@test "default-values: Add column last default literal" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT '4')"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT 5"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1,v2" ]] || false
[[ "$output" =~ "1,4,5" ]] || false
[[ "$output" =~ "2,4,5" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Add column implicit last default expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT (v1 + 2)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1,v2" ]] || false
[[ "$output" =~ "1,2,4" ]] || false
[[ "$output" =~ "2,3,5" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Add column explicit last default expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT (v1 + 2) AFTER v1"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1,v2" ]] || false
[[ "$output" =~ "1,2,4" ]] || false
[[ "$output" =~ "2,3,5" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Add column first default literal" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT '4')"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT 5 FIRST"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "v2,pk,v1" ]] || false
[[ "$output" =~ "5,1,4" ]] || false
[[ "$output" =~ "5,2,4" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Add column first default expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT)"
dolt sql -q "INSERT INTO test VALUES (1, 3), (2, 4)"
dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT (v1 + 2) FIRST"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "v2,pk,v1" ]] || false
[[ "$output" =~ "5,1,3" ]] || false
[[ "$output" =~ "6,2,4" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Add column forward reference to default expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT DEFAULT (v1) PRIMARY KEY, v1 BIGINT)"
dolt sql -q "INSERT INTO test (v1) VALUES (1), (2)"
dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT (pk + 1) AFTER pk"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v2,v1" ]] || false
[[ "$output" =~ "1,2,1" ]] || false
[[ "$output" =~ "2,3,2" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Add column back reference to default literal" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT 5)"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT (v1 - 1) AFTER pk"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v2,v1" ]] || false
[[ "$output" =~ "1,4,5" ]] || false
[[ "$output" =~ "2,4,5" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Add column first with existing defaults still functioning" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 10))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT (-pk) FIRST"
dolt sql -q "INSERT INTO test (pk) VALUES (3)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "v2,pk,v1" ]] || false
[[ "$output" =~ "-1,1,11" ]] || false
[[ "$output" =~ "-2,2,12" ]] || false
[[ "$output" =~ "-3,3,13" ]] || false
[[ "${#lines[@]}" = "4" ]] || false
}
@test "default-values: Drop column referencing other column" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2), v2 BIGINT)"
dolt sql -q "ALTER TABLE test DROP COLUMN v1"
}
@test "default-values: Modify column move first forward reference default literal" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 2), v2 BIGINT DEFAULT (pk + 1))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
dolt sql -q "ALTER TABLE test MODIFY COLUMN v1 BIGINT DEFAULT (pk + 2) FIRST"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "v1,pk,v2" ]] || false
[[ "$output" =~ "3,1,2" ]] || false
[[ "$output" =~ "4,2,3" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
}
@test "default-values: Modify column move first add reference" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (v1 + 1))"
dolt sql -q "INSERT INTO test (pk, v1) VALUES (1, 2), (2, 3)"
dolt sql -q "ALTER TABLE test MODIFY COLUMN v1 BIGINT DEFAULT (pk + 5) FIRST"
dolt sql -q "INSERT INTO test (pk) VALUES (3)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "v1,pk,v2" ]] || false
[[ "$output" =~ "2,1,3" ]] || false
[[ "$output" =~ "3,2,4" ]] || false
[[ "$output" =~ "8,3,9" ]] || false
[[ "${#lines[@]}" = "4" ]] || false
}
@test "default-values: Modify column move last being referenced" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (v1 + 1))"
dolt sql -q "INSERT INTO test (pk, v1) VALUES (1, 2), (2, 3)"
dolt sql -q "ALTER TABLE test MODIFY COLUMN v1 BIGINT AFTER v2"
dolt sql -q "INSERT INTO test (pk, v1) VALUES (3, 4)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v2,v1" ]] || false
[[ "$output" =~ "1,3,2" ]] || false
[[ "$output" =~ "2,4,3" ]] || false
[[ "$output" =~ "3,5,4" ]] || false
[[ "${#lines[@]}" = "4" ]] || false
}
@test "default-values: Modify column move last add reference" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (pk * 2))"
dolt sql -q "INSERT INTO test (pk, v1) VALUES (1, 2), (2, 3)"
dolt sql -q "ALTER TABLE test MODIFY COLUMN v1 BIGINT DEFAULT (-pk) AFTER v2"
dolt sql -q "INSERT INTO test (pk) VALUES (3)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v2,v1" ]] || false
[[ "$output" =~ "1,2,2" ]] || false
[[ "$output" =~ "2,4,3" ]] || false
[[ "$output" =~ "3,6,-3" ]] || false
[[ "${#lines[@]}" = "4" ]] || false
}
@test "default-values: Modify column no move add reference" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (pk * 2))"
dolt sql -q "INSERT INTO test (pk, v1) VALUES (1, 2), (2, 3)"
dolt sql -q "ALTER TABLE test MODIFY COLUMN v1 BIGINT DEFAULT (-pk)"
dolt sql -q "INSERT INTO test (pk) VALUES (3)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1,v2" ]] || false
[[ "$output" =~ "1,2,2" ]] || false
[[ "$output" =~ "2,3,4" ]] || false
[[ "$output" =~ "3,-3,6" ]] || false
[[ "${#lines[@]}" = "4" ]] || false
}
@test "default-values: Table referenced with column" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (test.pk))"
dolt sql -q "INSERT INTO test (pk) VALUES (1), (2)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1" ]] || false
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "${#lines[@]}" = "3" ]] || false
run dolt schema show
[ "$status" -eq "0" ]
[[ "$output" =~ "\`v1\` bigint DEFAULT (pk)" ]] || false
}
@test "default-values: Column referenced with name change" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (v1 + 1))"
dolt sql -q "INSERT INTO test (pk, v1) VALUES (1, 2)"
dolt sql -q "ALTER TABLE test RENAME COLUMN v1 to v1x"
dolt sql -q "INSERT INTO test (pk, v1x) VALUES (2, 3)"
dolt sql -q "ALTER TABLE test CHANGE COLUMN v1x v1y BIGINT"
dolt sql -q "INSERT INTO test (pk, v1y) VALUES (3, 4)"
run dolt sql -q "SELECT * FROM test" -r=csv
[ "$status" -eq "0" ]
[[ "$output" =~ "pk,v1y,v2" ]] || false
[[ "$output" =~ "1,2,3" ]] || false
[[ "$output" =~ "2,3,4" ]] || false
[[ "$output" =~ "3,4,5" ]] || false
[[ "${#lines[@]}" = "4" ]] || false
run dolt schema show
[ "$status" -eq "0" ]
[[ "$output" =~ "\`v2\` bigint DEFAULT (v1y + 1)" ]] || false
}
@test "default-values: Invalid literal for column type" {
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 INT UNSIGNED DEFAULT -1)"
[ "$status" -eq "1" ]
}
@test "default-values: Invalid literal for column type 2" {
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT 'hi')"
[ "$status" -eq "1" ]
}
@test "default-values: Expression contains invalid literal once implicitly converted" {
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 INT UNSIGNED DEFAULT '-1')"
[ "$status" -eq "1" ]
}
@test "default-values: Null literal is invalid for NOT NULL" {
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT NOT NULL DEFAULT NULL)"
[ "$status" -eq "1" ]
}
@test "default-values: Back reference to expression" {
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2), v2 BIGINT DEFAULT (9))"
[ "$status" -eq "1" ]
}
@test "default-values: TEXT literals" {
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 TEXT DEFAULT 'hi')"
[ "$status" -eq "1" ]
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 LONGTEXT DEFAULT 'hi')"
[ "$status" -eq "1" ]
}
@test "default-values: Other types using NOW/CURRENT_TIMESTAMP literal" {
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT NOW())"
[ "$status" -eq "1" ]
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 VARCHAR(20) DEFAULT CURRENT_TIMESTAMP())"
[ "$status" -eq "1" ]
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIT(5) DEFAULT NOW())"
[ "$status" -eq "1" ]
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 DATE DEFAULT CURRENT_TIMESTAMP())"
[ "$status" -eq "1" ]
}
@test "default-values: Custom functions are invalid" {
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (CUSTOMFUNC(1)))"
[ "$status" -eq "1" ]
}
@test "default-values: Default expression references own column" {
run dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v1))"
[ "$status" -eq "1" ]
}
@test "default-values: Expression contains invalid literal, fails on insertion" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 INT UNSIGNED DEFAULT (-1))"
run dolt sql -q "INSERT INTO test (pk) VALUES (1)"
[ "$status" -eq "1" ]
}
@test "default-values: Expression contains null on NOT NULL, fails on insertion" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT NOT NULL DEFAULT (NULL))"
run dolt sql -q "INSERT INTO test (pk) VALUES (1)"
[ "$status" -eq "1" ]
}
@test "default-values: Add column first back reference to expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))"
run dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT (v1 + 2) FIRST"
[ "$status" -eq "1" ]
}
@test "default-values: Add column after back reference to expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))"
run dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT (v1 + 2) AFTER pk"
[ "$status" -eq "1" ]
}
@test "default-values: Add column self reference" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))"
run dolt sql -q "ALTER TABLE test ADD COLUMN v2 BIGINT DEFAULT (v2)"
[ "$status" -eq "1" ]
}
@test "default-values: Drop column referenced by other column" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (v1))"
run dolt sql -q "ALTER TABLE test DROP COLUMN v1"
[ "$status" -eq "1" ]
}
@test "default-values: Modify column moving back creates back reference to expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk), v2 BIGINT DEFAULT (v1))"
run dolt sql -q "ALTER TABLE test MODIFY COLUMN v1 BIGINT DEFAULT (pk) AFTER v2"
[ "$status" -eq "1" ]
}
@test "default-values: Modify column moving forward creates back reference to expression" {
dolt sql -q "CREATE TABLE test(pk BIGINT DEFAULT (v2) PRIMARY KEY, v1 BIGINT DEFAULT (pk), v2 BIGINT)"
run dolt sql -q "ALTER TABLE test MODIFY COLUMN v1 BIGINT DEFAULT (pk) FIRST"
[ "$status" -eq "1" ]
}
@test "default-values: Modify column invalid after" {
dolt sql -q "CREATE TABLE test(pk BIGINT DEFAULT (v2) PRIMARY KEY, v1 BIGINT DEFAULT (pk), v2 BIGINT)"
run dolt sql -q "ALTER TABLE test MODIFY COLUMN v1 BIGINT DEFAULT (pk) AFTER v3"
[ "$status" -eq "1" ]
}
@test "default-values: Add column invalid after" {
dolt sql -q "CREATE TABLE test(pk BIGINT DEFAULT (v2) PRIMARY KEY, v1 BIGINT DEFAULT (pk), v2 BIGINT)"
run dolt sql -q "ALTER TABLE test ADD COLUMN v1 BIGINT DEFAULT (pk) AFTER v3"
[ "$status" -eq "1" ]
}

View File

@@ -0,0 +1,462 @@
#!/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() {
assert_feature_version
teardown_common
}
@test "diff: clean working set" {
dolt add .
dolt commit -m table
dolt sql -q 'insert into test values (0,0,0,0,0,0)'
dolt add .
dolt commit -m row
run dolt diff
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt diff head
[ "$status" -eq 0 ]
[ "$output" = "" ]
dolt diff head^
run dolt diff head^
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
run dolt diff head^ head
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
run dolt diff head head^
[ "$status" -eq 0 ]
[[ "$output" =~ "- | 0" ]] || false
}
@test "diff: dirty working set" {
dolt add .
dolt commit -m table
dolt sql -q 'insert into test values (0,0,0,0,0,0)'
run dolt diff
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
run dolt diff head
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
dolt add .
run dolt diff
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt diff head
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
}
@test "diff: with table args" {
dolt sql -q 'create table other (pk int not null primary key)'
dolt add .
dolt commit -m tables
dolt sql -q 'insert into test values (0,0,0,0,0,0)'
dolt sql -q 'insert into other values (9)'
run dolt diff test
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
[[ ! "$output" =~ "+ | 9" ]] || false
run dolt diff other
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 9" ]] || false
[[ ! "$output" =~ "+ | 0" ]] || false
run dolt diff test other
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
[[ "$output" =~ "+ | 9" ]] || false
dolt add .
run dolt diff head test other
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
[[ "$output" =~ "+ | 9" ]] || false
dolt commit -m rows
run dolt diff head^ head test other
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
[[ "$output" =~ "+ | 9" ]] || false
run dolt diff head^ head fake
[ "$status" -ne 0 ]
[[ "$output" =~ "table fake does not exist in either diff root" ]] || false
}
@test "diff: with table and branch of the same name" {
dolt sql -q 'create table dolomite (pk int not null primary key)'
dolt add .
dolt commit -m tables
dolt branch dolomite
dolt sql -q 'insert into dolomite values (9)'
dolt add .
dolt commit -m 'intermediate commit'
dolt sql -q 'insert into test values (0,0,0,0,0,0)'
# branch/commit args get preference over tables
run dolt diff dolomite
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 9" ]] || false
[[ "$output" =~ "+ | 0" ]] || false
run dolt diff dolomite test
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 0" ]] || false
[[ ! "$output" =~ "+ | 9" ]] || false
run dolt diff dolomite head dolomite
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 9" ]] || false
[[ ! "$output" =~ "+ | 0" ]] || false
run dolt diff head^ head dolomite
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 9" ]] || false
[[ ! "$output" =~ "+ | 0" ]] || false
dolt branch -D dolomite
dolt sql -q 'insert into dolomite values (8)'
run dolt diff dolomite
[ "$status" -eq 0 ]
[[ "$output" =~ "+ | 8" ]] || false
[[ ! "$output" =~ "+ | 0" ]] || false
}
@test "diff: with index and foreign key changes" {
dolt sql <<SQL
CREATE TABLE parent (
pk bigint PRIMARY KEY,
c1 bigint,
c2 bigint,
INDEX c1 (c1)
);
ALTER TABLE test ADD CONSTRAINT fk1 FOREIGN KEY (c1) REFERENCES parent(c1);
SQL
dolt add -A
dolt commit -m "added parent table, foreign key"
dolt sql <<SQL
ALTER TABLE parent ADD INDEX c2 (c2);
ALTER TABLE test DROP FOREIGN KEY fk1;
ALTER TABLE parent DROP INDEX c1;
ALTER TABLE test ADD CONSTRAINT fk2 FOREIGN KEY (c2) REFERENCES parent(c2);
SQL
dolt diff test
run dolt diff test
[ "$status" -eq 0 ]
[[ "$output" =~ "+ INDEX \`c2\` (\`c2\`)" ]] || false
[[ "$output" =~ "- CONSTRAINT \`fk1\` FOREIGN KEY (\`c1\`)" ]] || false
[[ "$output" =~ " REFERENCES \`parent\` (\`c1\`)" ]] || false
[[ "$output" =~ "+ CONSTRAINT \`fk2\` FOREIGN KEY (\`c2\`)" ]] || false
[[ "$output" =~ " REFERENCES \`parent\` (\`c2\`)" ]] || false
dolt diff parent
run dolt diff parent
[ "$status" -eq 0 ]
[[ "$output" =~ "- INDEX \`c1\` (\`c1\`)" ]] || false
[[ "$output" =~ "+ INDEX \`c2\` (\`c2\`)" ]] || false
}
@test "diff: summary comparing working table to last commit" {
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "table created"
dolt sql -q "insert into test values (2, 11, 0, 0, 0, 0)"
dolt sql -q "insert into test values (3, 11, 0, 0, 0, 0)"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "2 Rows Unmodified (100.00%)" ]] || false
[[ "$output" =~ "2 Rows Added (100.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Modified (0.00%)" ]] || false
[[ "$output" =~ "0 Cells Modified (0.00%)" ]] || false
[[ "$output" =~ "(2 Entries vs 4 Entries)" ]] || false
dolt add test
dolt commit -m "added two rows"
dolt sql -q "replace into test values (0, 11, 0, 0, 0, 6)"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "3 Rows Unmodified (75.00%)" ]] || false
[[ "$output" =~ "0 Rows Added (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "1 Row Modified (25.00%)" ]] || false
[[ "$output" =~ "2 Cells Modified (8.33%)" ]] || false
[[ "$output" =~ "(4 Entries vs 4 Entries)" ]] || false
dolt add test
dolt commit -m "modified first row"
dolt sql -q "delete from test where pk = 0"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "3 Rows Unmodified (75.00%)" ]] || false
[[ "$output" =~ "0 Rows Added (0.00%)" ]] || false
[[ "$output" =~ "1 Row Deleted (25.00%)" ]] || false
[[ "$output" =~ "0 Rows Modified (0.00%)" ]] || false
[[ "$output" =~ "0 Cells Modified (0.00%)" ]] || false
[[ "$output" =~ "(4 Entries vs 3 Entries)" ]] || false
}
@test "diff: summary comparing row with a deleted cell and an added cell" {
dolt add test
dolt commit -m "create table"
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "put row"
dolt sql -q "replace into test (pk, c1, c3, c4, c5) values (0, 1, 3, 4, 5)"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "0 Rows Unmodified (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Added (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "1 Row Modified (100.00%)" ]] || false
[[ "$output" =~ "1 Cell Modified (16.67%)" ]] || false
[[ "$output" =~ "(1 Entry vs 1 Entry)" ]] || false
dolt add test
dolt commit -m "row modified"
dolt sql -q "replace into test values (0, 1, 2, 3, 4, 5)"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "0 Rows Unmodified (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Added (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "1 Row Modified (100.00%)" ]] || false
[[ "$output" =~ "1 Cell Modified (16.67%)" ]] || false
[[ "$output" =~ "(1 Entry vs 1 Entry)" ]] || false
}
@test "diff: summary comparing two branches" {
dolt checkout -b firstbranch
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt add test
dolt commit -m "Added one row"
dolt checkout -b newbranch
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "Added another row"
run dolt diff --summary firstbranch newbranch
[ "$status" -eq 0 ]
[[ "$output" =~ "1 Row Unmodified (100.00%)" ]] || false
[[ "$output" =~ "1 Row Added (100.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Modified (0.00%)" ]] || false
[[ "$output" =~ "0 Cells Modified (0.00%)" ]] || false
[[ "$output" =~ "(1 Entry vs 2 Entries)" ]] || false
}
@test "diff: summary shows correct changes after schema change" {
cat <<DELIM > employees.csv
"id","first name","last name","title","start date","end date"
0,tim,sehn,ceo,"",""
1,aaron,son,founder,"",""
2,brian,hendricks,founder,"",""
DELIM
dolt table import -c -pk=id employees employees.csv
dolt add employees
dolt commit -m "Added employees table with data"
dolt sql -q "alter table employees add city longtext"
dolt sql -q "insert into employees values (3, 'taylor', 'bantle', 'software engineer', '', '', 'Santa Monica')"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "3 Rows Unmodified (100.00%)" ]] || false
[[ "$output" =~ "1 Row Added (33.33%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Modified (0.00%)" ]] || false
[[ "$output" =~ "0 Cells Modified (0.00%)" ]] || false
[[ "$output" =~ "(3 Entries vs 4 Entries)" ]] || false
dolt sql -q "replace into employees values (0, 'tim', 'sehn', 'ceo', '2 years ago', '', 'Santa Monica')"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "2 Rows Unmodified (66.67%)" ]] || false
[[ "$output" =~ "1 Row Added (33.33%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "1 Row Modified (33.33%)" ]] || false
[[ "$output" =~ "2 Cells Modified (11.11%)" ]] || false
[[ "$output" =~ "(3 Entries vs 4 Entries)" ]] || false
}
@test "diff: summary gets summaries for all tables with changes" {
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt sql <<SQL
CREATE TABLE employees (
\`id\` LONGTEXT NOT NULL,
\`first name\` LONGTEXT,
\`last name\` LONGTEXT,
\`title\` LONGTEXT,
\`start date\` LONGTEXT,
\`end date\` LONGTEXT,
PRIMARY KEY (id)
);
SQL
dolt sql -q "insert into employees values (0, 'tim', 'sehn', 'ceo', '', '')"
dolt add test employees
dolt commit -m "test tables created"
dolt sql -q "insert into test values (2, 11, 0, 0, 0, 0)"
dolt sql -q "insert into employees values (1, 'brian', 'hendriks', 'founder', '', '')"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/test b/test" ]] || false
[[ "$output" =~ "--- a/test @" ]] || false
[[ "$output" =~ "+++ b/test @" ]] || false
[[ "$output" =~ "diff --dolt a/employees b/employees" ]] || false
[[ "$output" =~ "--- a/employees @" ]] || false
[[ "$output" =~ "+++ b/employees @" ]] || false
}
@test "diff: with where clause" {
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "table created"
dolt sql -q "insert into test values (2, 22, 0, 0, 0, 0)"
dolt sql -q "insert into test values (3, 33, 0, 0, 0, 0)"
run dolt diff --where "pk=2"
[ "$status" -eq 0 ]
[[ "$output" =~ "22" ]] || false
! [[ "$output" =~ "33" ]] || false
dolt add test
dolt commit -m "added two rows"
dolt checkout -b test1
dolt sql -q "insert into test values (4, 44, 0, 0, 0, 0)"
dolt add .
dolt commit -m "committed to branch test1"
dolt checkout master
dolt checkout -b test2
dolt sql -q "insert into test values (5, 55, 0, 0, 0, 0)"
dolt add .
dolt commit -m "committed to branch test2"
dolt checkout master
run dolt diff test1 test2
[ "$status" -eq 0 ]
[[ "$output" =~ "44" ]] || false
[[ "$output" =~ "55" ]] || false
run dolt diff test1 test2 --where "pk=4"
[ "$status" -eq 0 ]
[[ "$output" =~ "44" ]] || false
! [[ "$output" =~ "55" ]] || false
run dolt diff test1 test2 --where "from_pk=4"
[ "$status" -eq 0 ]
[[ "$output" =~ "44" ]] || false
! [[ "$output" =~ "55" ]] || false
run dolt diff test1 test2 --where "from_pk=5"
[ "$status" -eq 0 ]
! [[ "$output" =~ "44" ]] || false
! [[ "$output" =~ "55" ]] || false
run dolt diff test1 test2 --where "to_pk=5"
[ "$status" -eq 0 ]
[[ "$output" =~ "55" ]] || false
! [[ "$output" =~ "44" ]] || false
run dolt diff test1 test2 --where "to_pk=4"
[ "$status" -eq 0 ]
! [[ "$output" =~ "44" ]] || false
! [[ "$output" =~ "55" ]] || false
}
@test "diff: with where clause errors" {
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "table created"
dolt sql -q "insert into test values (2, 22, 0, 0, 0, 0)"
dolt sql -q "insert into test values (3, 33, 0, 0, 0, 0)"
run dolt diff --where "poop=0"
[ "$status" -eq 1 ]
[[ "$output" =~ "failed to parse where clause" ]] || false
dolt add test
dolt commit -m "added two rows"
run dolt diff --where "poop=0"
skip "Bad where clause not found because the argument parsing logic is only triggered on existance of a diff"
[ "$status" -eq 1 ]
[[ "$output" =~ "failed to parse where clause" ]] || false
}
@test "diff: --cached" {
run dolt diff --cached
[ $status -eq 0 ]
[ "$output" = "" ]
dolt add test
run dolt diff --cached
[ $status -eq 0 ]
[[ $output =~ "added table" ]] || false
dolt commit -m "First commit"
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
run dolt diff
[ $status -eq 0 ]
CORRECT_DIFF=$output
dolt add test
run dolt diff --cached
[ $status -eq 0 ]
[ "$output" = "$CORRECT_DIFF" ]
# Make sure it ignores changes to the working set that aren't staged
dolt sql -q "create table test2 (pk int, c1 int, primary key(pk))"
run dolt diff --cached
[ $status -eq 0 ]
[ "$output" = "$CORRECT_DIFF" ]
}
@test "diff: with invalid ref does not panic" {
dolt add .
dolt commit -m table
dolt checkout -b test-branch
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt add test
dolt commit -m "added row"
FIRST_COMMIT=`dolt log | grep commit | cut -d " " -f 2 | tail -1`
run dolt diff $FIRST_COMMIT test-branch
[ $status -eq 0 ]
[[ ! $output =~ "panic" ]]
run dolt diff master@$FIRST_COMMIT test-branch
[ $status -eq 1 ]
[[ ! $output =~ "panic" ]]
run dolt diff ref.with.period test-branch
[ $status -eq 1 ]
[[ ! $output =~ "panic" ]]
}
@test "diff: with foreign key and sql output" {
dolt sql <<SQL
CREATE TABLE parent (
id int PRIMARY KEY,
pv1 int,
pv2 int,
INDEX v1 (pv1),
INDEX v2 (pv2)
);
SQL
dolt add -A
dolt commit -m "hi"
dolt sql <<SQL
CREATE TABLE child (
id int primary key,
cv1 int,
cv2 int,
CONSTRAINT fk_named FOREIGN KEY (cv1) REFERENCES parent(pv1)
);
SQL
run dolt diff -s -r=sql master
[ $status -eq 0 ]
[[ $output =~ "CONSTRAINT \`fk_named\` FOREIGN KEY (\`cv1\`) REFERENCES \`parent\` (\`pv1\`)" ]] || false
}

View File

@@ -0,0 +1,839 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
assert_feature_version
teardown_common
}
@test "docs: dolt status and ls to view supported docs on dolt init" {
echo license-text > LICENSE.md
echo readme-text > README.md
run ls
[[ "$output" =~ "LICENSE.md" ]] || false
[[ "$output" =~ "README.md" ]] || false
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch master" ]] || false
[[ "$output" =~ "Untracked files" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
run cat LICENSE.md
[ "$output" = "license-text" ]
run cat README.md
[ "$output" = "readme-text" ]
touch INVALID.md
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch master" ]] || false
[[ "$output" =~ "Untracked files" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
[[ ! "$output" =~ "INVALID.md" ]] || false
}
@test "docs: dolt add . and dolt commit dolt docs" {
echo testing123 > LICENSE.md
echo testing456 > README.md
run dolt add dolt_docs
[ "$status" -eq 1 ]
[[ "$output" =~ "'dolt_docs' is not a valid table name" ]] || false
dolt add .
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch master" ]] || false
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
run dolt commit -m "adding license and readme"
[ "$status" -eq 0 ]
[[ "$output" =~ "adding license and readme" ]] || false
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
rm LICENSE.md
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes not staged for commit:" ]] || false
[[ "$output" =~ deleted:[[:space:]]*LICENSE.md ]] || false
dolt add .
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*deleted:[[:space:]]*LICENSE.md) ]] || false
dolt commit -m "delete license"
run ls
[[ ! "$output" =~ "LICENSE.md" ]] || false
}
@test "docs: dolt add . and dolt commit dolt docs with another table" {
echo license-text > LICENSE.md
echo readme-text > README.md
dolt add .
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch master" ]] || false
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
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
dolt add test
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*new table:[[:space:]]*test) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
dolt commit -m "adding license and readme, and test table"
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch master" ]] || false
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
}
@test "docs: dolt add LICENSE.md stages license" {
echo "new license" > LICENSE.md
echo "new readme" > README.md
dolt add LICENSE.md
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch master" ]] || false
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ "Untracked files:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
run dolt commit -m "license commit"
[ "$status" -eq 0 ]
[[ "$output" =~ "license commit" ]] || false
}
@test "docs: dolt add README.md stages readme" {
echo "new license" > LICENSE.md
echo "new readme" > README.md
dolt add README.md
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch master" ]] || false
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
[[ "$output" =~ "Untracked files:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
run dolt commit -m "readme commit"
[ "$status" -eq 0 ]
[[ "$output" =~ "readme commit" ]] || false
}
@test "docs: dolt add doesn't add files that are not LICENSE.md or README.md" {
touch README.md
touch LICENSE.md
touch invalid
run dolt add README.md invalid
[ "$status" -eq 1 ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Untracked files" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
[[ ! "$output" =~ "invalid" ]] || false
run dolt add invalid LICENSE.md
[ "$status" -eq 1 ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Untracked files" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ ! "$output" =~ "invalid" ]] || false
run dolt add invalid README.md LICENSE.md
[ "$status" -eq 1 ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Untracked files" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
}
@test "docs: dolt reset --hard should move doc files to untracked files when there are no doc values on the head commit" {
echo readme-content > README.md
echo license-content > LICENSE.md
dolt reset --hard
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Untracked files" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
run ls
[[ "$output" =~ "LICENSE.md" ]] || false
[[ "$output" =~ "README.md" ]] || false
dolt add .
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
dolt reset --hard
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Untracked files" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
}
@test "docs: dolt reset --hard should update doc files on the fs when doc values exist on the head commit" {
echo license-text > LICENSE.md
echo readme-text > README.md
dolt add .
dolt commit -m "first docs commit"
echo updated readme > README.md
dolt status
dolt reset --hard
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
run cat README.md
[ "$output" = readme-text ]
echo newLicenseText > LICENSE.md
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
dolt add test LICENSE.md
dolt reset --hard
run dolt status
[ "$status" -eq 0 ]
[ "$status" -eq 0 ]
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
run cat LICENSE.md
[ "$output" = "license-text" ]
}
@test "docs: dolt reset . should remove docs from staging area" {
echo ~license~ > LICENSE.md
echo ~readme~ > README.md
dolt add .
dolt reset .
run dolt status
[ "$status" -eq 0 ]
[[ ! "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ "Untracked files:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
dolt add .
dolt commit -m "initial doc commit"
echo ~new-text~ > README.md
dolt add .
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*README.md) ]] || false
run dolt reset .
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes not staged for commit:" ]] || false
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*README.md) ]] || false
run cat README.md
[[ "$output" =~ "~new-text~" ]]
}
@test "docs: dolt reset --soft should remove docs from staging area" {
echo ~license~ > LICENSE.md
echo ~readme~ > README.md
dolt add .
dolt reset --soft
run dolt status
[ "$status" -eq 0 ]
[[ ! "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ "Untracked files:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
dolt add .
dolt commit -m "initial doc commit"
echo ~new-text~ > README.md
dolt add .
dolt reset --soft
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes not staged for commit:" ]] || false
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*README.md) ]] || false
run cat README.md
[[ "$output" =~ "~new-text~" ]]
}
@test "docs: dolt reset should remove docs from staging area" {
echo ~license~ > LICENSE.md
echo ~readme~ > README.md
dolt add .
dolt reset
run dolt status
[ "$status" -eq 0 ]
[[ ! "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ "Untracked files:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
dolt add .
dolt commit -m "initial doc commit"
echo ~new-text~ > README.md
dolt add .
dolt reset
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes not staged for commit:" ]] || false
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*README.md) ]] || false
run cat README.md
[[ "$output" =~ "~new-text~" ]]
}
@test "docs: dolt reset <doc> should remove doc from staging area" {
echo "license" > LICENSE.md
echo "readme" > README.md
dolt add LICENSE.md
run dolt reset dolt_docs
[ "$status" -eq 1 ]
[[ "$output" =~ "'dolt_docs' is not a valid table name" ]] || false
dolt reset LICENSE.md
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Untracked files:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
dolt add .
run dolt reset LICENSE.md invalid
[ "$status" -eq 1 ]
[[ "$output" =~ "Invalid Table(s)" ]] || false
[[ "$output" =~ "invalid" ]] || false
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
dolt reset README.md
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
dolt commit -m "initial license commit"
echo new > LICENSE.md
dolt add .
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
dolt reset README.md LICENSE.md
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes not staged for commit:" ]] || false
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ "Untracked files:" ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
}
@test "docs: dolt reset <table> <doc> resets tables and docs from staging area" {
echo readme > README.md
echo license > LICENSE.md
dolt add .
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
dolt add test
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ ([[:space:]]*new table:[[:space:]]*test) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ ([[:space:]]*new doc:[[:space:]]*README.md) ]] || false
dolt reset test LICENSE.md README.md
run dolt status
[[ ! "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ "Untracked files:" ]] || false
[[ "$output" =~ (new table:[[:space:]]*test) ]] || false
[[ "$output" =~ (new doc:[[:space:]]*LICENSE.md) ]] || false
[[ "$output" =~ (new doc:[[:space:]]*README.md) ]] || false
}
@test "docs: dolt checkout <doc> should save the staged docs to the filesystem if the doc has already been added" {
echo "this is my license" > LICENSE.md
echo "this is my readme" > README.md
dolt add .
dolt checkout LICENSE.md
run cat LICENSE.md
[[ "$output" =~ "this is my license" ]] || false
run cat README.md
[[ "$output" =~ "this is my readme" ]] || false
echo "testing-modified-doc" > LICENSE.md
dolt checkout LICENSE.md
run cat LICENSE.md
[[ "$output" =~ "this is my license" ]] || false
run cat README.md
[[ "$output" =~ "this is my readme" ]] || false
}
@test "docs: dolt checkout <doc> should save the head docs to the filesystem when the doc exists on the head, and has not been staged" {
echo "this is my license" > LICENSE.md
echo "this is my readme" > README.md
dolt add .
dolt commit -m "committing license"
echo "this is new" > LICENSE.md
dolt checkout LICENSE.md
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
run cat LICENSE.md
[[ "$output" =~ "this is my license" ]] || false
run cat README.md
[[ "$output" =~ "this is my readme" ]] || false
}
@test "docs: dolt checkout <doc> should delete the doc from filesystem if it doesn't exist on staged or head roots" {
echo "readme" > README.md
echo "license" > LICENSE.md
dolt checkout README.md
run dolt status
[ "$status" -eq 0 ]
[[ ! "$output" =~ "README.md" ]] || false
run ls
[[ ! "$output" =~ "README.md" ]] || false
[[ "$output" =~ "LICENSE.md" ]] || false
}
@test "docs: dolt checkout <doc> <table> should checkout both doc and table" {
echo "a license" > LICENSE.md
echo "a readme" > README.md
dolt sql <<SQL
CREATE TABLE test1 (
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
dolt status
dolt checkout LICENSE.md test1
run dolt status
[[ ! "$output" =~ "LICENSE.md" ]] || false
[[ ! "$output" =~ "test1" ]] || false
[[ "$output" =~ "README.md" ]] || false
run ls
[[ ! "$output" =~ "LICENSE.md" ]] || false
[[ "$output" =~ "README.md" ]] || false
run cat README.md
[[ "$output" =~ "a readme" ]] || false
echo "new readme" > README.md
dolt sql <<SQL
CREATE TABLE test2 (
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
dolt add .
dolt sql -q "insert into test2 (pk) values (100)"
echo New text in readme > README.md
dolt checkout test2 README.md
run cat README.md
[[ "$output" =~ "new readme" ]] || false
run dolt table select test2
[[ ! "$output" =~ "100" ]] || false
}
@test "docs: dolt checkout <doc> <invalid_arg> should return an error and leave doc unchanged" {
echo original readme text > README.md
echo original license text > LICENSE.md
dolt add .
dolt commit -m "initial doc commit"
echo updated license > LICENSE.md
run dolt checkout LICENSE.md invalid
[ "$status" -eq 1 ]
[[ "$output" =~ "'invalid' did not match any table(s) known to dolt." ]] || false
run cat LICENSE.md
[[ "$output" =~ "updated license" ]] || false
run cat README.md
[[ "$output" =~ "original readme text" ]] || false
}
@test "docs: dolt checkout <branch> should save docs to the file system, leaving any untracked files" {
echo readme > README.md
echo license > LICENSE.md
dolt add LICENSE.md
dolt commit -m "license commit"
dolt checkout -b test-branch
run cat README.md
[[ "$output" =~ "readme" ]] || false
run cat LICENSE.md
[[ "$output" =~ "license" ]] || false
echo new-license > LICENSE.md
rm README.md
dolt add .
dolt commit -m "updated license"
dolt checkout master
run cat LICENSE.md
[[ "$output" =~ "license" ]] || false
run ls
[[ ! "$output" =~ "README.md" ]] || false
dolt checkout test-branch
run ls
[[ "$output" =~ "LICENSE.md" ]] || false
[[ ! "$output" =~ "README.md" ]] || false
run cat LICENSE.md
[[ "$output" =~ "new-license" ]] || false
}
@test "docs: dolt checkout <branch>, assuming no conflicts, should preserve changes in the working set (on the filesystem)" {
echo readme > README.md
echo license > LICENSE.md
dolt add LICENSE.md README.md
dolt commit -m "initial license and readme commit"
echo updated-readme > README.md
dolt checkout -b test-branch
run dolt status
[[ "$output" =~ "README.md" ]] || false
run cat README.md
[[ "$output" =~ "updated-readme" ]] || false
run cat LICENSE.md
[[ "$output" =~ "license" ]] || false
dolt add README.md
dolt commit -m "commit of updated-readme"
echo "another new README!" > README.md
dolt checkout master
run dolt status
[[ "$output" =~ "README.md" ]] || false
run cat README.md
[[ "$output" =~ "another new README!" ]] || false
}
@test "docs: dolt diff shows diffs between working root and file system docs" {
# 2 added docs
echo "testing readme" > README.md
echo "testing license" > LICENSE.md
run dolt diff
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/LICENSE.md b/LICENSE.md" ]] || false
[[ "$output" =~ "diff --dolt a/README.md b/README.md" ]] || false
[[ "$output" =~ "added doc" ]] || false
dolt add .
run dolt diff
[ "$status" -eq 0 ]
[ "$output" = "" ]
dolt commit -m "docs"
# 1 modified doc, 1 other doc on working root with no changes
echo "a new readme" > README.md
run dolt diff
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/README.md b/README.md" ]] || false
[[ "$output" =~ "--- a/README.md" ]] || false
[[ "$output" =~ "+++ b/README.md" ]] || false
[[ "$output" =~ "- testing readme" ]] || false
[[ "$output" =~ "+ a new readme" ]] || false
[[ ! "$output" =~ "LICENSE.md" ]] || false
dolt add .
dolt commit -m "modified README.md"
# 1 deleted doc, 1 other doc on working root with no changes
rm LICENSE.md
run dolt diff
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/LICENSE.md b/LICENSE.md" ]] || false
[[ "$output" =~ "- testing license" ]] || false
[[ "$output" =~ "deleted doc" ]] || false
[[ ! "$output" =~ "README.md" ]] || false
dolt add .
dolt commit -m "deleted LICENSE.md"
# 1 modified doc, no other docs on working root
echo "A new README.md " > README.md
run dolt diff
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/README.md b/README.md" ]] || false
[[ "$output" =~ "--- a/README.md" ]] || false
[[ "$output" =~ "+++ b/README.md" ]] || false
[[ ! "$output" =~ "LICENSE.md" ]] || false
}
@test "docs: dolt diff <doc> shows diff of one <doc> between working root and file system docs" {
echo "testing readme" > README.md
echo "testing license" > LICENSE.md
run dolt diff README.md
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/README.md b/README.md" ]] || false
[[ "$output" =~ "added doc" ]] || false
[[ ! "$output" =~ "LICENSE.md" ]] || false
run dolt diff LICENSE.md
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/LICENSE.md b/LICENSE.md" ]] || false
[[ "$output" =~ "added doc" ]] || false
[[ ! "$output" =~ "README.md" ]] || false
dolt add .
dolt commit -m "docs"
echo "a new readme" > README.md
echo "a new license" > LICENSE.md
run dolt diff README.md
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/README.md b/README.md" ]] || false
[[ "$output" =~ "--- a/README.md" ]] || false
[[ "$output" =~ "+++ b/README.md" ]] || false
[[ "$output" =~ "- testing readme" ]] || false
[[ "$output" =~ "+ a new readme" ]] || false
[[ ! "$output" =~ "LICENSE.md" ]] || false
run dolt diff LICENSE.md
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/LICENSE.md b/LICENSE.md" ]] || false
[[ "$output" =~ "--- a/LICENSE.md" ]] || false
[[ "$output" =~ "+++ b/LICENSE.md" ]] || false
[[ "$output" =~ "- testing license" ]] || false
[[ "$output" =~ "+ a new license" ]] || false
[[ ! "$output" =~ "README.md" ]] || false
rm README.md
rm LICENSE.md
run dolt diff LICENSE.md
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/LICENSE.md b/LICENSE.md" ]] || false
[[ "$output" =~ "- testing license" ]] || false
[[ "$output" =~ "deleted doc" ]] || false
[[ ! "$output" =~ "README" ]] || false
run dolt diff README.md
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/README.md b/README.md" ]] || false
[[ "$output" =~ "- testing readme" ]] || false
[[ "$output" =~ "deleted doc" ]] || false
[[ ! "$output" =~ "LICENSE" ]] || false
}
@test "docs: dolt table commands do not allow write operations on dolt_docs" {
echo "a readme" > README.md
echo "a license" > LICENSE.md
dolt add .
dolt commit -m "First commit of docs"
run dolt table cp dolt_docs another_table
[ "$status" -eq 0 ]
run dolt table export dolt_docs test.csv
[ "$status" -eq 0 ]
run dolt table import dolt_docs -c `batshelper 1pk5col-ints.csv`
[ "$status" -eq 1 ]
[[ "$output" =~ "reserved" ]] || false
run dolt table mv dolt_docs new
[ "$status" -eq 1 ]
[[ "$output" =~ "system table" ]] || false
run dolt table rm dolt_docs
[ "$status" -eq 1 ]
[[ "$output" =~ "system table" ]] || false
}
@test "docs: dolt schema command does not show dolt_docs" {
echo "a readme" > README.md
echo "a license" > LICENSE.md
dolt add .
dolt commit -m "First commit of docs"
run dolt schema import -c --pks=pk dolt_docs `batshelper 1pk5col-ints.csv`
[ "$status" -eq 1 ]
[[ "$output" =~ "reserved" ]] || false
run dolt schema show dolt_docs
[ "$status" -eq 1 ]
[[ "$output" =~ "not found" ]] || false
run dolt schema show
[ "$status" -eq 0 ]
[[ "$output" =~ "No tables in working set" ]] || false
dolt table import -c -s `batshelper employees-sch.sql` employees `batshelper employees-tbl.json`
run dolt schema show
[ "$status" -eq 0 ]
[[ "$output" =~ "employees @ working" ]] || false
[[ ! "$output" =~ "dolt_docs" ]] || false
}
@test "docs: dolt ls should not show dolt_docs table" {
echo "a readme" > README.md
echo "a license" > LICENSE.md
run dolt ls
[ "$status" -eq 0 ]
[[ ! "$output" =~ "dolt_docs" ]] || false
dolt add .
run dolt ls
[ "$status" -eq 0 ]
[[ ! "$output" =~ "dolt_docs" ]] || false
dolt commit -m "First commit of docs"
run dolt ls
[ "$status" -eq 0 ]
[[ ! "$output" =~ "dolt_docs" ]] || false
}
@test "docs: dolt sql operation on dolt_docs" {
echo "a readme" > README.md
echo "a license" > LICENSE.md
run dolt sql -q "show tables"
[ "$status" -eq 0 ]
[[ ! "$output" =~ "dolt_docs" ]] || false
run dolt sql -q "CREATE TABLE dolt_docs (doc_name TEXT, doc_text LONGTEXT, PRIMARY KEY(doc_name))"
[ "$status" -eq 1 ]
[[ "$output" =~ "reserved" ]] || false
dolt add .
dolt commit -m "initial doc commits"
run dolt sql -q "show tables"
[ "$status" -eq 0 ]
[[ ! "$output" =~ "dolt_docs" ]] || false
run dolt sql -q "INSERT INTO dolt_docs VALUES ('new_doc', 'new_text')"
[ "$status" -eq 1 ]
[[ "$output" =~ "table doesn't support" ]] || false
run dolt sql -q "DELETE FROM dolt_docs WHERE doc_name='REAMDE.md'"
[ "$status" -eq 1 ]
[[ "$output" =~ "table doesn't support" ]] || false
run dolt sql -q "UPDATE dolt_docs SET doc_name='new_doc' WHERE doc_name='README.md'"
[ "$status" -eq 1 ]
[[ "$output" =~ "table doesn't support" ]] || false
run dolt sql -q "SELECT * FROM dolt_docs" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "doc_name,doc_text" ]] || false
[[ "$output" =~ "README.md" ]] || false
[[ "$output" =~ "LICENSE.md" ]] || false
run dolt sql -q "ALTER TABLE dolt_docs ADD a int"
[ "$status" -eq 1 ]
[[ "$output" =~ "cannot be altered" ]] || false
run dolt sql -q "RENAME TABLE dolt_docs TO new_table"
[ "$status" -eq 1 ]
[[ "$output" =~ "system tables cannot be dropped or altered" ]] || false
}
@test "docs: dolt branch/merge with conflicts for docs" {
echo "a readme" > README.md
echo "a license" > LICENSE.md
dolt add .
dolt commit -m "Committing initial docs"
dolt branch test-a
dolt branch test-b
dolt checkout test-a
echo test-a branch > README.md
dolt add .
dolt commit -m "Changed README.md on test-a branch"
dolt checkout test-b
run cat README.md
[[ $output =~ "a readme" ]] || false
[[ ! $output =~ "test-a branch" ]] || false
echo test-b branch > README.md
dolt add .
dolt commit -m "Changed README.md on test-a branch"
dolt checkout master
# On successful FF merge, docs match the new working root
run dolt merge test-a
[ "$status" -eq 0 ]
[[ $output =~ "Fast-forward" ]] || false
run cat README.md
[[ "$output" =~ "test-a branch" ]] || false
# A merge with conflicts does not change the working root.
# If the conflicts are resolved with --ours, the working root and the docs on the filesystem remain the same.
run dolt merge test-b
[ "$status" -eq 0 ]
[[ $output =~ "CONFLICT" ]] || false
run cat README.md
[[ "$output" =~ "test-a branch" ]] || false
run dolt conflicts cat dolt_docs
[ "$status" -eq 0 ]
[[ $output =~ "test-a branch" ]] || false
[[ $output =~ "test-b branch" ]] || false
dolt conflicts resolve dolt_docs --ours
run cat README.md
[[ ! $output =~ "test-b branch" ]] || false
[[ $output =~ "test-a branch" ]] || false
# Only allow `dolt add dolt_docs` when dolt_docs is in conflict
dolt add dolt_docs
dolt commit -m "Resolved docs conflict with --ours"
# If the conflicts are resolved with --theirs, the working root and the docs on the filesystem are updated.
dolt branch test-a-again
dolt branch test-b-again
dolt checkout test-a-again
echo test-a-again branch > README.md
dolt add .
dolt commit -m "Changed README.md on test-a-again branch"
dolt checkout test-b-again
echo test-b-again branch > README.md
dolt add .
dolt commit -m "Changed README.md on test-b-again branch"
dolt checkout master
dolt merge test-a-again
dolt merge test-b-again
dolt conflicts resolve dolt_docs --theirs
run cat README.md
[[ ! $output =~ "test-a-again branch" ]] || false
[[ $output =~ "test-b-again branch" ]] || false
dolt add .
dolt commit -m "merge test-b-again with fixed conflicts"
# A merge with auto-resolved conflicts updates the working root. The docs should match the new working root.
dolt checkout test-b-again
echo test-b-one-more-time > README.md
dolt add .
dolt commit -m "test-b-one-more-time"
dolt checkout master
dolt merge test-b-again
run cat README.md
[[ "$output" =~ "one-more-time" ]] || false
run dolt status
echo "output = $output"
[[ "$output" =~ "All conflicts fixed" ]] || false
[[ "$output" =~ "Changes to be committed:" ]] || false
[[ "$output" =~ "README.md" ]] || false
}

View File

@@ -0,0 +1,201 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
assert_feature_version
teardown_common
}
# Tests on an empty dolt repository
@test "empty-repo: dolt init on an already initialized repository" {
run dolt init
[ "$status" -ne 0 ]
[ "$output" = "This directory has already been initialized." ]
}
@test "empty-repo: dolt status on a new repository" {
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch master" ]] || false
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
[[ ! "$output" =~ "Untracked files:" ]] || false
[[ ! "$output" =~ "LICENSE.md" ]] || false
[[ ! "$output" =~ "README.md" ]] || false
}
@test "empty-repo: dolt ls in a new repository" {
run dolt ls
[ "$status" -eq 0 ]
[ "$output" = "No tables in working set" ]
}
@test "empty-repo: dolt branch in a new repository" {
run dolt branch
[ "$status" -eq 0 ]
# I can't seem to get this to match "* master" so I made a regex instead
# [ "$output" = "* master" ]
[[ "$output" =~ "* master" ]] || false
}
@test "empty-repo: dolt log in a new repository" {
run dolt log
[ "$status" -eq 0 ]
[[ "$output" =~ "commit " ]] || false
[[ "$output" =~ "Initialize data repository" ]] || false
}
@test "empty-repo: dolt add . in new repository" {
run dolt add .
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
@test "empty-repo: dolt reset in new repository" {
run dolt reset
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
@test "empty-repo: dolt diff in new repository" {
run dolt diff
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
@test "empty-repo: dolt commit with nothing added" {
run dolt commit -m "commit"
[ "$status" -eq 1 ]
[ "$output" = 'no changes added to commit (use "dolt add")' ]
}
@test "empty-repo: dolt commit --allow-empty with nothing added" {
run dolt commit -m "distinctively-named commit" --allow-empty
[ "$status" -eq 0 ]
run dolt log
[[ "$output" =~ "distinctively-named commit" ]] || false
}
@test "empty-repo: dolt sql in a new repository" {
run dolt sql -q "select * from test"
[ "$status" -eq 1 ]
[[ "$output" = "table not found: test" ]] || false
}
@test "empty-repo: invalid sql in a new repository" {
run dolt sql -q "foo bar"
[ "$status" -eq 1 ]
[[ "$output" =~ "Error parsing SQL" ]] || false
}
@test "empty-repo: dolt schema show in new repository" {
run dolt schema show
[ "$status" -eq 0 ]
[[ "$output" =~ "No tables in working set" ]] || false
}
@test "empty-repo: dolt table select in new repository" {
run dolt sql -q "select * from test"
[ "$status" -ne 0 ]
}
@test "empty-repo: dolt table import in a new repository" {
run dolt table import
[ "$status" -ne 0 ]
[[ "$output" =~ "usage" ]] || false
}
@test "empty-repo: dolt table export in a new repository" {
run dolt table export
[ "$status" -ne 0 ]
[[ "${lines[0]}" =~ "usage" ]] || false
}
@test "empty-repo: dolt table rm in a new repository" {
run dolt table rm
[ "$status" -ne 0 ]
[[ "${lines[0]}" =~ "usage" ]] || false
}
@test "empty-repo: dolt table cp in a new repository" {
run dolt table cp
[ "$status" -ne 0 ]
[[ "${lines[0]}" =~ "usage" ]] || false
}
@test "empty-repo: dolt checkout master on master" {
run dolt checkout master
[ "$status" -eq 1 ]
[ "$output" = "Already on branch 'master'" ]
}
@test "empty-repo: dolt checkout non-existant branch" {
run dolt checkout foo
[ "$status" -ne 0 ]
[ "$output" = "error: could not find foo" ]
}
@test "empty-repo: create and checkout a branch" {
run dolt branch test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt checkout test
[ "$status" -eq 0 ]
[ "$output" = "Switched to branch 'test'" ]
run dolt branch
[ "$status" -eq 0 ]
[[ "$output" =~ "* test" ]] || false
}
@test "empty-repo: create and checkout a branch with dolt checkout -b" {
run dolt checkout -b test
[ "$status" -eq 0 ]
[ "$output" = "Switched to branch 'test'" ]
run dolt branch
[ "$status" -eq 0 ]
[[ "$output" =~ "* test" ]] || false
}
@test "empty-repo: delete a branch" {
dolt branch test
run dolt branch -d test
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt branch
[[ ! "$output" =~ "test" ]] || false
}
@test "empty-repo: move a branch" {
dolt branch foo
run dolt branch -m foo bar
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt branch
[[ ! "$output" =~ "foo" ]] || false
[[ "$output" =~ "bar" ]] || false
}
@test "empty-repo: copy a branch" {
dolt branch foo
run dolt branch -c foo bar
[ "$status" -eq 0 ]
[ "$output" = "" ]
run dolt branch
[[ "$output" =~ "foo" ]] || false
[[ "$output" =~ "bar" ]] || false
}
@test "empty-repo: branch names must support /" {
run dolt branch tim/test-this-format-11
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
@test "empty-repo: branch names do not support ." {
run dolt branch "dots.are.not.supported"
[ "$status" -eq 1 ]
[ "$output" = "fatal: 'dots.are.not.supported' is an invalid branch name." ]
}

View File

@@ -0,0 +1,162 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
dolt sql <<SQL
CREATE TABLE test_int (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
CREATE TABLE test_string (
pk LONGTEXT NOT NULL,
c1 LONGTEXT,
c2 LONGTEXT,
c3 LONGTEXT,
c4 LONGTEXT,
c5 LONGTEXT,
PRIMARY KEY (pk)
);
SQL
}
teardown() {
assert_feature_version
teardown_common
}
@test "export-tables: table export sql datetime" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT PRIMARY KEY,
v1 DATE,
v2 TIME,
v3 YEAR,
v4 DATETIME
);
INSERT INTO test VALUES
(1,'2020-04-08','11:11:11','2020','2020-04-08 11:11:11'),
(2,'2020-04-08','12:12:12','2020','2020-04-08 12:12:12');
SQL
dolt table export test test.sql
run cat test.sql
[[ "$output" =~ "INSERT INTO \`test\` (\`pk\`,\`v1\`,\`v2\`,\`v3\`,\`v4\`) VALUES (1,'2020-04-08','11:11:11','2020','2020-04-08 11:11:11');" ]] || false
[[ "$output" =~ "INSERT INTO \`test\` (\`pk\`,\`v1\`,\`v2\`,\`v3\`,\`v4\`) VALUES (2,'2020-04-08','12:12:12','2020','2020-04-08 12:12:12');" ]] || false
dolt table export test test.json
run cat test.json
[ "$output" = '{"rows": [{"pk":1,"v1":"2020-04-08","v2":"11:11:11","v3":"2020","v4":"2020-04-08 11:11:11"},{"pk":2,"v1":"2020-04-08","v2":"12:12:12","v3":"2020","v4":"2020-04-08 12:12:12"}]}' ]
}
@test "export-tables: dolt table import from stdin export to stdout" {
skiponwindows "Need to install python before this test will work."
echo 'pk,c1,c2,c3,c4,c5
0,1,2,3,4,5
9,8,7,6,5,4
'|dolt table import -u test_int
dolt table export --file-type=csv test_int|python -c '
import sys
rows = []
for line in sys.stdin:
line = line.strip()
if line != "":
rows.append(line.strip().split(","))
if len(rows) != 3:
sys.exit(1)
if rows[0] != "pk,c1,c2,c3,c4,c5".split(","):
sys.exit(1)
if rows[1] != "0,1,2,3,4,5".split(","):
sys.exit(1)
if rows[2] != "9,8,7,6,5,4".split(","):
sys.exit(1)
'
}
@test "export-tables: dolt table export" {
dolt sql -q "insert into test_int values (0, 1, 2, 3, 4, 5)"
run dolt table export test_int export.csv
[ "$status" -eq 0 ]
[[ "$output" =~ "Successfully exported data." ]] || false
[ -f export.csv ]
run grep 5 export.csv
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 2 ]
run dolt table export test_int export.csv
[ "$status" -ne 0 ]
[[ "$output" =~ "export.csv already exists" ]] || false
run dolt table export -f test_int export.csv
[ "$status" -eq 0 ]
[[ "$output" =~ "Successfully exported data." ]] || false
[ -f export.csv ]
}
@test "export-tables: dolt table SQL export" {
dolt sql -q "insert into test_int values (0, 1, 2, 3, 4, 5)"
run dolt table export test_int export.sql
[ "$status" -eq 0 ]
[[ "$output" =~ "Successfully exported data." ]] || false
[ -f export.sql ]
diff --strip-trailing-cr $BATS_TEST_DIRNAME/helper/1pk5col-ints.sql export.sql
}
@test "export-tables: export a table with a string with commas to csv" {
run dolt sql -q "insert into test_string values ('tim', 'is', 'super', 'duper', 'rad', 'a,b,c,d,e')"
[ "$status" -eq 0 ]
run dolt table export test_string export.csv
[ "$status" -eq 0 ]
[[ "$output" =~ "Successfully exported data." ]] || false
grep -E \"a,b,c,d,e\" export.csv
}
@test "export-tables: export a table with a string with double quotes to csv" {
run dolt sql -q 'insert into test_string (pk,c1,c5) values ("this", "is", "a ""quotation""");'
[ "$status" -eq 0 ]
run dolt table export test_string export.csv
[ "$status" -eq 0 ]
[[ "$output" =~ "Successfully exported data." ]] || false
grep '"a ""quotation"""' export.csv
}
@test "export-tables: export a table with a string with new lines to csv" {
run dolt sql -q 'insert into test_string (pk,c1,c5) values ("this", "is", "a new \n line");'
[ "$status" -eq 0 ]
run dolt table export test_string export.csv
[ "$status" -eq 0 ]
[[ "$output" =~ "Successfully exported data." ]] || false
# output will be slit over two lines
grep 'this,is,,,,"a new ' export.csv
grep ' line"' export.csv
}
@test "export-tables: table with column with not null constraint can be exported and reimported" {
dolt sql -q "CREATE TABLE person_info(name VARCHAR(255) NOT NULL,location VARCHAR(255) NOT NULL,age BIGINT NOT NULL,PRIMARY KEY (name));"
dolt add .
dolt commit -m 'add person_info table'
dolt sql -q "INSERT INTO person_info (name, location, age) VALUES ('kevern smith', 'los angeles', 21);"
dolt sql -q "INSERT INTO person_info (name, location, age) VALUES ('barbara smith', 'los angeles', 24);"
# insert empty value in not null column
dolt sql -q "INSERT INTO person_info (name, location, age) VALUES ('gary busy', '', 900);"
dolt sql -q "INSERT INTO person_info (name, location, age) VALUES ('the tampa bay buccs', 'florida', 123);"
dolt sql -q "INSERT INTO person_info (name, location, age) VALUES ('michael fakeperson', 'fake city', 39);"
# create csvs
dolt sql -r csv -q 'select * from person_info' > sql-csv.csv
dolt table export person_info export-csv.csv
dolt checkout person_info
run dolt table import -u person_info sql-csv.csv
[ "$status" -eq 0 ]
run dolt table import -u person_info export-csv.csv
[ "$status" -eq 0 ]
}

View File

@@ -0,0 +1,128 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
teardown_common
}
# client FeatureVersion must be >= repo FeatureVersion to read
# read with maximum FeatureVersion for assersions
MAX=1000
OLD=10
NEW=20
@test "feature-version: set feature version with CLI flag" {
dolt --feature-version 19 sql -q "CREATE TABLE test (pk int PRIMARY KEY)"
run dolt --feature-version $MAX version --feature
[[ "$output" =~ "feature version: 19" ]] || false
}
@test "feature-version: new client writes to table, locking out old client" {
run dolt --feature-version $OLD sql <<SQL
CREATE TABLE test (pk int PRIMARY KEY);
INSERT INTO test VALUES (10),(11),(12);
SQL
[ "$status" -eq 0 ]
run dolt --feature-version $NEW sql -q "INSERT INTO test VALUES (20),(21),(22);"
[ "$status" -eq 0 ]
# old client can't read or write
run dolt --feature-version $OLD sql -q "SELECT * FROM test"
[ "$status" -ne 0 ]
[[ ! "$output" =~ "panic" ]] || false
run dolt --feature-version $OLD sql -q "INSERT INTO test VALUES (13);"
[ "$status" -ne 0 ]
[[ ! "$output" =~ "panic" ]] || false
run dolt --feature-version $MAX version --feature
[ "$status" -eq 0 ]
[[ "$output" =~ "feature version: $NEW" ]] || false
}
setup_remote_tests() {
# remote repo from top-level test directory
rm -rf .dolt/
# create a new repo and a remote
mkdir remote first_repo
pushd first_repo
dolt --feature-version $OLD init
dolt --feature-version $OLD remote add origin file://../remote/
# add some data and push
dolt --feature-version $OLD sql <<SQL
CREATE TABLE test (pk int PRIMARY KEY);
INSERT INTO test VALUES (10),(11),(12);
SQL
dolt --feature-version $OLD add .
dolt --feature-version $OLD commit -m "test table"
dolt --feature-version $OLD push origin master
popd
# clone repo
dolt --feature-version $OLD clone file://remote clone_repo
}
@test "feature-version: pulling newer FeatureVersion locks out old client" {
setup_remote_tests
pushd first_repo
dolt --feature-version $NEW sql -q "INSERT INTO test VALUES (20);"
dolt --feature-version $NEW commit -am "added row with new FeatureVersion on master"
dolt --feature-version $NEW push origin master
popd
pushd clone_repo
run dolt --feature-version $NEW sql -q "SELECT count(*) FROM test;" -r csv
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "3" ]] || false
run dolt --feature-version $MAX version --feature
[ "$status" -eq 0 ]
[[ "$output" =~ "feature version: $OLD" ]] || false
# pull fails with old FeatureVersion
run dolt --feature-version $OLD pull
[ "$status" -ne 0 ]
# pull succeeds with old FeatureVersion
run dolt --feature-version $NEW pull
[ "$status" -eq 0 ]
run dolt --feature-version $NEW sql -q "SELECT count(*) FROM test;" -r csv
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "4" ]] || false
run dolt --feature-version $MAX version --feature
[ "$status" -eq 0 ]
[[ "$output" =~ "feature version: $NEW" ]] || false
}
@test "feature-version: older client maintains access to feature branch" {
setup_remote_tests
pushd clone_repo
dolt --feature-version $OLD checkout -b other
dolt --feature-version $OLD sql -q "INSERT INTO test VALUES (13);"
dolt --feature-version $OLD commit -am "made some changes on branch other"
popd
pushd first_repo
dolt --feature-version $NEW sql -q "INSERT INTO test VALUES (20);"
dolt --feature-version $NEW commit -am "added row with new FeatureVersion on master"
dolt --feature-version $NEW push origin master
popd
pushd clone_repo
dolt --feature-version $OLD fetch
dolt --feature-version $OLD checkout master
run dolt --feature-version $OLD pull
[ "$status" -ne 0 ]
[[ "$output" =~ "visit https://github.com/dolthub/dolt/releases/latest/" ]] || false
dolt --feature-version $OLD sql -q "SELECT * FROM test"
dolt --feature-version $OLD checkout other
popd
}

View File

@@ -0,0 +1,251 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
dolt sql <<SQL
CREATE TABLE test (
pk int NOT NULL PRIMARY KEY,
c0 int
);
INSERT INTO test VALUES
(0,0),(1,1),(2,2);
CREATE TABLE to_drop (
pk int PRIMARY KEY
);
SQL
dolt add -A
dolt commit -m "added table test"
}
teardown() {
assert_feature_version
teardown_common
}
@test "filter-branch: smoke-test" {
dolt sql -q "INSERT INTO test VALUES (7,7),(8,8),(9,9);"
dolt add -A && dolt commit -m "added more rows"
dolt filter-branch "DELETE FROM test WHERE pk > 1;"
run dolt sql -q "SELECT count(*) FROM test" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2" ]] || false
dolt sql -q "SELECT max(pk), max(c0) FROM dolt_history_test;" -r csv
run dolt sql -q "SELECT max(pk), max(c0) FROM dolt_history_test;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "1,1" ]] || false
}
@test "filter-branch: filter multiple branches" {
dolt branch other
dolt sql -q "INSERT INTO test VALUES (7,7),(8,8),(9,9);"
dolt add -A && dolt commit -m "added more rows"
dolt checkout other
dolt sql -q "INSERT INTO test VALUES (4,4),(5,5),(6,6);"
dolt add -A && dolt commit -m "added more rows"
dolt checkout master
dolt filter-branch --all "DELETE FROM test WHERE pk > 4;"
run dolt sql -q "SELECT pk,c0 FROM dolt_history_test ORDER BY pk" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "0,0" ]] || false
[[ "$output" =~ "0,0" ]] || false
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "2,2" ]] || false
dolt checkout other
run dolt sql -q "SELECT pk,c0 FROM dolt_history_test ORDER BY pk" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "0,0" ]] || false
[[ "$output" =~ "0,0" ]] || false
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "1,1" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "2,2" ]] || false
[[ "$output" =~ "4,4" ]] || false
}
@test "filter-branch: with missing table" {
dolt sql -q "DROP TABLE test;"
dolt add -A && dolt commit -m "dropped test"
# filter-branch warns about missing table but doesn't error
run dolt filter-branch "DELETE FROM test WHERE pk > 1;"
[ "$status" -eq 0 ]
[[ "$output" =~ "table not found: test" ]] || false
run dolt sql -q "SELECT count(*) FROM test AS OF 'HEAD~1';" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2" ]] || false
}
@test "filter-branch: forks history" {
dolt branch other
dolt sql -q "INSERT INTO test VALUES (7,7),(8,8),(9,9);"
dolt add -A && dolt commit -m "added more rows"
dolt filter-branch "DELETE FROM test WHERE pk > 1;"
dolt checkout other
run dolt sql -q "SELECT * FROM test WHERE pk > 1" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2,2" ]] || false
}
@test "filter-branch: filter until commit" {
dolt sql -q "INSERT INTO test VALUES (7,7)"
dolt add -A && dolt commit -m "added (7,7)"
dolt sql -q "INSERT INTO test VALUES (8,8)"
dolt add -A && dolt commit -m "added (8,8)"
dolt sql -q "INSERT INTO test VALUES (9,9)"
dolt add -A && dolt commit -m "added (9,9)"
dolt filter-branch "DELETE FROM test WHERE pk > 2;" HEAD~2
run dolt sql -q "SELECT max(pk), max(c0) FROM test AS OF 'HEAD';" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2,2" ]] || false
run dolt sql -q "SELECT max(pk), max(c0) FROM test AS OF 'HEAD~1';" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2,2" ]] || false
run dolt sql -q "SELECT max(pk), max(c0) FROM test AS OF 'HEAD~2';" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "7,7" ]] || false
}
function setup_write_test {
dolt sql -q "INSERT INTO test VALUES (4,4);"
dolt add -A && dolt commit -m "4"
dolt sql -q "INSERT INTO test VALUES (5,5);"
dolt add -A && dolt commit -m "5"
}
@test "filter-branch: INSERT INTO" {
setup_write_test
dolt filter-branch "INSERT INTO test VALUES (9,9);"
run dolt sql -q "SELECT pk,c0 FROM dolt_history_test ORDER BY pk DESC LIMIT 4;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "9,9" ]] || false
[[ "$output" =~ "9,9" ]] || false
[[ "$output" =~ "9,9" ]] || false
[[ "$output" =~ "5,5" ]] || false
}
@test "filter-branch: UPDATE" {
setup_write_test
dolt filter-branch "UPDATE test SET c0 = 9 WHERE pk = 2;"
run dolt sql -q "SELECT pk,c0 FROM dolt_history_test ORDER BY c0 DESC LIMIT 4;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "2,9" ]] || false
[[ "$output" =~ "2,9" ]] || false
[[ "$output" =~ "2,9" ]] || false
[[ "$output" =~ "5,5" ]] || false
}
@test "filter-branch: ADD/DROP column" {
setup_write_test
dolt filter-branch "ALTER TABLE TEST ADD COLUMN c1 int;"
for commit in HEAD HEAD~1 HEAD~2; do
run dolt sql -q "SELECT * FROM test AS OF '$commit';" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "pk,c0,c1" ]] || false
done
dolt filter-branch "ALTER TABLE TEST DROP COLUMN c0;"
for commit in HEAD HEAD~1 HEAD~2; do
run dolt sql -q "SELECT * FROM test AS OF '$commit';" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "pk,c1" ]] || false
done
}
@test "filter-branch: ADD/DROP table" {
setup_write_test
for commit in HEAD HEAD~1 HEAD~2; do
run dolt sql -q "SHOW TABLES AS OF '$commit';" -r csv
[ "$status" -eq 0 ]
[[ ! "$output" =~ "added" ]] || false
done
dolt filter-branch "CREATE TABLE added (pk int PRIMARY KEY);"
for commit in HEAD HEAD~1 HEAD~2; do
run dolt sql -q "SHOW TABLES AS OF '$commit';" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "added" ]] || false
done
for commit in HEAD HEAD~1 HEAD~2; do
run dolt sql -q "SHOW TABLES AS OF '$commit';" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "to_drop" ]] || false
done
dolt filter-branch "DROP TABLE to_drop;"
for commit in HEAD HEAD~1 HEAD~2; do
run dolt sql -q "SHOW TABLES AS OF '$commit';" -r csv
[ "$status" -eq 0 ]
[[ ! "$output" =~ "to_drop" ]] || false
done
}
@test "filter-branch: error on conflict" {
setup_write_test
run dolt filter-branch "INSERT INTO test VALUES (1,2);"
[ "$status" -ne 0 ]
[[ ! "$output" =~ "panic" ]] || false
run dolt filter-branch "REPLACE INTO test VALUES (1,2);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT pk,c0 FROM dolt_history_test WHERE pk=1;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "1,2" ]] || false
[[ "$output" =~ "1,2" ]] || false
[[ "$output" =~ "1,2" ]] || false
}
@test "filter-branch: error on incorrect schema" {
setup_write_test
dolt sql <<SQL
ALTER TABLE test ADD COLUMN c1 int;
INSERT INTO test VALUES (6,6,6);
SQL
dolt add -A && dolt commit -m "added column c1"
run dolt filter-branch "INSERT INTO test VALUES (9,9);"
[ "$status" -ne 0 ]
[[ ! "$output" =~ "panic" ]] || false
run dolt filter-branch "INSERT INTO test (pk,c0) VALUES (9,9);"
[ "$status" -eq 0 ]
run dolt sql -q "SELECT pk,c0 FROM dolt_history_test WHERE pk=9;" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "9,9" ]] || false
[[ "$output" =~ "9,9" ]] || false
[[ "$output" =~ "9,9" ]] || false
[[ "$output" =~ "9,9" ]] || false
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,190 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
remotesrv_pid=
setup() {
setup_common
cd $BATS_TMPDIR
mkdir remotes-$$
mkdir remotes-$$/empty
echo remotesrv log available here $BATS_TMPDIR/remotes-$$/remotesrv.log
remotesrv --http-port 1234 --dir ./remotes-$$ &> ./remotes-$$/remotesrv.log 3>&- &
remotesrv_pid=$!
cd dolt-repo-$$
mkdir "dolt-repo-clones"
dolt remote add test-remote http://localhost:50051/test-org/test-repo
}
teardown() {
teardown_common
kill $remotesrv_pid
rm -rf $BATS_TMPDIR/remotes-$$
}
@test "garbage_collection: dolt remotes server is running" {
ps -p $remotesrv_pid | grep remotesrv
}
@test "garbage_collection: gc on empty dir" {
dolt gc
dolt gc
dolt gc -s
}
@test "garbage_collection: smoke test" {
dolt sql <<SQL
CREATE TABLE test (pk int PRIMARY KEY);
INSERT INTO test VALUES
(1),(2),(3),(4),(5);
SQL
run dolt sql -q 'select count(*) from test' -r csv
[ "$status" -eq "0" ]
[[ "$output" =~ "5" ]] || false
dolt gc
dolt gc
run dolt gc
[ "$status" -eq "0" ]
run dolt status
[ "$status" -eq "0" ]
dolt sql <<SQL
CREATE TABLE test2 (pk int PRIMARY KEY);
INSERT INTO test2 VALUES
(1),(2),(3),(4),(5);
SQL
run dolt sql -q 'select count(*) from test' -r csv
[ "$status" -eq "0" ]
[[ "$output" =~ "5" ]] || false
run dolt sql -q 'select count(*) from test2' -r csv
[ "$status" -eq "0" ]
[[ "$output" =~ "5" ]] || false
run dolt gc
[ "$status" -eq "0" ]
run dolt status
[ "$status" -eq "0" ]
}
@test "garbage_collection: clone a remote" {
dolt sql <<SQL
CREATE TABLE test (pk int PRIMARY KEY);
INSERT INTO test VALUES (0),(1),(2);
SQL
dolt add test
dolt commit -m "test commit"
dolt push test-remote master
cd "dolt-repo-clones"
run dolt clone http://localhost:50051/test-org/test-repo
[ "$status" -eq 0 ]
cd ../
# running GC will update the manifest to version 5
run dolt gc
[ "$status" -eq 0 ]
dolt sql <<SQL
INSERT INTO test VALUES (10),(11),(12);
SQL
dolt add test
dolt commit -m "test commit2"
dolt push test-remote master
# assert that the clone still works
cd "dolt-repo-clones/test-repo"
run dolt pull
[ "$status" -eq 0 ]
run dolt sql -q "select count (*) from test" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "6" ]] || false
}
@test "garbage_collection: leave committed and uncommitted data" {
dolt sql <<SQL
CREATE TABLE test (pk int PRIMARY KEY);
INSERT INTO test VALUES
(1),(2),(3),(4),(5);
SQL
dolt add .
dolt commit -m "added values 1 - 5"
# make some garbage
dolt sql -q "INSERT INTO test VALUES (6),(7),(8);"
dolt reset --hard
# leave data in the working set
dolt sql -q "INSERT INTO test VALUES (11),(12),(13),(14),(15);"
BEFORE=$(du .dolt/noms/ | sed 's/[^0-9]*//g')
run dolt gc
[ "$status" -eq 0 ]
run dolt sql -q "SELECT sum(pk) FROM test;"
[ "$status" -eq 0 ]
[[ "$output" =~ "80" ]] || false
AFTER=$(du .dolt/noms/ | sed 's/[^0-9]*//g')
# assert space was reclaimed
echo "$BEFORE"
echo "$AFTER"
[ "$BEFORE" -gt "$AFTER" ]
}
setup_merge() {
dolt sql -q "CREATE TABLE test (pk int PRIMARY KEY, c0 int);"
dolt sql -q "CREATE TABLE quiz (pk int PRIMARY KEY, c0 int);"
dolt add . && dolt commit -m "created tables test & quiz"
dolt branch other
dolt sql -q "INSERT INTO test VALUES (0,10),(1,11),(2,12);"
dolt commit -am "added rows on master"
dolt checkout other
dolt sql -q "INSERT INTO test VALUES (0,20),(1,21),(2,22);"
dolt commit -am "added rows on other"
dolt checkout master
}
@test "garbage_collection: leave merge commit" {
setup_merge
dolt merge other
dolt gc
dolt conflicts resolve --ours .
dolt add .
dolt commit -am "resolved conflicts with ours"
run dolt sql -q "SELECT * FROM test;" -r csv
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "0,10" ]] || false
[[ "${lines[2]}" =~ "1,11" ]] || false
[[ "${lines[3]}" =~ "2,12" ]] || false
}
@test "garbage_collection: leave working pre-merge" {
setup_merge
# make a dirty working set with table quiz
dolt sql -q "INSERT INTO quiz VALUES (9,99)"
dolt merge other
dolt gc
run dolt merge --abort
[ "$status" -eq 0 ]
dolt sql -q "SELECT * FROM test;" -r csv
run dolt sql -q "SELECT * FROM test;" -r csv
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "0,10" ]] || false
[[ "${lines[2]}" =~ "1,11" ]] || false
[[ "${lines[3]}" =~ "2,12" ]] || false
dolt sql -q "SELECT * FROM quiz;" -r csv
run dolt sql -q "SELECT * FROM quiz;" -r csv
[ "$status" -eq 0 ]
[[ "${lines[1]}" =~ "9,99" ]] || false
}

View File

@@ -0,0 +1,196 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
REMOTE=http://localhost:50051/test-org/test-repo
remotesrv_pid=
setup() {
setup_common
cd $BATS_TMPDIR
mkdir remotes-$$
echo remotesrv log available here $BATS_TMPDIR/remotes-$$/remotesrv.log
remotesrv --http-port 1234 --dir ./remotes-$$ &> ./remotes-$$/remotesrv.log 3>&- &
remotesrv_pid=$!
cd dolt-repo-$$
dolt remote add test-remote $REMOTE
dolt push test-remote master
export DOLT_HEAD_COMMIT=`get_head_commit`
skiponwindows "git-dolt tests are flaky on Windows"
}
teardown() {
teardown_common
rm -rf $BATS_TMPDIR/git-repo-$$
kill $remotesrv_pid
rm -rf $BATS_TMPDIR/remotes-$$
}
@test "git-dolt: install sets up a smudge filter in the current git repository" {
init_git_repo
run git dolt install
[ "$status" -eq 0 ]
[[ "${lines[0]}" =~ "Installed git-dolt smudge filter" ]] || false
[[ "${lines[1]}" =~ "commit the changes to .gitattributes" ]] || false
run cat .gitattributes
[ "${lines[0]}" = "*.git-dolt filter=git-dolt" ]
run cat .git/config
len=${#lines[@]}
[ "${lines[len-2]}" = "[filter \"git-dolt\"]" ]
[[ "${lines[len-1]}" =~ "smudge = git-dolt-smudge" ]] || false
}
@test "git-dolt: install works in subdirectories of the git repository" {
init_git_repo
mkdir -p deeply/nested/directory
pushd deeply/nested/directory
run git dolt install
[ "$status" -eq 0 ]
popd
run cat .gitattributes
[ "${lines[0]}" = "*.git-dolt filter=git-dolt" ]
run cat .git/config
len=${#lines[@]}
[ "${lines[len-2]}" = "[filter \"git-dolt\"]" ]
[[ "${lines[len-1]}" =~ "smudge = git-dolt-smudge" ]] || false
}
@test "git-dolt: install fails with a helpful error when executed outside of a git repo" {
run git dolt install
[ "$status" -eq 1 ]
[[ "$output" =~ "couldn't find a .git directory" ]] || false
}
@test "git-dolt: link takes a remote url (and an optional revspec and destination directory), clones the repo, and outputs a pointer file" {
init_git_repo
run git dolt link $REMOTE
[ "$status" -eq 0 ]
# Ensure it reports the resolved revision
[[ "$output" =~ "revision $DOLT_HEAD_COMMIT" ]] || false
# Ensure it reports the pointer filename
[[ "$output" =~ "test-repo.git-dolt" ]] || false
# Ensure it reports the addition to .gitignore
[[ "$output" =~ "test-repo added to .gitignore" ]] || false
[ -d test-repo ]
run cat test-repo.git-dolt
[[ "${lines[0]}" =~ ^version\ [0-9]+\.[0-9]+\.[0-9]+$ ]] || false
[ "${lines[1]}" = "remote $REMOTE" ]
[ "${lines[2]}" = "revision $DOLT_HEAD_COMMIT" ]
run cat .gitignore
[[ "${lines[0]}" =~ "test-repo" ]] || false
}
@test "git-dolt: smudge filter automatically clones dolt repositories referenced in checked out git-dolt pointer files" {
init_git_repo
git dolt install
git dolt link $REMOTE
git add .
git commit -m "set up git-dolt integration"
rm -rf test-repo test-repo.git-dolt
run git checkout -- test-repo.git-dolt
[[ "$output" =~ "Found git-dolt pointer file" ]] || false
[[ "$output" =~ "Cloning remote $REMOTE" ]] || false
[ -d test-repo ]
cd test-repo
[ `get_head_commit` = "$DOLT_HEAD_COMMIT" ]
}
@test "git-dolt: fetch takes the name of a git-dolt pointer file and clones the repo to the specified revision if it doesn't exist" {
init_git_repo
create_test_pointer
run git dolt fetch test-repo
[ "$status" -eq 0 ]
[[ "$output" =~ "Dolt repository cloned from remote $REMOTE to directory test-repo at revision $DOLT_HEAD_COMMIT" ]] || false
[ -d test-repo ]
cd test-repo
[ `get_head_commit` = "$DOLT_HEAD_COMMIT" ]
}
@test "git-dolt: update updates the specified pointer file to the specified revision" {
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
dolt add test
dolt commit -m "test commit"
export NEW_DOLT_HEAD_COMMIT=`get_head_commit`
init_git_repo
create_test_pointer
run git dolt update test-repo $NEW_DOLT_HEAD_COMMIT
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Updated pointer file test-repo.git-dolt to revision $NEW_DOLT_HEAD_COMMIT. You should git commit this change." ]
run cat test-repo.git-dolt
[[ "${lines[0]}" =~ ^version\ [0-9]+\.[0-9]+\.[0-9]+$ ]] || false
[ "${lines[1]}" = "remote $REMOTE" ]
[ "${lines[2]}" = "revision $NEW_DOLT_HEAD_COMMIT" ]
}
@test "git-dolt: fails helpfully when dolt is not installed" {
mkdir TMP_PATH
pushd TMP_PATH
cp `which git` ./git
cp `which git-dolt` ./git-dolt
if [ $IS_WINDOWS = true ]; then
ORIGINAL_PATH=$PATH
export PATH=""
export WSLENV=PATH
run git dolt
export PATH=$ORIGINAL_PATH
else
PATH=`pwd` run git dolt
fi
popd
rm -rf TMP_PATH
[ "$status" -eq 1 ]
[[ "$output" =~ "It looks like Dolt is not installed on your system" ]] || false
}
@test "git-dolt: shows usage on unknown commands" {
run git dolt nonsense
[[ "$output" =~ Usage ]] || false
}
@test "git-dolt: prints usage information with no arguments" {
run git dolt
[[ "$output" =~ Usage ]] || false
}
init_git_repo() {
mkdir ../git-repo-$$
cd ../git-repo-$$
git init
git config user.email "foo@bar.com"
git config user.name "Foo User"
}
create_test_pointer() {
cat <<EOF > test-repo.git-dolt
version 0.0.0
remote $REMOTE
revision $DOLT_HEAD_COMMIT
EOF
}
get_head_commit() {
dolt log -n 1 | grep -m 1 commit | cut -c 8-
}

View File

@@ -0,0 +1,3 @@
pk,c1,c2,c3,c4,c5
0,1,2,3,4,5
1,1,2,3,4,5
1 pk c1 c2 c3 c4 c5
2 0 1 2 3 4 5
3 1 1 2 3 4 5

View File

@@ -0,0 +1,20 @@
{
"rows": [
{
"pk": 0,
"c1": 1,
"c2": 2,
"c3": 3,
"c4": 4,
"c5": 5
},
{
"pk": 1,
"c1": 1,
"c2": 2,
"c3": 3,
"c4": 4,
"c5": 5
}
]
}

View File

@@ -0,0 +1,3 @@
pk|c1|c2|c3|c4|c5
0|1|2|3|4|5
1|1|2|3|4|5

View File

@@ -0,0 +1,11 @@
DROP TABLE IF EXISTS `test_int`;
CREATE TABLE `test_int` (
`pk` bigint NOT NULL,
`c1` bigint,
`c2` bigint,
`c3` bigint,
`c4` bigint,
`c5` bigint,
PRIMARY KEY (`pk`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `test_int` (`pk`,`c1`,`c2`,`c3`,`c4`,`c5`) VALUES (0,1,2,3,4,5);

View File

@@ -0,0 +1,5 @@
pk,c1,c2,c3,c4,c5
"0","1
1","2","3","4","5"
"1","1","2","3
3","4","5"
1 pk c1 c2 c3 c4 c5
2 0 1 1 2 3 4 5
3 1 1 2 3 3 4 5

View File

@@ -0,0 +1,3 @@
pk,c1,c2,c3,c4,c5,c6
"0","foo","bar","baz","car","dog","tim"
"1","1","2","3","4","5","6"
1 pk c1 c2 c3 c4 c5 c6
2 0 foo bar baz car dog tim
3 1 1 2 3 4 5 6

View File

@@ -0,0 +1,4 @@
pk, int, string, boolean, float, uint, uuid
0, 0, "asdf", TRUE, 0.0, 0, "00000000-0000-0000-0000-000000000000"
1, -1, "qwerty", FALSE, -1.0, 1, "00000000-0000-0000-0000-000000000001"
2, 1, "", TRUE, 0.0, 0, "123e4567-e89b-12d3-a456-426655440000"
1 pk int string boolean float uint uuid
2 0 0 asdf TRUE 0.0 0 00000000-0000-0000-0000-000000000000
3 1 -1 qwerty FALSE -1.0 1 00000000-0000-0000-0000-000000000001
4 2 1 TRUE 0.0 0 123e4567-e89b-12d3-a456-426655440000

View File

@@ -0,0 +1,5 @@
pk1,pk2,c1,c2,c3,c4,c5
0,0,1,2,3,4,5
0,1,1,2,3,4,5
1,0,1,2,3,4,5
1,1,1,2,3,4,5
1 pk1 pk2 c1 c2 c3 c4 c5
2 0 0 1 2 3 4 5
3 0 1 1 2 3 4 5
4 1 0 1 2 3 4 5
5 1 1 1 2 3 4 5

View File

@@ -0,0 +1,2 @@
pk,c1
0,<EFBFBD>
1 pk c1
2 0

View File

View File

@@ -0,0 +1,2 @@
this,is,bad
real,bad,

View File

View File

@@ -0,0 +1,2 @@
lowercase, UPPERCASE, Mixed, UNDER_SCORES, D-a-s-h-e-s
test, test, test, test, test
1 lowercase UPPERCASE Mixed UNDER_SCORES D-a-s-h-e-s
2 test test test test test

View File

@@ -0,0 +1,60 @@
load helper/windows-compat
if [ -z "$BATS_TMPDIR" ]; then
export BATS_TMPDIR=$HOME/batstmp/
mkdir $BATS_TMPDIR
fi
nativebatsdir() { echo `nativepath $BATS_TEST_DIRNAME/$1`; }
batshelper() { echo `nativebatsdir helper/$1`; }
stash_current_dolt_user() {
export STASHED_DOLT_USER_NAME=`dolt config --global --get user.name`
export STASHED_DOLT_USER_EMAIL=`dolt config --global --get user.email`
}
restore_stashed_dolt_user() {
dolt config --global --add user.name "$STASHED_DOLT_USER_NAME"
dolt config --global --add user.email "$STASHED_DOLT_USER_EMAIL"
unset STASHED_DOLT_USER_NAME STASHED_DOLT_USER_EMAIL
}
set_dolt_user() {
dolt config --global --add user.name "$1" > /dev/null 2>&1
dolt config --global --add user.email "$2" > /dev/null 2>&1
}
current_dolt_user_name() {
dolt config --global --get user.name
}
current_dolt_user_email() {
dolt config --global --get user.email
}
setup_no_dolt_init() {
export PATH=$PATH:~/go/bin
cd $BATS_TMPDIR
# Append the directory name with the pid of the calling process so
# multiple tests can be run in parallel on the same machine
mkdir "dolt-repo-$$"
cd "dolt-repo-$$"
}
assert_feature_version() {
run dolt version --feature
[[ "$output" =~ "feature version: 0" ]] || exit 1
}
setup_common() {
setup_no_dolt_init
dolt init
}
teardown_common() {
rm -rf "$BATS_TMPDIR/dolt-repo-$$"
}
nativevar DOLT_ROOT_PATH $BATS_TMPDIR/config-$$ /p
dolt config --global --add metrics.disabled true > /dev/null 2>&1
set_dolt_user "Bats Tests" "bats@email.fake"

View File

@@ -0,0 +1,3 @@
CREATE TABLE employees (
And then I said, supposing you brought the light inside of the body... Sounds interesting.
);

View File

@@ -0,0 +1,9 @@
CREATE TABLE employees (
`id` LONGTEXT NOT NULL,
`first name` LONGTEXT,
`last name` LONGTEXT,
`title` LONGTEXT,
`start date` LONGTEXT,
`end date` LONGTEXT,
PRIMARY KEY (`id`)
);

View File

@@ -0,0 +1,30 @@
{
"rows": [
{
"id": 0,
"first name": "tim",
"last name": "sehn",
"title": "ceo",
"start date": "",
"end date": ""
bad
},
{
"id": 1,
"first name": "aaron",
"last name": "son",
"title": "founder",
"start date": "",
"end date": ""
},
{
"id": 2,
"first name": "brian",
"last name": "hendricks",
"title": "founder",
"start date": "",
"end date": ""
}
}
]
}

View File

@@ -0,0 +1,36 @@
{
"rows": [
{
"id": 0,
"first name": "tim",
"last name": "sehn",
"title": "ceo",
"start date": "",
"end date": ""
},
{
"id": 1,
"first name": "aaron",
"last name": "son",
"title": "founder",
"start date": "",
"end date": ""
},
{
"id": 2,
"first name": "brian",
"last name": "hendricks",
"title": "founder",
"start date": "",
"end date": ""
},
{
"id": 3,
"first name": "matt",
"last name": "jesuele",
"title": "software engineer",
"start date": "",
"end date": ""
}
]
}

View File

@@ -0,0 +1,4 @@
id, title, start date, end date, first name, last name
0, "ceo", "", "", "tim", "sehn"
1, "founder", "", "", "aaron", "son"
2, "founder", "", "", "brian", "hendriks"
1 id title start date end date first name last name
2 0 ceo tim sehn
3 1 founder aaron son
4 2 founder brian hendriks

View File

@@ -0,0 +1,28 @@
{
"rows": [
{
"id": 0,
"title": "ceo",
"start date": "",
"end date": "",
"first name": "tim",
"last name": "sehn"
},
{
"id": 1,
"title": "founder",
"start date": "",
"end date": "",
"first name": "aaron",
"last name": "son"
},
{
"id": 2,
"title": "founder",
"start date": "",
"end date": "",
"first name": "brian",
"last name": "hendricks"
}
]
}

View File

@@ -0,0 +1,3 @@
id, first name, last name, position
0, "tim", "sehn", "ceo"
1, "aaron", "son", "founder"
1 id first name last name position
2 0 tim sehn ceo
3 1 aaron son founder

View File

@@ -0,0 +1,28 @@
{
"rows": [
{
"id": "0",
"first name": "tim",
"last name": "sehn",
"position": "ceo"
},
{
"id": "1",
"first name": "aaron",
"last name": "son",
"position": "founder"
},
{
"id": "2",
"first name": "brian",
"last name": "hendricks",
"position": "founder"
},
{
"id": "3",
"first name": "matt",
"last name": "jesuele",
"position": "software engineer"
}
]
}

View File

@@ -0,0 +1,28 @@
{
"rows": [
{
"id": 0,
"first name": "tim",
"last name": "sehn",
"title": "ceo",
"start date": "",
"end date": ""
},
{
"id": 1,
"first name": "aaron",
"last name": "son",
"title": "founder",
"start date": "",
"end date": ""
},
{
"id": 2,
"first name": "brian",
"last name": "hendricks",
"title": "founder",
"start date": "",
"end date": ""
}
]
}

Binary file not shown.

View File

@@ -0,0 +1,39 @@
{
"rows": [
{
"pk": "a",
"headerOne": "\"\"",
"headerTwo": 1
},
{
"pk": "b",
"headerOne": "",
"headerTwo": 2
},
{
"pk": "c",
"headerOne": null,
"headerTwo": 3
},
{
"pk": "d",
"headerOne": "row four",
"headerTwo": null
},
{
"pk": "e",
"headerOne": "row five",
"headerTwo": null
},
{
"pk": "f",
"headerOne": "row six",
"headerTwo": 6
},
{
"pk": "g",
"headerOne": null,
"headerTwo": null
}
]
}

View File

@@ -0,0 +1,6 @@
pk1, v1, v2
1, 99, 51
2, 11, 55
3, 88, 52
4, 22, 54
5, 77, 53
1 pk1 v1 v2
2 1 99 51
3 2 11 55
4 3 88 52
5 4 22 54
6 5 77 53

View File

@@ -0,0 +1,7 @@
pk1, v1, v2
1, 99, 51
2, 11, 55
3, 88, 52
4, 22, 54
5, 77, 53
6, 11, 55
1 pk1 v1 v2
2 1 99 51
3 2 11 55
4 3 88 52
5 4 22 54
6 5 77 53
7 6 11 55

View File

@@ -0,0 +1 @@
O5P55nw4uSrbFKBPciCtihlIDlMPjKVqEb0HTuw8e0HcUTtolU2HZZbrlmdQjgAID9Y3_D7dCGYYw4Bw==","kty":"OKP","crv":"Ed25519"}

View File

@@ -0,0 +1 @@
{"d":"7sPHtB3FE7aJVNh2WW65ZnUI4ACA_WN_w-3QhmGMOAc=","x":"jmWVlqO5P55nw4uSrbFKBPciCtihlIDlMPjKVqEb0HTuw8e0HcUTtolU2HZZbrlmdQjgAID9Y3_D7dCGYYw4Bw==","kty":"OKP","crv":"Ed25519"}

View File

@@ -0,0 +1 @@
{"d":"7sPHtB3FE7aJVNh2WW65ZnUI4ACA_WN_w-3QhmGMOAc=","x":"jmWVlqO5P55nw4uSrbFKBPciCtihlIDlMPjKVqEb0HTuw8e0HcUTtolU2HZZbrlmdQjgAID9Y3_D7dCGYY

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
4:__LD_1__:ma67ier4cau1ai1jhk2fom2m3bggmfa3:iht2tkfo9cbbnrfmla9ks4gahc0snq4o:63c0dojobm5j7arp99hiq78hj1rtp7m5:2:ro000svvgga0k7hatg7fta9j8ismtc3b:1:chghnlvugtiui6khfo29cpfnfr3166qc:1:d0b8ibrrjvvv3f0mtd7hathtjq2vhig9:1:oktjimrpqi8m9dbpt3c7ikoaolhgtr2n:6:oik6v50p7q6as4t7qg7f1i06iomt9vn9:2:4bujnjuatdli0klda7ucot0tl836jujt:1:qe0mct6rf8puhdnqecm185p63dacaqrt:4:erturgf7to0f6r8prlbllflbshg5li4n:1:u9c6ttq6ddrgqdfbod9pg2vv79ab6crt:2:aum9p7826iqaeq0pjtqlcn56hoj5nhht:2

View File

@@ -0,0 +1,8 @@
{
"head": "refs/heads/master",
"staged": "s0o665ofbugmrfechrp7vq1390oefojf",
"working": "s0o665ofbugmrfechrp7vq1390oefojf",
"merge": null,
"remotes": {},
"branches": {}
}

View File

@@ -0,0 +1,103 @@
import csv
import sys
import time
import mysql.connector
from io import StringIO
from multiprocessing import Process
def _connect(user, host, port, database):
return mysql.connector.connect(user=user, host=host, port=port, database=database, allow_local_infile=True)
def _print_err_and_exit(e):
print(e, file=sys.stderr)
sys.exit(1)
def csv_to_row_maps(csv_str):
csv_str = csv_str.replace('\\n', '\n')
rd = csv.DictReader(StringIO(csv_str))
rows = []
for row in rd:
rows.append(row)
return rows
class DoltConnection(object):
def __init__(self, user='root', host='127.0.0.1', port=3306, database='dolt', auto_commit=False):
self.user = user
self.host = host
self.port = port
self.database = database
self.auto_commit = auto_commit
self.cnx = None
def connect(self):
try:
self.cnx = _connect(self.user, self.host, self.port, self.database)
self.cnx.autocommit=self.auto_commit
except BaseException as e:
_print_err_and_exit(e)
def close(self):
self.cnx.close()
def query(self, query_str, exit_on_err=True):
try:
cursor = self.cnx.cursor()
cursor.execute(query_str)
if cursor.description is None:
return [], cursor.rowcount
raw = cursor.fetchall()
row_maps = []
for curr in raw:
r = {}
for i, k in enumerate(cursor.column_names):
r[k] = str(curr[i])
row_maps.append(r)
return row_maps, cursor.rowcount
except BaseException as e:
if exit_on_err:
_print_err_and_exit(e)
raise e
class InfiniteRetryConnection(DoltConnection):
def connect(self):
while True:
try:
self.cnx = _connect(user=self.user, host=self.host, port=self.port, database=self.database)
try:
self.cnx.close()
except BaseException:
pass
return
except BaseException:
pass
def wait_for_connection(user='root', host='127.0.0.1', port=3306, database='dolt', timeout_ms=5000):
timeoutf = timeout_ms / 1000.0
exit_zero_on_connect = InfiniteRetryConnection(user=user, host=host, port=port, database=database)
cnx_proc = Process(target=exit_zero_on_connect.connect)
cnx_proc.start()
cnx_proc.join(timeout=timeoutf)
if cnx_proc.exitcode is None:
cnx_proc.terminate()
_print_err_and_exit(Exception("Failed to establish connection in time."))
elif cnx_proc.exitcode != 0:
_print_err_and_exit(Exception("Connection process exited with exit code %d." % cnx_proc.exitcode))

View File

@@ -0,0 +1,2 @@
INSERT INTO test (pk, int, string, boolean, float, uint, uuid)
VALUES (3, 3, "three", TRUE, 3.3, 3, "00000000-0000-0000-0000-000000000003");

View File

@@ -0,0 +1,10 @@
CREATE TABLE `newtable`(
`pk` BIGINT NOT NULL,
`int` BIGINT,
`string` LONGTEXT,
`boolean` BOOLEAN,
`float` DOUBLE,
`uint` BIGINT UNSIGNED,
`uuid` LONGTEXT,
PRIMARY KEY (`pk`)
);

View File

@@ -0,0 +1 @@
DELETE FROM test WHERE pk=1;

View File

@@ -0,0 +1 @@
UPDATE test SET int=-1, boolean=FALSE, uint=2 WHERE pk=2;

View File

@@ -0,0 +1 @@
INSERT INTO test (pk1, pk2, c1, c2, c3, c4, c5) VALUES (2, 2, 1, 2, 3, 4, 5);

View File

@@ -0,0 +1 @@
UPDATE test SET pk1=3, pk2=3 WHERE pk1=1 AND pk2=1;

View File

@@ -0,0 +1,10 @@
CREATE TABLE `newtable`(
`pk1` BIGINT NOT NULL COMMENT 'tag:10',
`pk2` BIGINT NOT NULL COMMENT 'tag:11',
`c1` BIGINT COMMENT 'tag:12',
`c2` BIGINT COMMENT 'tag:13',
`c3` BIGINT COMMENT 'tag:14',
`c4` BIGINT COMMENT 'tag:15',
`c5` BIGINT COMMENT 'tag:16',
PRIMARY KEY (`pk1`, `pk2`)
);

View File

@@ -0,0 +1 @@
DELETE FROM test WHERE pk1=1 AND pk2=0 ;

View File

@@ -0,0 +1 @@
UPDATE test SET pk1=3 WHERE pk1=0 AND pk2=1;

View File

@@ -0,0 +1 @@
UPDATE test SET c1=9, c3=9, c5=9 WHERE pk1=1 AND pk2=1;

View File

@@ -0,0 +1,163 @@
SERVER_REQS_INSTALLED="FALSE"
SERVER_PID=""
DEFAULT_DB=""
PYTHON_QUERY_SCRIPT="
import os
import sys
args = sys.argv[sys.argv.index('--') + 1:]
query_results = None
if len(args) == 6:
working_dir, database, port_str, auto_commit, query_strs, query_results = args
else:
working_dir, database, port_str, auto_commit, query_strs = args
print('Query Strings: ' + query_strs)
print('Workind Dir: ' + working_dir)
print('Database: ' + database)
print('Port: ' + port_str)
print('Autocommit: ' + auto_commit)
print('Expected Results: ' + str(query_results))
os.chdir(working_dir)
if auto_commit == '1':
auto_commit = True
else:
auto_commit = False
from pytest import DoltConnection, csv_to_row_maps
dc = DoltConnection(port=int(port_str), database=database, user='dolt', auto_commit=auto_commit)
dc.connect()
queries = query_strs.split(';')
expected = [None]*len(queries)
if query_results is not None:
expected = query_results.split(';')
if len(expected) < len(queries):
expected.extend(['']*(len(queries)-len(expected)))
for i in range(len(queries)):
query_str = queries[i].strip()
print('executing:', query_str)
actual_rows, num_rows = dc.query(query_str)
if expected[i] is not None:
expected_rows = csv_to_row_maps(expected[i])
print('expected:', expected_rows, '\n actual:', actual_rows)
if expected_rows != actual_rows:
print('expected:', expected_rows, '\n actual:', actual_rows)
sys.exit(1)
"
set_server_reqs_installed() {
SERVER_REQS_INSTALLED=$(python3 -c "
requirements_installed = True
try:
import mysql.connector
except:
requirements_installed = False
print(str(requirements_installed).upper())
")
}
wait_for_connection() {
PYTEST_DIR="$BATS_TEST_DIRNAME/helper"
python3 -c "
import os
import sys
args = sys.argv[sys.argv.index('--') + 1:]
working_dir, database, port_str, timeout_ms = args
os.chdir(working_dir)
from pytest import wait_for_connection
wait_for_connection(port=int(port_str), timeout_ms=int(timeout_ms), database=database, user='dolt')
" -- "$PYTEST_DIR" "$DEFAULT_DB" "$1" "$2"
}
start_sql_server() {
DEFAULT_DB="$1"
let PORT="$$ % (65536-1024) + 1024"
dolt sql-server --host 0.0.0.0 --port=$PORT --user dolt &
SERVER_PID=$!
wait_for_connection $PORT 5000
}
start_sql_multi_user_server() {
DEFAULT_DB="$1"
let PORT="$$ % (65536-1024) + 1024"
echo "
log_level: debug
user:
name: dolt
listener:
host: 0.0.0.0
port: $PORT
max_connections: 10
behavior:
autocommit: false
" > .cliconfig.yaml
dolt sql-server --config .cliconfig.yaml &
SERVER_PID=$!
wait_for_connection $PORT 5000
}
start_multi_db_server() {
DEFAULT_DB="$1"
let PORT="$$ % (65536-1024) + 1024"
dolt sql-server --host 0.0.0.0 --port=$PORT --user dolt --multi-db-dir ./ &
SERVER_PID=$!
wait_for_connection $PORT 5000
}
stop_sql_server() {
kill $SERVER_PID
}
# server_query connects to a running mysql server, executes a query and compares the results against what is expected.
# In the event that the results do not match expectations, the python process will exit with an exit code of 1
# * param1 is 1 for autocommit = true, 0 for autocommit = false
# * param2 is the query_str
# * param3 is a csv representing the expected result set. If a query is not expected to have a result set "" should
# be passed.
server_query() {
let PORT="$$ % (65536-1024) + 1024"
PYTEST_DIR="$BATS_TEST_DIRNAME/helper"
echo Executing server_query
python3 -c "$PYTHON_QUERY_SCRIPT" -- "$PYTEST_DIR" "$DEFAULT_DB" "$PORT" "$1" "$2" "$3"
}
# server_query connects to a running mysql server, executes a query and compares the results against what is expected.
# In the event that the results do not match expectations, the python process will exit with an exit code of 1
# * param1 is 1 for autocommit = true, 0 for autocommit = false
# * param2 is the query_str
multi_query() {
let PORT="$$ % (65536-1024) + 1024"
PYTEST_DIR="$BATS_TEST_DIRNAME/helper"
echo Executing multi_query
python3 -c "$PYTHON_QUERY_SCRIPT" -- "$PYTEST_DIR" "$DEFAULT_DB" "$PORT" "$1" "$2"
}
# update_query runs an update query and should be called with 2 parameters
# * param1 is 1 for autocommit = true, 0 for autocommit = false
# * param2 is the query string
update_query() {
server_query $1 "$2" ""
}
# insert_query runs an insert query and should be called with 2 parameters
# * param1 is 1 for autocommit = true, 0 for autocommit = false
# * param2 is the query string
insert_query() {
server_query $1 "$2" ""
}

Some files were not shown because too many files have changed in this diff Show More