style: reformat test tables
This commit is contained in:
@@ -23,14 +23,22 @@ func TestCompareSchemaDetails(t *testing.T) {
|
|||||||
mutate func(*models.Schema)
|
mutate func(*models.Schema)
|
||||||
check func(*SchemaChange) bool
|
check func(*SchemaChange) bool
|
||||||
}{
|
}{
|
||||||
{"table added", func(s *models.Schema) { s.Tables = append(s.Tables, models.InitTable("u", "public")) },
|
{
|
||||||
func(c *SchemaChange) bool { return c.Tables != nil && len(c.Tables.Extra) == 1 }},
|
"table added", func(s *models.Schema) { s.Tables = append(s.Tables, models.InitTable("u", "public")) },
|
||||||
{"view added", func(s *models.Schema) { s.Views = []*models.View{models.InitView("v", "public")} },
|
func(c *SchemaChange) bool { return c.Tables != nil && len(c.Tables.Extra) == 1 },
|
||||||
func(c *SchemaChange) bool { return c.Views != nil && len(c.Views.Extra) == 1 }},
|
},
|
||||||
{"sequence added", func(s *models.Schema) { s.Sequences = []*models.Sequence{models.InitSequence("sq", "public")} },
|
{
|
||||||
func(c *SchemaChange) bool { return c.Sequences != nil && len(c.Sequences.Extra) == 1 }},
|
"view added", func(s *models.Schema) { s.Views = []*models.View{models.InitView("v", "public")} },
|
||||||
{"script added", func(s *models.Schema) { s.Scripts = []*models.Script{models.InitScript("sc")} },
|
func(c *SchemaChange) bool { return c.Views != nil && len(c.Views.Extra) == 1 },
|
||||||
func(c *SchemaChange) bool { return c.Scripts != nil && len(c.Scripts.Extra) == 1 }},
|
},
|
||||||
|
{
|
||||||
|
"sequence added", func(s *models.Schema) { s.Sequences = []*models.Sequence{models.InitSequence("sq", "public")} },
|
||||||
|
func(c *SchemaChange) bool { return c.Sequences != nil && len(c.Sequences.Extra) == 1 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"script added", func(s *models.Schema) { s.Scripts = []*models.Script{models.InitScript("sc")} },
|
||||||
|
func(c *SchemaChange) bool { return c.Scripts != nil && len(c.Scripts.Extra) == 1 },
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ func checkNames(t *testing.T, label string, got, want []string) {
|
|||||||
|
|
||||||
// runSortSuite exercises a by-name and by-sequence sorter pair over the shared fixture.
|
// runSortSuite exercises a by-name and by-sequence sorter pair over the shared fixture.
|
||||||
func runSortSuite[T any](t *testing.T, build func(sortCase) T, name func(T) string,
|
func runSortSuite[T any](t *testing.T, build func(sortCase) T, name func(T) string,
|
||||||
byName func([]T, bool) error, bySeq func([]T, bool) error) {
|
byName, bySeq func([]T, bool) error,
|
||||||
|
) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
mk := func() []T {
|
mk := func() []T {
|
||||||
out := make([]T, 0, len(sortFixture))
|
out := make([]T, 0, len(sortFixture))
|
||||||
|
|||||||
@@ -23,15 +23,27 @@ func mustExpr(t *testing.T, src string) ast.Expr {
|
|||||||
func TestGoTypeToSQL(t *testing.T) {
|
func TestGoTypeToSQL(t *testing.T) {
|
||||||
r := newTestReader()
|
r := newTestReader()
|
||||||
tests := []struct{ src, want string }{
|
tests := []struct{ src, want string }{
|
||||||
{"int", "integer"}, {"int32", "integer"}, {"int64", "bigint"},
|
{"int", "integer"},
|
||||||
{"string", "text"}, {"bool", "boolean"}, {"float32", "real"},
|
{"int32", "integer"},
|
||||||
{"float64", "double precision"}, {"uint8", "text"},
|
{"int64", "bigint"},
|
||||||
{"time.Time", "timestamp"}, {"time.Duration", "text"},
|
{"string", "text"},
|
||||||
{"sql_types.SqlString", "text"}, {"sql_types.SqlInt", "integer"},
|
{"bool", "boolean"},
|
||||||
{"sql_types.SqlInt64", "bigint"}, {"sql_types.SqlFloat", "double precision"},
|
{"float32", "real"},
|
||||||
{"sql_types.SqlBool", "boolean"}, {"sql_types.SqlTime", "timestamp"},
|
{"float64", "double precision"},
|
||||||
{"sql_types.Other", "text"}, {"other.Thing", "text"},
|
{"uint8", "text"},
|
||||||
{"*int64", "bigint"}, {"*time.Time", "timestamp"}, {"[]byte", "text"},
|
{"time.Time", "timestamp"},
|
||||||
|
{"time.Duration", "text"},
|
||||||
|
{"sql_types.SqlString", "text"},
|
||||||
|
{"sql_types.SqlInt", "integer"},
|
||||||
|
{"sql_types.SqlInt64", "bigint"},
|
||||||
|
{"sql_types.SqlFloat", "double precision"},
|
||||||
|
{"sql_types.SqlBool", "boolean"},
|
||||||
|
{"sql_types.SqlTime", "timestamp"},
|
||||||
|
{"sql_types.Other", "text"},
|
||||||
|
{"other.Thing", "text"},
|
||||||
|
{"*int64", "bigint"},
|
||||||
|
{"*time.Time", "timestamp"},
|
||||||
|
{"[]byte", "text"},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.src, func(t *testing.T) {
|
t.Run(tt.src, func(t *testing.T) {
|
||||||
|
|||||||
@@ -23,15 +23,27 @@ func mustExpr(t *testing.T, src string) ast.Expr {
|
|||||||
func TestGoTypeToSQL(t *testing.T) {
|
func TestGoTypeToSQL(t *testing.T) {
|
||||||
r := newTestReader()
|
r := newTestReader()
|
||||||
tests := []struct{ src, want string }{
|
tests := []struct{ src, want string }{
|
||||||
{"int", "integer"}, {"int32", "integer"}, {"int64", "bigint"},
|
{"int", "integer"},
|
||||||
{"string", "text"}, {"bool", "boolean"}, {"float32", "real"},
|
{"int32", "integer"},
|
||||||
{"float64", "double precision"}, {"uint8", "text"},
|
{"int64", "bigint"},
|
||||||
{"time.Time", "timestamp"}, {"time.Duration", "text"},
|
{"string", "text"},
|
||||||
{"sql_types.SqlString", "text"}, {"sql_types.SqlInt", "integer"},
|
{"bool", "boolean"},
|
||||||
{"sql_types.SqlInt64", "bigint"}, {"sql_types.SqlFloat", "double precision"},
|
{"float32", "real"},
|
||||||
{"sql_types.SqlBool", "boolean"}, {"sql_types.SqlTime", "timestamp"},
|
{"float64", "double precision"},
|
||||||
{"sql_types.Other", "text"}, {"other.Thing", "text"},
|
{"uint8", "text"},
|
||||||
{"*int64", "bigint"}, {"*time.Time", "timestamp"}, {"[]byte", "text"},
|
{"time.Time", "timestamp"},
|
||||||
|
{"time.Duration", "text"},
|
||||||
|
{"sql_types.SqlString", "text"},
|
||||||
|
{"sql_types.SqlInt", "integer"},
|
||||||
|
{"sql_types.SqlInt64", "bigint"},
|
||||||
|
{"sql_types.SqlFloat", "double precision"},
|
||||||
|
{"sql_types.SqlBool", "boolean"},
|
||||||
|
{"sql_types.SqlTime", "timestamp"},
|
||||||
|
{"sql_types.Other", "text"},
|
||||||
|
{"other.Thing", "text"},
|
||||||
|
{"*int64", "bigint"},
|
||||||
|
{"*time.Time", "timestamp"},
|
||||||
|
{"[]byte", "text"},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.src, func(t *testing.T) {
|
t.Run(tt.src, func(t *testing.T) {
|
||||||
|
|||||||
@@ -224,9 +224,12 @@ func TestParseDatasourceProviders(t *testing.T) {
|
|||||||
provider string
|
provider string
|
||||||
want models.DatabaseType
|
want models.DatabaseType
|
||||||
}{
|
}{
|
||||||
{`"postgresql"`, models.PostgresqlDatabaseType}, {`"postgres"`, models.PostgresqlDatabaseType},
|
{`"postgresql"`, models.PostgresqlDatabaseType},
|
||||||
{`"mysql"`, "mysql"}, {`"sqlite"`, models.SqlLiteDatabaseType},
|
{`"postgres"`, models.PostgresqlDatabaseType},
|
||||||
{`"sqlserver"`, models.MSSQLDatabaseType}, {`"cockroachdb"`, models.PostgresqlDatabaseType},
|
{`"mysql"`, "mysql"},
|
||||||
|
{`"sqlite"`, models.SqlLiteDatabaseType},
|
||||||
|
{`"sqlserver"`, models.MSSQLDatabaseType},
|
||||||
|
{`"cockroachdb"`, models.PostgresqlDatabaseType},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
db := models.InitDatabase("d")
|
db := models.InitDatabase("d")
|
||||||
|
|||||||
@@ -321,8 +321,14 @@ func TestMatchDecorator(t *testing.T) {
|
|||||||
func TestTypeScriptTypeToSQL(t *testing.T) {
|
func TestTypeScriptTypeToSQL(t *testing.T) {
|
||||||
r := &Reader{}
|
r := &Reader{}
|
||||||
tests := []struct{ in, want string }{
|
tests := []struct{ in, want string }{
|
||||||
{"string", "text"}, {"number", "integer"}, {"boolean", "boolean"}, {"Date", "timestamp"},
|
{"string", "text"},
|
||||||
{"any", "jsonb"}, {"string[]", "text"}, {"string | null", "text"}, {"Unknown", "text"},
|
{"number", "integer"},
|
||||||
|
{"boolean", "boolean"},
|
||||||
|
{"Date", "timestamp"},
|
||||||
|
{"any", "jsonb"},
|
||||||
|
{"string[]", "text"},
|
||||||
|
{"string | null", "text"},
|
||||||
|
{"Unknown", "text"},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if got := r.typeScriptTypeToSQL(tt.in); got != tt.want {
|
if got := r.typeScriptTypeToSQL(tt.in); got != tt.want {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type wrapped[T any] struct {
|
|||||||
|
|
||||||
// arrayRoundTrip runs the full Scan/Value/JSON/YAML/XML contract for one array type.
|
// arrayRoundTrip runs the full Scan/Value/JSON/YAML/XML contract for one array type.
|
||||||
// badScan is a literal the type's Scan must reject ("" skips the check).
|
// badScan is a literal the type's Scan must reject ("" skips the check).
|
||||||
func arrayRoundTrip[T any, P arrayPtr[T]](t *testing.T, sample T, null T, badScan string) {
|
func arrayRoundTrip[T any, P arrayPtr[T]](t *testing.T, sample, null T, badScan string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
sv, ok := any(sample).(arrayValue)
|
sv, ok := any(sample).(arrayValue)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -149,10 +149,17 @@ func TestObjectKind_CreateIndexFromForm(t *testing.T) {
|
|||||||
|
|
||||||
func TestLoadDatabase(t *testing.T) {
|
func TestLoadDatabase(t *testing.T) {
|
||||||
for _, tt := range []struct{ format, path string }{
|
for _, tt := range []struct{ format, path string }{
|
||||||
{"dbml", "dbml/simple.dbml"}, {"json", "json/database.json"}, {"yaml", "yaml/database.yaml"},
|
{"dbml", "dbml/simple.dbml"},
|
||||||
{"drawdb", "drawdb/simple.json"}, {"dctx", "dctx/p1.dctx"}, {"graphql", "graphql/simple.graphql"},
|
{"json", "json/database.json"},
|
||||||
{"prisma", "prisma/example.prisma"}, {"typeorm", "typeorm/example.ts"},
|
{"yaml", "yaml/database.yaml"},
|
||||||
{"drizzle", "drizzle/schema.ts"}, {"gorm", "gorm/simple.go"}, {"bun", "bun/simple.go"},
|
{"drawdb", "drawdb/simple.json"},
|
||||||
|
{"dctx", "dctx/p1.dctx"},
|
||||||
|
{"graphql", "graphql/simple.graphql"},
|
||||||
|
{"prisma", "prisma/example.prisma"},
|
||||||
|
{"typeorm", "typeorm/example.ts"},
|
||||||
|
{"drizzle", "drizzle/schema.ts"},
|
||||||
|
{"gorm", "gorm/simple.go"},
|
||||||
|
{"bun", "bun/simple.go"},
|
||||||
} {
|
} {
|
||||||
t.Run(tt.format, func(t *testing.T) {
|
t.Run(tt.format, func(t *testing.T) {
|
||||||
se := newUIEditor()
|
se := newUIEditor()
|
||||||
@@ -200,9 +207,16 @@ func TestCreateNewDatabase(t *testing.T) {
|
|||||||
|
|
||||||
func TestSaveDatabase(t *testing.T) {
|
func TestSaveDatabase(t *testing.T) {
|
||||||
for _, tt := range []struct{ format, file string }{
|
for _, tt := range []struct{ format, file string }{
|
||||||
{"json", "o.json"}, {"yaml", "o.yaml"}, {"dbml", "o.dbml"}, {"drawdb", "o.drawdb.json"},
|
{"json", "o.json"},
|
||||||
{"graphql", "o.graphql"}, {"prisma", "o.prisma"}, {"typeorm", "o.ts"}, {"drizzle", "d.ts"},
|
{"yaml", "o.yaml"},
|
||||||
{"gorm", "g.go"}, {"bun", "b.go"},
|
{"dbml", "o.dbml"},
|
||||||
|
{"drawdb", "o.drawdb.json"},
|
||||||
|
{"graphql", "o.graphql"},
|
||||||
|
{"prisma", "o.prisma"},
|
||||||
|
{"typeorm", "o.ts"},
|
||||||
|
{"drizzle", "d.ts"},
|
||||||
|
{"gorm", "g.go"},
|
||||||
|
{"bun", "b.go"},
|
||||||
} {
|
} {
|
||||||
t.Run(tt.format, func(t *testing.T) {
|
t.Run(tt.format, func(t *testing.T) {
|
||||||
se := newUIEditor()
|
se := newUIEditor()
|
||||||
|
|||||||
@@ -219,11 +219,19 @@ func TestFormatDefaultValue(t *testing.T) {
|
|||||||
in any
|
in any
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{"now()", "sql`now()`"}, {"CURRENT_TIMESTAMP", "sql`now()`"},
|
{"now()", "sql`now()`"},
|
||||||
{"gen_random_uuid()", "sql`gen_random_uuid()`"}, {"uuid_generate_v4()", "sql`gen_random_uuid()`"},
|
{"CURRENT_TIMESTAMP", "sql`now()`"},
|
||||||
{"42", "42"}, {"-1.5", "-1.5"}, {"it's", `'it\'s'`}, {"plain", "'plain'"},
|
{"gen_random_uuid()", "sql`gen_random_uuid()`"},
|
||||||
{true, "true"}, {false, "false"},
|
{"uuid_generate_v4()", "sql`gen_random_uuid()`"},
|
||||||
{7, "7"}, {int64(8), "8"}, {2.5, "2.5"},
|
{"42", "42"},
|
||||||
|
{"-1.5", "-1.5"},
|
||||||
|
{"it's", `'it\'s'`},
|
||||||
|
{"plain", "'plain'"},
|
||||||
|
{true, "true"},
|
||||||
|
{false, "false"},
|
||||||
|
{7, "7"},
|
||||||
|
{int64(8), "8"},
|
||||||
|
{2.5, "2.5"},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if got := tm.formatDefaultValue(tt.in); got != tt.want {
|
if got := tm.formatDefaultValue(tt.in); got != tt.want {
|
||||||
|
|||||||
@@ -13,15 +13,30 @@ func TestSQLTypeToPrisma(t *testing.T) {
|
|||||||
schema.Enums = append(schema.Enums, &models.Enum{Name: "Role", Values: []string{"A"}})
|
schema.Enums = append(schema.Enums, &models.Enum{Name: "Role", Values: []string{"A"}})
|
||||||
|
|
||||||
tests := []struct{ in, want string }{
|
tests := []struct{ in, want string }{
|
||||||
{"text", "String"}, {"varchar(255)", "String"}, {"character varying", "String"}, {"char(1)", "String"},
|
{"text", "String"},
|
||||||
{"boolean", "Boolean"}, {"bool", "Boolean"},
|
{"varchar(255)", "String"},
|
||||||
{"integer", "Int"}, {"int", "Int"}, {"int4", "Int"},
|
{"character varying", "String"},
|
||||||
{"bigint", "BigInt"}, {"int8", "BigInt"}, {"BIGINT", "BigInt"},
|
{"char(1)", "String"},
|
||||||
{"double precision", "Float"}, {"float8", "Float"},
|
{"boolean", "Boolean"},
|
||||||
{"numeric(10,2)", "Decimal"}, {"decimal", "Decimal"},
|
{"bool", "Boolean"},
|
||||||
{"timestamp", "DateTime"}, {"timestamptz", "DateTime"}, {"date", "DateTime"},
|
{"integer", "Int"},
|
||||||
{"jsonb", "Json"}, {"json", "Json"}, {"bytea", "Bytes"},
|
{"int", "Int"},
|
||||||
{"role", "Role"}, {"unknown_type", "String"},
|
{"int4", "Int"},
|
||||||
|
{"bigint", "BigInt"},
|
||||||
|
{"int8", "BigInt"},
|
||||||
|
{"BIGINT", "BigInt"},
|
||||||
|
{"double precision", "Float"},
|
||||||
|
{"float8", "Float"},
|
||||||
|
{"numeric(10,2)", "Decimal"},
|
||||||
|
{"decimal", "Decimal"},
|
||||||
|
{"timestamp", "DateTime"},
|
||||||
|
{"timestamptz", "DateTime"},
|
||||||
|
{"date", "DateTime"},
|
||||||
|
{"jsonb", "Json"},
|
||||||
|
{"json", "Json"},
|
||||||
|
{"bytea", "Bytes"},
|
||||||
|
{"role", "Role"},
|
||||||
|
{"unknown_type", "String"},
|
||||||
}
|
}
|
||||||
// Repeat: the mapping used to depend on map iteration order.
|
// Repeat: the mapping used to depend on map iteration order.
|
||||||
for i := 0; i < 50; i++ {
|
for i := 0; i < 50; i++ {
|
||||||
|
|||||||
@@ -140,9 +140,15 @@ func TestFormatDefaultValue(t *testing.T) {
|
|||||||
in any
|
in any
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{"now()", "now()"}, {"gen_random_uuid()", "uuid()"}, {"uuid_generate_v4()", "uuid()"},
|
{"now()", "now()"},
|
||||||
{"hello", `"hello"`}, {true, "true"}, {false, "false"},
|
{"gen_random_uuid()", "uuid()"},
|
||||||
{42, "42"}, {int64(7), "7"}, {1.5, "1.5"},
|
{"uuid_generate_v4()", "uuid()"},
|
||||||
|
{"hello", `"hello"`},
|
||||||
|
{true, "true"},
|
||||||
|
{false, "false"},
|
||||||
|
{42, "42"},
|
||||||
|
{int64(7), "7"},
|
||||||
|
{1.5, "1.5"},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if got := w.formatDefaultValue(tt.in); got != tt.want {
|
if got := w.formatDefaultValue(tt.in); got != tt.want {
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestColumnTypesSurviveRoundTrip(t *testing.T) {
|
func TestColumnTypesSurviveRoundTrip(t *testing.T) {
|
||||||
types := []string{"integer", "boolean", "timestamp", "text", "uuid", "jsonb", "bigint",
|
types := []string{
|
||||||
"varchar(255)", "char(3)", "numeric(10,2)", "timestamptz", "smallint", "date", "double precision"}
|
"integer", "boolean", "timestamp", "text", "uuid", "jsonb", "bigint",
|
||||||
|
"varchar(255)", "char(3)", "numeric(10,2)", "timestamptz", "smallint", "date", "double precision",
|
||||||
|
}
|
||||||
|
|
||||||
tbl := models.InitTable("things", "public")
|
tbl := models.InitTable("things", "public")
|
||||||
id := models.InitColumn("id", "things", "public")
|
id := models.InitColumn("id", "things", "public")
|
||||||
|
|||||||
Reference in New Issue
Block a user