From b49859537b2077269f9d0fe001fcca19f65cd29b Mon Sep 17 00:00:00 2001 From: Hein Date: Sat, 3 Oct 2026 21:41:54 +0200 Subject: [PATCH] style: reformat test tables --- pkg/diff/diff_objects_test.go | 24 +++++++++----- pkg/models/sorting_test.go | 3 +- pkg/readers/bun/helpers_test.go | 30 ++++++++++++----- pkg/readers/gorm/helpers_test.go | 30 ++++++++++++----- pkg/readers/prisma/reader_full_test.go | 9 +++-- pkg/readers/typeorm/reader_full_test.go | 10 ++++-- .../sql_array_types_roundtrip_test.go | 2 +- pkg/ui/helpers_loadsave_test.go | 28 ++++++++++++---- pkg/writers/drizzle/writer_full_test.go | 18 +++++++--- pkg/writers/prisma/types_test.go | 33 ++++++++++++++----- pkg/writers/prisma/writer_full_test.go | 12 +++++-- pkg/writers/typeorm/types_roundtrip_test.go | 6 ++-- 12 files changed, 146 insertions(+), 59 deletions(-) diff --git a/pkg/diff/diff_objects_test.go b/pkg/diff/diff_objects_test.go index 54fc012..36243e6 100644 --- a/pkg/diff/diff_objects_test.go +++ b/pkg/diff/diff_objects_test.go @@ -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) { diff --git a/pkg/models/sorting_test.go b/pkg/models/sorting_test.go index 2301069..0196f32 100644 --- a/pkg/models/sorting_test.go +++ b/pkg/models/sorting_test.go @@ -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)) diff --git a/pkg/readers/bun/helpers_test.go b/pkg/readers/bun/helpers_test.go index c486057..048de3c 100644 --- a/pkg/readers/bun/helpers_test.go +++ b/pkg/readers/bun/helpers_test.go @@ -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) { diff --git a/pkg/readers/gorm/helpers_test.go b/pkg/readers/gorm/helpers_test.go index fff36e8..2c378ca 100644 --- a/pkg/readers/gorm/helpers_test.go +++ b/pkg/readers/gorm/helpers_test.go @@ -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) { diff --git a/pkg/readers/prisma/reader_full_test.go b/pkg/readers/prisma/reader_full_test.go index 9933fa2..ca0463a 100644 --- a/pkg/readers/prisma/reader_full_test.go +++ b/pkg/readers/prisma/reader_full_test.go @@ -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") diff --git a/pkg/readers/typeorm/reader_full_test.go b/pkg/readers/typeorm/reader_full_test.go index cca38d9..d9f6bd4 100644 --- a/pkg/readers/typeorm/reader_full_test.go +++ b/pkg/readers/typeorm/reader_full_test.go @@ -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 { diff --git a/pkg/sqltypes/sql_array_types_roundtrip_test.go b/pkg/sqltypes/sql_array_types_roundtrip_test.go index 888f4b0..4f903e6 100644 --- a/pkg/sqltypes/sql_array_types_roundtrip_test.go +++ b/pkg/sqltypes/sql_array_types_roundtrip_test.go @@ -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 { diff --git a/pkg/ui/helpers_loadsave_test.go b/pkg/ui/helpers_loadsave_test.go index 764a785..548cabc 100644 --- a/pkg/ui/helpers_loadsave_test.go +++ b/pkg/ui/helpers_loadsave_test.go @@ -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() diff --git a/pkg/writers/drizzle/writer_full_test.go b/pkg/writers/drizzle/writer_full_test.go index 00cd91f..acb2d40 100644 --- a/pkg/writers/drizzle/writer_full_test.go +++ b/pkg/writers/drizzle/writer_full_test.go @@ -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 { diff --git a/pkg/writers/prisma/types_test.go b/pkg/writers/prisma/types_test.go index 2153d5e..17e58d0 100644 --- a/pkg/writers/prisma/types_test.go +++ b/pkg/writers/prisma/types_test.go @@ -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++ { diff --git a/pkg/writers/prisma/writer_full_test.go b/pkg/writers/prisma/writer_full_test.go index 6ddcd9a..8be1700 100644 --- a/pkg/writers/prisma/writer_full_test.go +++ b/pkg/writers/prisma/writer_full_test.go @@ -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 { diff --git a/pkg/writers/typeorm/types_roundtrip_test.go b/pkg/writers/typeorm/types_roundtrip_test.go index 9f33f45..9d3a4c5 100644 --- a/pkg/writers/typeorm/types_roundtrip_test.go +++ b/pkg/writers/typeorm/types_roundtrip_test.go @@ -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")