Skip to content

Commit 6a2ee9f

Browse files
committed
Add bats tests for diffing enum columns
1 parent c2bb78c commit 6a2ee9f

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

integration-tests/bats/diff.bats

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,3 +1966,125 @@ SQL
19661966
[[ "$output" =~ "t1" ]] || false
19671967
[[ "$output" =~ "t2" ]] || false
19681968
}
1969+
1970+
1971+
@test "diff: enum data change" {
1972+
dolt sql <<SQL
1973+
drop table test;
1974+
create table test (pk int primary key, size ENUM('x-small', 'small', 'medium', 'large', 'x-large'));
1975+
insert into test values (1,'x-small');
1976+
insert into test values (2,'small');
1977+
insert into test values (3,'medium');
1978+
SQL
1979+
dolt add .
1980+
dolt commit -am "First commit"
1981+
1982+
dolt sql <<SQL
1983+
insert into test values (4,'large');
1984+
delete from test where pk = 1;
1985+
update test set size = 'x-large' where pk = 2;
1986+
SQL
1987+
1988+
run dolt diff
1989+
1990+
EXPECTED=$(cat <<'EOF'
1991+
+---+----+---------+
1992+
| | pk | size |
1993+
+---+----+---------+
1994+
| - | 1 | x-small |
1995+
| < | 2 | small |
1996+
| > | 2 | x-large |
1997+
| + | 4 | large |
1998+
+---+----+---------+
1999+
EOF
2000+
)
2001+
2002+
[ "$status" -eq 0 ]
2003+
[[ "$output" =~ "$EXPECTED" ]] || false
2004+
2005+
run dolt diff --data --schema
2006+
[ "$status" -eq 0 ]
2007+
[[ "$output" =~ "$EXPECTED" ]] || false
2008+
2009+
run dolt diff --data
2010+
[[ "$output" =~ "$EXPECTED" ]] || false
2011+
}
2012+
2013+
@test "diff: enum and schema changes" {
2014+
dolt sql <<SQL
2015+
drop table test;
2016+
create table test (pk int primary key, size ENUM('x-small', 'small', 'medium', 'large', 'x-large'));
2017+
insert into test values (1,'x-small');
2018+
insert into test values (2,'small');
2019+
insert into test values (3,'medium');
2020+
SQL
2021+
dolt add .
2022+
dolt commit -am "First commit"
2023+
2024+
dolt sql <<SQL
2025+
alter table test add column c1 int;
2026+
insert into test values (4,'large',1);
2027+
delete from test where pk = 1;
2028+
update test set size = 'x-large' where pk = 2;
2029+
SQL
2030+
2031+
run dolt diff
2032+
2033+
EXPECTED=$(cat <<'EOF'
2034+
CREATE TABLE `test` (
2035+
`pk` int NOT NULL,
2036+
`size` enum('x-small','small','medium','large','x-large'),
2037+
+ `c1` int,
2038+
PRIMARY KEY (`pk`)
2039+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;
2040+
+---+----+---------+------+
2041+
| | pk | size | c1 |
2042+
+---+----+---------+------+
2043+
| - | 1 | x-small | NULL |
2044+
| < | 2 | small | NULL |
2045+
| > | 2 | x-large | NULL |
2046+
| + | 4 | large | 1 |
2047+
+---+----+---------+------+
2048+
EOF
2049+
)
2050+
2051+
[ "$status" -eq 0 ]
2052+
[[ "$output" =~ "$EXPECTED" ]] || false
2053+
2054+
run dolt diff --data --schema
2055+
[ "$status" -eq 0 ]
2056+
[[ "$output" =~ "$EXPECTED" ]] || false
2057+
2058+
run dolt diff --schema
2059+
2060+
EXPECTED=$(cat <<'EOF'
2061+
CREATE TABLE `test` (
2062+
`pk` int NOT NULL,
2063+
`size` enum('x-small','small','medium','large','x-large'),
2064+
+ `c1` int,
2065+
PRIMARY KEY (`pk`)
2066+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;
2067+
EOF
2068+
)
2069+
2070+
[[ "$output" =~ "$EXPECTED" ]] || false
2071+
# Count the line numbers to make sure there are no data changes output
2072+
[ "${#lines[@]}" -eq 9 ]
2073+
2074+
run dolt diff --data
2075+
EXPECTED=$(cat <<'EOF'
2076+
+---+----+---------+------+
2077+
| | pk | size | c1 |
2078+
+---+----+---------+------+
2079+
| - | 1 | x-small | NULL |
2080+
| < | 2 | small | NULL |
2081+
| > | 2 | x-large | NULL |
2082+
| + | 4 | large | 1 |
2083+
+---+----+---------+------+
2084+
EOF
2085+
)
2086+
2087+
[[ "$output" =~ "$EXPECTED" ]] || false
2088+
# Count the line numbers to make sure there are no schema changes output
2089+
[ "${#lines[@]}" -eq 11 ]
2090+
}

0 commit comments

Comments
 (0)