Skip to content

Commit 4f1cfb6

Browse files
Merge pull request #429 from liquidata-inc/andy/back_compat
andy/Test compatibility between Dolt versions
2 parents 0cc0614 + 34b1960 commit 4f1cfb6

File tree

100 files changed

+512
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+512
-87
lines changed

bats/compatibility/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
env_test/

bats/compatibility/README.md

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

bats/compatibility/runner.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
function build_dolt() {
4+
pushd "$dolt_dir" > /dev/null || exit
5+
git checkout "$1" > /dev/null
6+
go install .
7+
popd > /dev/null || exit
8+
}
9+
10+
function setup_dir() {
11+
if [ -d "$1" ]; then rm -r "$1"; fi
12+
mkdir "$1"
13+
pushd "$1" > /dev/null || exit
14+
"$top_dir/setup_repo.sh" > setup_repo.log
15+
cp -r "$top_dir"/bats/* .
16+
popd > /dev/null || exit
17+
}
18+
19+
function run_bats_tests() {
20+
pushd "$1" > /dev/null || exit
21+
cwd=$(pwd)
22+
hash=$(git rev-parse HEAD)
23+
echo "testing dolt @ $hash against repo in $cwd"
24+
bats .
25+
echo
26+
popd > /dev/null || exit
27+
}
28+
29+
# ensure that we have a clean working change set before we begin
30+
if [[ $(git diff --stat) != '' ]]; then
31+
echo "cannot run compatibility tests with git working changes"
32+
exit
33+
fi
34+
35+
# copy all the test files to take them out of source control
36+
# when we checkout different Dolt releases we don't want to
37+
# delete our environment
38+
test_env="env_test"
39+
rm -r $test_env
40+
mkdir $test_env
41+
cp -r test_files/* $test_env
42+
pushd $test_env > /dev/null || exit
43+
44+
top_dir=$(pwd)
45+
starting_branch=$(git rev-parse --abbrev-ref HEAD)
46+
dolt_dir="../../../go/cmd/dolt/"
47+
48+
# setup a repository with dolt built
49+
# from the current branch
50+
build_dolt "$starting_branch"
51+
setup_dir "head"
52+
53+
while IFS= read -r ver
54+
do
55+
56+
build_dolt "$ver"
57+
setup_dir "$ver"
58+
59+
# run compatibility.bats to ensure dolt @ $ver can
60+
# read a repo created with dolt @ HEAD
61+
ver_hash=$(git rev-parse HEAD)
62+
echo "hash for dolt @ $ver: $ver_hash"
63+
run_bats_tests head
64+
65+
done < <(grep -v '^ *#' < dolt_versions.txt)
66+
67+
# now build dolt @ HEAD and make sure we can read
68+
# all of the legacy repositories we created
69+
build_dolt "$starting_branch"
70+
71+
while IFS= read -r ver
72+
do
73+
head_hash=$(git rev-parse HEAD)
74+
echo "hash for dolt @ head: $head_hash"
75+
run_bats_tests "$ver"
76+
77+
done < <(grep -v '^ *#' < dolt_versions.txt)
78+
79+
80+
popd > /dev/null || exit
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env bats
2+
load $BATS_TEST_DIRNAME/helper/common.bash
3+
4+
setup() {
5+
setup_common
6+
}
7+
8+
teardown() {
9+
teardown_common
10+
}
11+
clear
12+
@test "dolt version" {
13+
run dolt version
14+
[ "$status" -eq 0 ]
15+
regex='dolt version [0-9]+.[0-9]+.[0-9]+'
16+
[[ "$output" =~ $regex ]] || false
17+
}
18+
19+
@test "dolt status" {
20+
run dolt status
21+
[ "$status" -eq 0 ]
22+
[[ "$output" =~ "On branch master" ]] || false
23+
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
24+
}
25+
26+
@test "dolt ls" {
27+
run dolt ls
28+
[ "$status" -eq 0 ]
29+
[[ "${lines[0]}" =~ "Tables in working set:" ]] || false
30+
}
31+
32+
@test "dolt branch" {
33+
run dolt branch
34+
[ "$status" -eq 0 ]
35+
}
36+
37+
@test "dolt diff" {
38+
run dolt diff
39+
[ "$status" -eq 0 ]
40+
}
41+
42+
@test "dolt schema show on branch init" {
43+
run dolt checkout init
44+
[ "$status" -eq 0 ]
45+
46+
dolt schema show
47+
run dolt schema show abc
48+
[ "$status" -eq 0 ]
49+
[[ "${lines[0]}" =~ "abc @ working" ]] || false
50+
[[ "${lines[1]}" =~ "CREATE TABLE \`abc\` (" ]] || false
51+
[[ "${lines[2]}" =~ " \`pk\` BIGINT NOT NULL COMMENT 'tag:0'," ]] || false
52+
[[ "${lines[3]}" =~ " \`a\` LONGTEXT COMMENT 'tag:100'," ]] || false
53+
[[ "${lines[4]}" =~ " \`b\` DOUBLE COMMENT 'tag:101'," ]] || false
54+
[[ "${lines[5]}" =~ " \`w\` BIGINT COMMENT 'tag:102'," ]] || false
55+
[[ "${lines[6]}" =~ " \`x\` BIGINT COMMENT 'tag:103'," ]] || false
56+
[[ "${lines[7]}" =~ " PRIMARY KEY (\`pk\`)" ]] || false
57+
[[ "${lines[8]}" =~ ");" ]] || false
58+
}
59+
60+
@test "dolt sql 'select * from abc' on branch init" {
61+
# checkout we're on the right branch
62+
run dolt status
63+
[ "$status" -eq 0 ]
64+
[[ "$output" =~ "On branch init" ]] || false
65+
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
66+
67+
dolt sql -q 'select * from abc;'
68+
run dolt sql -q 'select * from abc;'
69+
[ "$status" -eq 0 ]
70+
71+
72+
[[ "${lines[1]}" =~ "| pk | a | b | w | x |" ]] || false
73+
[[ "${lines[2]}" =~ "+----+------+-----+---+---+" ]] || false
74+
[[ "${lines[3]}" =~ "| 0 | asdf | 1.1 | 0 | 0 |" ]] || false
75+
[[ "${lines[4]}" =~ "| 1 | asdf | 1.1 | 0 | 0 |" ]] || false
76+
[[ "${lines[5]}" =~ "| 2 | asdf | 1.1 | 0 | 0 |" ]] || false
77+
}
78+
79+
@test "dolt schema show on branch master" {
80+
run dolt checkout master
81+
[ "$status" -eq 0 ]
82+
83+
dolt schema show
84+
run dolt schema show abc
85+
[ "$status" -eq 0 ]
86+
[[ "${lines[0]}" =~ "abc @ working" ]] || false
87+
[[ "${lines[1]}" =~ "CREATE TABLE \`abc\` (" ]] || false
88+
[[ "${lines[2]}" =~ "\`pk\` BIGINT NOT NULL COMMENT 'tag:0'," ]] || false
89+
[[ "${lines[3]}" =~ "\`a\` LONGTEXT COMMENT 'tag:100'," ]] || false
90+
[[ "${lines[4]}" =~ "\`b\` DOUBLE COMMENT 'tag:101'," ]] || false
91+
[[ "${lines[5]}" =~ "\`x\` BIGINT COMMENT 'tag:103'," ]] || false
92+
[[ "${lines[6]}" =~ "\`y\` BIGINT COMMENT 'tag:104'," ]] || false
93+
[[ "${lines[7]}" =~ "PRIMARY KEY (\`pk\`)" ]] || false
94+
[[ "${lines[8]}" =~ ");" ]] || false
95+
}
96+
97+
98+
@test "dolt sql 'select * from abc' on branch master" {
99+
# checkout we're on the right branch
100+
run dolt status
101+
[ "$status" -eq 0 ]
102+
[[ "$output" =~ "On branch master" ]] || false
103+
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
104+
105+
dolt sql -q 'select * from abc;'
106+
run dolt sql -q 'select * from abc;'
107+
[ "$status" -eq 0 ]
108+
[[ "${lines[1]}" =~ "| pk | a | b | x | y |" ]] || false
109+
[[ "${lines[2]}" =~ "+----+------+-----+---+--------+" ]] || false
110+
[[ "${lines[3]}" =~ "| 0 | asdf | 1.1 | 0 | <NULL> |" ]] || false
111+
[[ "${lines[4]}" =~ "| 2 | asdf | 1.1 | 0 | <NULL> |" ]] || false
112+
[[ "${lines[5]}" =~ "| 3 | data | 1.1 | 0 | <NULL> |" ]] || false
113+
}
114+
115+
@test "dolt schema show on branch other" {
116+
run dolt checkout other
117+
[ "$status" -eq 0 ]
118+
119+
dolt schema show
120+
run dolt schema show abc
121+
[ "$status" -eq 0 ]
122+
[[ "${lines[0]}" =~ "abc @ working" ]] || false
123+
[[ "${lines[1]}" =~ "CREATE TABLE \`abc\` (" ]] || false
124+
[[ "${lines[2]}" =~ "\`pk\` BIGINT NOT NULL COMMENT 'tag:0'," ]] || false
125+
[[ "${lines[3]}" =~ "\`a\` LONGTEXT COMMENT 'tag:100'," ]] || false
126+
[[ "${lines[4]}" =~ "\`b\` DOUBLE COMMENT 'tag:101'," ]] || false
127+
[[ "${lines[5]}" =~ "\`w\` BIGINT COMMENT 'tag:102'," ]] || false
128+
[[ "${lines[6]}" =~ "\`z\` BIGINT COMMENT 'tag:105'," ]] || false
129+
[[ "${lines[7]}" =~ "PRIMARY KEY (\`pk\`)" ]] || false
130+
[[ "${lines[8]}" =~ ");" ]] || false
131+
}
132+
133+
@test "dolt sql 'select * from abc' on branch other" {
134+
# checkout we're on the right branch
135+
run dolt status
136+
[ "$status" -eq 0 ]
137+
[[ "$output" =~ "On branch other" ]] || false
138+
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
139+
140+
dolt sql -q 'select * from abc;'
141+
run dolt sql -q 'select * from abc;'
142+
[ "$status" -eq 0 ]
143+
[[ "${lines[1]}" =~ "| pk | a | b | w | z |" ]] || false
144+
[[ "${lines[2]}" =~ "+----+------+-----+---+--------+" ]] || false
145+
[[ "${lines[3]}" =~ "| 0 | asdf | 1.1 | 0 | <NULL> |" ]] || false
146+
[[ "${lines[4]}" =~ "| 1 | asdf | 1.1 | 0 | <NULL> |" ]] || false
147+
[[ "${lines[5]}" =~ "| 4 | data | 1.1 | 0 | <NULL> |" ]] || false
148+
149+
dolt checkout master
150+
}
151+
152+
@test "dolt table import" {
153+
run dolt table import -c -s abc_schema.json abc2 abc.csv
154+
[ "$status" -eq 0 ]
155+
[[ "$output" =~ "Import completed successfully." ]] || false
156+
157+
dolt sql -q 'drop table abc2'
158+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load helper/windows-compat
2+
3+
if [ -z "$BATS_TMPDIR" ]; then
4+
export BATS_TMPDIR=$HOME/batstmp/
5+
mkdir $BATS_TMPDIR
6+
fi
7+
8+
setup_common() {
9+
echo "setup" > /dev/null
10+
}
11+
12+
teardown_common() {
13+
echo "teardown" > /dev/null
14+
}
15+
16+
dolt config --global --add metrics.disabled true > /dev/null 2>&1
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
nativepath() { echo "$1"; }
2+
nativevar() { eval export "$1"="$2"; }
3+
skiponwindows() { :; }
4+
5+
IS_WINDOWS=false
6+
7+
if [ -d /mnt/c/Windows/System32 ]; then
8+
IS_WINDOWS=true
9+
if [ ! -d /mnt/c/batstmp ]; then
10+
mkdir /mnt/c/batstmp
11+
fi
12+
BATS_TMPDIR=`TMPDIR=/mnt/c/batstmp mktemp -d -t dolt-bats-tests-XXXXXX`
13+
export BATS_TMPDIR
14+
nativepath() {
15+
wslpath -w "$1"
16+
}
17+
nativevar() {
18+
eval export "$1"="$2"
19+
export WSLENV="$1$3"
20+
}
21+
skiponwindows() {
22+
skip "$1"
23+
}
24+
fi
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
v0.13.0
2+
v0.14.0
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
dolt init
4+
5+
dolt sql <<SQL
6+
CREATE TABLE abc (
7+
pk BIGINT NOT NULL COMMENT 'tag:0',
8+
a LONGTEXT COMMENT 'tag:100',
9+
b DOUBLE COMMENT 'tag:101',
10+
w BIGINT COMMENT 'tag:102',
11+
x BIGINT COMMENT 'tag:103',
12+
PRIMARY KEY (pk)
13+
);
14+
INSERT INTO abc VALUES (0, 'asdf', 1.1, 0, 0);
15+
INSERT INTO abc VALUES (1, 'asdf', 1.1, 0, 0);
16+
INSERT INTO abc VALUES (2, 'asdf', 1.1, 0, 0);
17+
SQL
18+
dolt add .
19+
dolt commit -m "initialized data"
20+
dolt branch init
21+
22+
23+
dolt branch other
24+
dolt sql <<SQL
25+
DELETE FROM abc WHERE pk=1;
26+
INSERT INTO abc VALUES (3, 'data', 1.1, 0, 0);
27+
ALTER TABLE abc DROP COLUMN w;
28+
ALTER TABLE abc ADD COLUMN y BIGINT COMMENT 'tag:104';
29+
SQL
30+
dolt add .
31+
dolt commit -m "made changes to master"
32+
33+
dolt checkout other
34+
dolt sql <<SQL
35+
DELETE FROM abc WHERE pk=2;
36+
INSERT INTO abc VALUES (4, 'data', 1.1, 0, 0);
37+
ALTER TABLE abc DROP COLUMN x;
38+
ALTER TABLE abc ADD COLUMN z BIGINT COMMENT 'tag:105';
39+
SQL
40+
dolt add .
41+
dolt commit -m "made changes to other"
42+
43+
dolt checkout master
44+
dolt table export abc abc.csv
45+
dolt schema export abc abc_schema.json
46+
47+
# add info to the log
48+
echo
49+
echo "dolt status"
50+
dolt status
51+
52+
echo
53+
echo "dolt branch"
54+
dolt branch
55+
56+
echo
57+
echo "dolt schema show"
58+
dolt schema show
59+
60+
echo
61+
echo "dolt sql -q 'select * from abc;'"
62+
dolt sql -q 'select * from abc;'

0 commit comments

Comments
 (0)