Skip to content

Commit

Permalink
Merge pull request #239 from liquidata-inc/aaron/create-view-bats-tests
Browse files Browse the repository at this point in the history
bats/create-views.bats: Pick up go-mysql-server support for views.
  • Loading branch information
Aaron Son authored Dec 9, 2019
2 parents 6b5d177 + 3dc7464 commit b74939c
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
110 changes: 110 additions & 0 deletions bats/create-views.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash

setup() {
setup_common
}

teardown() {
teardown_common
}

@test "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 "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 "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 "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 "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 "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 "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 "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 "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 ]
}
2 changes: 1 addition & 1 deletion go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (

replace github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi => ./gen/proto/dolt/services/eventsapi

replace github.com/src-d/go-mysql-server => github.com/liquidata-inc/go-mysql-server v0.4.1-0.20191204003907-576e8690465b
replace github.com/src-d/go-mysql-server => github.com/liquidata-inc/go-mysql-server v0.5.1-0.20191209191907-fc599b342cf8

replace vitess.io/vitess => github.com/liquidata-inc/vitess v0.0.0-20191125220844-c7181e70ee98

Expand Down
15 changes: 13 additions & 2 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpH
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/araddon/dateparse v0.0.0-20190622164848-0fb0a474d195 h1:c4mLfegoDw6OhSJXTd2jUEQgZUQuJWtocudb97Qn9EM=
github.com/araddon/dateparse v0.0.0-20190622164848-0fb0a474d195/go.mod h1:SLqhdZcd+dF3TEVL2RMoob5bBP5R1P1qkox+HtCBgGI=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
Expand Down Expand Up @@ -199,12 +201,19 @@ github.com/klauspost/crc32 v1.2.0/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3H
github.com/klauspost/pgzip v1.2.0/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/liquidata-inc/go-mysql-server v0.4.1-0.20191204003907-576e8690465b h1:LaTfDUa9JSuS4sHaDqfHgwFitInog3+wYlWOViNrfyw=
github.com/liquidata-inc/go-mysql-server v0.4.1-0.20191204003907-576e8690465b/go.mod h1:hzni/QFitaMZ9H7hbZ3K+C4BEl75iDKqTIY+Hbvj6VQ=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20191209191907-fc599b342cf8 h1:A+yJuYxjdl9/ptn1+q/Oedf4uLi9vryzXiEjyojDS6A=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20191209191907-fc599b342cf8/go.mod h1:iARqujLmSiUBBGmGgsAdmRymFm38D+5bIbrOqYjUIi0=
github.com/liquidata-inc/ishell v0.0.0-20190514193646-693241f1f2a0 h1:phMgajKClMUiIr+hF2LGt8KRuUa2Vd2GI1sNgHgSXoU=
github.com/liquidata-inc/ishell v0.0.0-20190514193646-693241f1f2a0/go.mod h1:YC1rI9k5gx8D02ljlbxDfZe80s/iq8bGvaaQsvR+qxs=
github.com/liquidata-inc/mmap-go v1.0.3 h1:2LndAeAtup9rpvUmu4wZSYCsjCQ0Zpc+NqE+6+PnT7g=
Expand Down Expand Up @@ -462,6 +471,8 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
gopkg.in/asn1-ber.v1 v1.0.0-20150924051756-4e86f4367175/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.41.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ldap.v2 v2.5.0/go.mod h1:oI0cpe/D7HRtBQl8aTg+ZmzFUAvu4lsv3eLXMLGFxWk=
gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4=
Expand Down

0 comments on commit b74939c

Please sign in to comment.