28 lines
709 B
Go
28 lines
709 B
Go
package dbutil
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
func TestQuoteMySQLIdentifier(t *testing.T) {
|
|
got := QuoteMySQLIdentifier("git`ocean")
|
|
if got != "`git``ocean`" {
|
|
t.Fatalf("unexpected quote: %q", got)
|
|
}
|
|
}
|
|
|
|
func TestIsDuplicateColumnError(t *testing.T) {
|
|
if !IsDuplicateColumnError(&mysql.MySQLError{Number: 1060, Message: "Duplicate column name"}) {
|
|
t.Fatal("expected duplicate column mysql error")
|
|
}
|
|
if IsDuplicateColumnError(&mysql.MySQLError{Number: 1049, Message: "Unknown database"}) {
|
|
t.Fatal("did not expect unknown database to be duplicate column")
|
|
}
|
|
if IsDuplicateColumnError(errors.New("not mysql")) {
|
|
t.Fatal("did not expect ordinary error")
|
|
}
|
|
}
|