style: reformat test tables
This commit is contained in:
@@ -23,14 +23,22 @@ func TestCompareSchemaDetails(t *testing.T) {
|
||||
mutate func(*models.Schema)
|
||||
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 }},
|
||||
{"view added", func(s *models.Schema) { s.Views = []*models.View{models.InitView("v", "public")} },
|
||||
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 }},
|
||||
{"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 }},
|
||||
{
|
||||
"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 },
|
||||
},
|
||||
{
|
||||
"view added", func(s *models.Schema) { s.Views = []*models.View{models.InitView("v", "public")} },
|
||||
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 },
|
||||
},
|
||||
{
|
||||
"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 {
|
||||
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.
|
||||
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()
|
||||
mk := func() []T {
|
||||
out := make([]T, 0, len(sortFixture))
|
||||
|
||||
@@ -23,15 +23,27 @@ func mustExpr(t *testing.T, src string) ast.Expr {
|
||||
func TestGoTypeToSQL(t *testing.T) {
|
||||
r := newTestReader()
|
||||
tests := []struct{ src, want string }{
|
||||
{"int", "integer"}, {"int32", "integer"}, {"int64", "bigint"},
|
||||
{"string", "text"}, {"bool", "boolean"}, {"float32", "real"},
|
||||
{"float64", "double precision"}, {"uint8", "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"},
|
||||
{"int", "integer"},
|
||||
{"int32", "integer"},
|
||||
{"int64", "bigint"},
|
||||
{"string", "text"},
|
||||
{"bool", "boolean"},
|
||||
{"float32", "real"},
|
||||
{"float64", "double precision"},
|
||||
{"uint8", "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 {
|
||||
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) {
|
||||
r := newTestReader()
|
||||
tests := []struct{ src, want string }{
|
||||
{"int", "integer"}, {"int32", "integer"}, {"int64", "bigint"},
|
||||
{"string", "text"}, {"bool", "boolean"}, {"float32", "real"},
|
||||
{"float64", "double precision"}, {"uint8", "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"},
|
||||
{"int", "integer"},
|
||||
{"int32", "integer"},
|
||||
{"int64", "bigint"},
|
||||
{"string", "text"},
|
||||
{"bool", "boolean"},
|
||||
{"float32", "real"},
|
||||
{"float64", "double precision"},
|
||||
{"uint8", "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 {
|
||||
t.Run(tt.src, func(t *testing.T) {
|
||||
|
||||
@@ -224,9 +224,12 @@ func TestParseDatasourceProviders(t *testing.T) {
|
||||
provider string
|
||||
want models.DatabaseType
|
||||
}{
|
||||
{`"postgresql"`, models.PostgresqlDatabaseType}, {`"postgres"`, models.PostgresqlDatabaseType},
|
||||
{`"mysql"`, "mysql"}, {`"sqlite"`, models.SqlLiteDatabaseType},
|
||||
{`"sqlserver"`, models.MSSQLDatabaseType}, {`"cockroachdb"`, models.PostgresqlDatabaseType},
|
||||
{`"postgresql"`, models.PostgresqlDatabaseType},
|
||||
{`"postgres"`, models.PostgresqlDatabaseType},
|
||||
{`"mysql"`, "mysql"},
|
||||
{`"sqlite"`, models.SqlLiteDatabaseType},
|
||||
{`"sqlserver"`, models.MSSQLDatabaseType},
|
||||
{`"cockroachdb"`, models.PostgresqlDatabaseType},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
db := models.InitDatabase("d")
|
||||
|
||||
@@ -321,8 +321,14 @@ func TestMatchDecorator(t *testing.T) {
|
||||
func TestTypeScriptTypeToSQL(t *testing.T) {
|
||||
r := &Reader{}
|
||||
tests := []struct{ in, want string }{
|
||||
{"string", "text"}, {"number", "integer"}, {"boolean", "boolean"}, {"Date", "timestamp"},
|
||||
{"any", "jsonb"}, {"string[]", "text"}, {"string | null", "text"}, {"Unknown", "text"},
|
||||
{"string", "text"},
|
||||
{"number", "integer"},
|
||||
{"boolean", "boolean"},
|
||||
{"Date", "timestamp"},
|
||||
{"any", "jsonb"},
|
||||
{"string[]", "text"},
|
||||
{"string | null", "text"},
|
||||
{"Unknown", "text"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
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.
|
||||
// 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()
|
||||
sv, ok := any(sample).(arrayValue)
|
||||
if !ok {
|
||||
|
||||
@@ -149,10 +149,17 @@ func TestObjectKind_CreateIndexFromForm(t *testing.T) {
|
||||
|
||||
func TestLoadDatabase(t *testing.T) {
|
||||
for _, tt := range []struct{ format, path string }{
|
||||
{"dbml", "dbml/simple.dbml"}, {"json", "json/database.json"}, {"yaml", "yaml/database.yaml"},
|
||||
{"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"},
|
||||
{"dbml", "dbml/simple.dbml"},
|
||||
{"json", "json/database.json"},
|
||||
{"yaml", "yaml/database.yaml"},
|
||||
{"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) {
|
||||
se := newUIEditor()
|
||||
@@ -200,9 +207,16 @@ func TestCreateNewDatabase(t *testing.T) {
|
||||
|
||||
func TestSaveDatabase(t *testing.T) {
|
||||
for _, tt := range []struct{ format, file string }{
|
||||
{"json", "o.json"}, {"yaml", "o.yaml"}, {"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"},
|
||||
{"json", "o.json"},
|
||||
{"yaml", "o.yaml"},
|
||||
{"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) {
|
||||
se := newUIEditor()
|
||||
|
||||
@@ -219,11 +219,19 @@ func TestFormatDefaultValue(t *testing.T) {
|
||||
in any
|
||||
want string
|
||||
}{
|
||||
{"now()", "sql`now()`"}, {"CURRENT_TIMESTAMP", "sql`now()`"},
|
||||
{"gen_random_uuid()", "sql`gen_random_uuid()`"}, {"uuid_generate_v4()", "sql`gen_random_uuid()`"},
|
||||
{"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"},
|
||||
{"now()", "sql`now()`"},
|
||||
{"CURRENT_TIMESTAMP", "sql`now()`"},
|
||||
{"gen_random_uuid()", "sql`gen_random_uuid()`"},
|
||||
{"uuid_generate_v4()", "sql`gen_random_uuid()`"},
|
||||
{"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 {
|
||||
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"}})
|
||||
|
||||
tests := []struct{ in, want string }{
|
||||
{"text", "String"}, {"varchar(255)", "String"}, {"character varying", "String"}, {"char(1)", "String"},
|
||||
{"boolean", "Boolean"}, {"bool", "Boolean"},
|
||||
{"integer", "Int"}, {"int", "Int"}, {"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"},
|
||||
{"text", "String"},
|
||||
{"varchar(255)", "String"},
|
||||
{"character varying", "String"},
|
||||
{"char(1)", "String"},
|
||||
{"boolean", "Boolean"},
|
||||
{"bool", "Boolean"},
|
||||
{"integer", "Int"},
|
||||
{"int", "Int"},
|
||||
{"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.
|
||||
for i := 0; i < 50; i++ {
|
||||
|
||||
@@ -140,9 +140,15 @@ func TestFormatDefaultValue(t *testing.T) {
|
||||
in any
|
||||
want string
|
||||
}{
|
||||
{"now()", "now()"}, {"gen_random_uuid()", "uuid()"}, {"uuid_generate_v4()", "uuid()"},
|
||||
{"hello", `"hello"`}, {true, "true"}, {false, "false"},
|
||||
{42, "42"}, {int64(7), "7"}, {1.5, "1.5"},
|
||||
{"now()", "now()"},
|
||||
{"gen_random_uuid()", "uuid()"},
|
||||
{"uuid_generate_v4()", "uuid()"},
|
||||
{"hello", `"hello"`},
|
||||
{true, "true"},
|
||||
{false, "false"},
|
||||
{42, "42"},
|
||||
{int64(7), "7"},
|
||||
{1.5, "1.5"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := w.formatDefaultValue(tt.in); got != tt.want {
|
||||
|
||||
@@ -11,8 +11,10 @@ import (
|
||||
)
|
||||
|
||||
func TestColumnTypesSurviveRoundTrip(t *testing.T) {
|
||||
types := []string{"integer", "boolean", "timestamp", "text", "uuid", "jsonb", "bigint",
|
||||
"varchar(255)", "char(3)", "numeric(10,2)", "timestamptz", "smallint", "date", "double precision"}
|
||||
types := []string{
|
||||
"integer", "boolean", "timestamp", "text", "uuid", "jsonb", "bigint",
|
||||
"varchar(255)", "char(3)", "numeric(10,2)", "timestamptz", "smallint", "date", "double precision",
|
||||
}
|
||||
|
||||
tbl := models.InitTable("things", "public")
|
||||
id := models.InitColumn("id", "things", "public")
|
||||
|
||||
Reference in New Issue
Block a user