-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* (chore): Upgrade tidb_parser to new repository fixes: #1795 Refs: #1197 #1754 * test(MySQL): Add test for default column values Refs: #1197 #1754
- Loading branch information
1 parent
0ae16d2
commit e5ba388
Showing
6 changed files
with
133 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package dolphin | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/kyleconroy/sqlc/internal/sql/sqlerr" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestUpdateErrors(t *testing.T) { | ||
p := NewParser() | ||
for i, tc := range []struct { | ||
stmt string | ||
err *sqlerr.Error | ||
}{ | ||
{ | ||
` | ||
CREATE TABLE foo (bar int); | ||
CREATE TABLE foo (bar int); | ||
`, | ||
sqlerr.RelationExists("foo"), | ||
}, | ||
} { | ||
test := tc | ||
t.Run(strconv.Itoa(i), func(t *testing.T) { | ||
stmts, err := p.Parse(strings.NewReader(test.stmt)) | ||
if err != nil { | ||
t.Log(test.stmt) | ||
t.Fatal(err) | ||
} | ||
|
||
c := NewCatalog() | ||
err = c.Build(stmts) | ||
if err == nil { | ||
t.Log(test.stmt) | ||
t.Fatal("err was nil") | ||
} | ||
|
||
var actual *sqlerr.Error | ||
if !errors.As(err, &actual) { | ||
t.Fatalf("err is not *sqlerr.Error: %#v", err) | ||
} | ||
|
||
if diff := cmp.Diff(test.err.Error(), actual.Error()); diff != "" { | ||
t.Log(test.stmt) | ||
t.Errorf("error mismatch: \n%s", diff) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSuccessfulUpdate(t *testing.T) { | ||
p := NewParser() | ||
for i, tc := range []struct { | ||
stmt string | ||
}{ | ||
{ | ||
` | ||
CREATE TABLE authors ( | ||
id INT PRIMARY KEY, | ||
name text NOT NULL, | ||
bio text NOT NULL DEFAULT (bio_func()) | ||
); | ||
`, | ||
}, | ||
{ | ||
` | ||
CREATE TABLE IF NOT EXISTS organizations | ||
( | ||
id VARCHAR(36) DEFAULT (UUID()) NOT NULL PRIMARY KEY | ||
); | ||
`, | ||
}, | ||
} { | ||
test := tc | ||
t.Run(strconv.Itoa(i), func(t *testing.T) { | ||
stmts, err := p.Parse(strings.NewReader(test.stmt)) | ||
if err != nil { | ||
t.Log(test.stmt) | ||
t.Fatal(err) | ||
} | ||
|
||
c := NewCatalog() | ||
err = c.Build(stmts) | ||
if err != nil { | ||
t.Log(test.stmt) | ||
t.Log(err) | ||
t.Fatal("err should have been nil") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters