Skip to content

Commit

Permalink
test: Adjust driver tests to accept custom migration content
Browse files Browse the repository at this point in the history
Most DBs can use a set of default queries. But those queries aren't
valid for cassandra. Allow a driver to supply DB preparation queries.

Add test input validation

Make a copy of test inputs rather than mutate it in place (the invalid
sql test did this).
  • Loading branch information
rafaelespinoza committed May 12, 2021
1 parent 2affc38 commit 77a911e
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 134 deletions.
17 changes: 16 additions & 1 deletion drivers/cassandra/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,20 @@ import (
)

func Test(t *testing.T) {
test.RunDriverTests(t, cassandra.NewDriver())
queries := test.Queries{
CreateFoos: test.MigrationContent{
Forward: "CREATE TABLE foos (id int PRIMARY KEY);",
Reverse: "DROP TABLE foos;",
},
CreateBars: test.MigrationContent{
Forward: "CREATE TABLE bars (id int PRIMARY KEY);",
Reverse: "DROP TABLE bars;",
},
AlterFoos: test.MigrationContent{
Forward: "ALTER TABLE foos ADD a varchar;",
Reverse: "ALTER TABLE foos DROP a;",
},
}

test.RunDriverTests(t, cassandra.NewDriver(), queries)
}
2 changes: 1 addition & 1 deletion drivers/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
)

func Test(t *testing.T) {
test.RunDriverTests(t, mysql.NewDriver())
test.RunDriverTests(t, mysql.NewDriver(), test.DefaultQueries)
}
2 changes: 1 addition & 1 deletion drivers/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
)

func Test(t *testing.T) {
test.RunDriverTests(t, postgres.NewDriver())
test.RunDriverTests(t, postgres.NewDriver(), test.DefaultQueries)
}
2 changes: 1 addition & 1 deletion drivers/sqlite3/sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
)

func Test(t *testing.T) {
test.RunDriverTests(t, sqlite3.NewDriver())
test.RunDriverTests(t, sqlite3.NewDriver(), test.DefaultQueries)
}
2 changes: 1 addition & 1 deletion internal/stub/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
)

func Test(t *testing.T) {
test.RunDriverTests(t, &stub.Driver{})
test.RunDriverTests(t, &stub.Driver{}, test.DefaultQueries)
}
Loading

0 comments on commit 77a911e

Please sign in to comment.