Added bats test for csv and json SQL output formats

Signed-off-by: Zach Musgrave <zach@liquidata.co>
This commit is contained in:
Zach Musgrave
2020-04-10 16:31:51 -07:00
parent 975f48f225
commit 68d3df0094

View File

@@ -160,6 +160,38 @@ teardown() {
[[ "$output" =~ "not found" ]] || false
}
@test "sql output formats" {
dolt sql <<SQL
CREATE TABLE test (
a int primary key,
b float,
c varchar(80),
d datetime
);
SQL
dolt sql <<SQL
insert into test values (1, 1.5, "1", "2020-01-01");
insert into test values (2, 2.5, "2", "2020-02-02");
insert into test values (3, NULL, "3", "2020-03-03");
insert into test values (4, 4.5, NULL, "2020-04-04");
insert into test values (5, 5.5, "5", NULL);
SQL
run dolt sql -r csv -q "select * from test order by a"
[ $status -eq 0 ]
[[ "$output" =~ "a,b,c,d" ]] || false
[[ "$output" =~ '1,1.5,1,2020-01-01 00:00:00 +0000 UTC' ]] || false
[[ "$output" =~ '2,2.5,2,2020-02-02 00:00:00 +0000 UTC' ]] || false
[[ "$output" =~ '3,,3,2020-03-03 00:00:00 +0000 UTC' ]] || false
[[ "$output" =~ '4,4.5,,2020-04-04 00:00:00 +0000 UTC' ]] || false
[[ "$output" =~ '5,5.5,5,' ]] || false
[ "${#lines[@]}" -eq 6 ]
run dolt sql -r json -q "select * from test order by a"
[ $status -eq 0 ]
[ "$output" == '{"rows": [{"a":1,"b":1.5,"c":"1","d":{}},{"a":2,"b":2.5,"c":"2","d":{}},{"a":3,"c":"3","d":{}},{"a":4,"b":4.5,"d":{}},{"a":5,"b":5.5,"c":"5"}]}' ]
}
@test "sql ambiguous column name" {
run dolt sql -q "select pk,pk1,pk2 from one_pk,two_pk where c1=0"
[ "$status" -eq 1 ]
@@ -593,4 +625,4 @@ SQL
skip run dolt sql -q "INSERT INTO test (col_a,col_b,col_c) VALUES ('a','','b') ON DUPLICATE KEY UPDATE col_a = col_a, col_b = col_b, col_c = VALUES(col_c);"
[ $status -eq 0 ]
[[ ! "$output" =~ 'unsupported feature' ]] || false
}
}