38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package mysql
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.warky.dev/wdevs/relspecgo/pkg/models"
|
|
"git.warky.dev/wdevs/relspecgo/pkg/readers"
|
|
)
|
|
|
|
func TestReaderMapDataType(t *testing.T) {
|
|
r := NewReader(&readers.ReaderOptions{})
|
|
for _, tc := range []struct{ input, want string }{{"varchar(64)", "string"}, {"bigint unsigned", "uint64"}, {"datetime", "timestamp"}, {"json", "json"}} {
|
|
if got := r.mapDataType(tc.input); got != tc.want {
|
|
t.Errorf("mapDataType(%q) = %q, want %q", tc.input, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestReaderRequiresConnectionString(t *testing.T) {
|
|
if _, err := NewReader(&readers.ReaderOptions{}).ReadDatabase(); err == nil {
|
|
t.Fatal("expected missing connection string error")
|
|
}
|
|
}
|
|
|
|
func TestRelationshipNamesCannotCollapseDistinctForeignKeys(t *testing.T) {
|
|
table := models.InitTable("t", "app")
|
|
reader := NewReader(&readers.ReaderOptions{})
|
|
for _, c := range []*models.Constraint{
|
|
{Name: "a_to_b", ReferencedTable: "c"},
|
|
{Name: "a", ReferencedTable: "b_to_c"},
|
|
} {
|
|
reader.deriveRelationship(table, c)
|
|
}
|
|
if len(table.Relationships) != 2 {
|
|
t.Fatalf("distinct foreign keys collapsed: %+v", table.Relationships)
|
|
}
|
|
}
|