Skip to content

Commit

Permalink
test(spanddl): possibility to specify expected error for ddl statement
Browse files Browse the repository at this point in the history
If an error occurred, an assertion on database schema is not needed.
  • Loading branch information
thall committed Jan 8, 2024
1 parent 4ef0077 commit 5890740
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions spanddl/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func TestDatabase_ApplyDDL(t *testing.T) {
name string
ddls []string
expected *Database
errorDdlIndex int
errorContains string
}{
{
Expand Down Expand Up @@ -45,6 +46,23 @@ func TestDatabase_ApplyDDL(t *testing.T) {
},
},

{
name: "drop missing table",
ddls: []string{
`CREATE TABLE Singers (
SingerId INT64 NOT NULL,
FirstName STRING(1024),
LastName STRING(1024),
SingerInfo BYTES(MAX),
BirthDate DATE,
) PRIMARY KEY(SingerId);`,

`DROP TABLE Albums`,
},
errorDdlIndex: 1,
errorContains: "DROP TABLE: table Albums does not exist",
},

{
name: "create table with row deletion policy",
ddls: []string{
Expand Down Expand Up @@ -356,13 +374,13 @@ func TestDatabase_ApplyDDL(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var db Database
for _, ddl := range tt.ddls {
for i, ddl := range tt.ddls {
ddl, err := spansql.ParseDDL(tt.name, ddl)
assert.NilError(t, err)
err = db.ApplyDDL(ddl)
if tt.errorContains != "" {
if tt.errorDdlIndex == i && tt.errorContains != "" {
assert.ErrorContains(t, err, tt.errorContains)
break
return
}
assert.NilError(t, err)
}
Expand Down

0 comments on commit 5890740

Please sign in to comment.