style: gofmt test files

This commit is contained in:
2026-10-07 20:58:44 +02:00
parent 5a3a1df3c8
commit 3efd539e0f
4 changed files with 73 additions and 63 deletions
@@ -1,3 +1,4 @@
//go:build integration
// +build integration // +build integration
package database package database
@@ -18,11 +19,11 @@ import (
// Integration test models // Integration test models
type IntegrationUser struct { type IntegrationUser struct {
ID int `db:"id"` ID int `db:"id"`
Name string `db:"name"` Name string `db:"name"`
Email string `db:"email"` Email string `db:"email"`
Age int `db:"age"` Age int `db:"age"`
CreatedAt time.Time `db:"created_at"` CreatedAt time.Time `db:"created_at"`
Posts []*IntegrationPost `bun:"rel:has-many,join:id=user_id"` Posts []*IntegrationPost `bun:"rel:has-many,join:id=user_id"`
} }
@@ -46,10 +47,10 @@ func (p IntegrationPost) TableName() string {
} }
type IntegrationComment struct { type IntegrationComment struct {
ID int `db:"id"` ID int `db:"id"`
Content string `db:"content"` Content string `db:"content"`
PostID int `db:"post_id"` PostID int `db:"post_id"`
CreatedAt time.Time `db:"created_at"` CreatedAt time.Time `db:"created_at"`
Post *IntegrationPost `bun:"rel:belongs-to,join:post_id=id"` Post *IntegrationPost `bun:"rel:belongs-to,join:post_id=id"`
} }
+5 -5
View File
@@ -26,11 +26,11 @@ func (u TestUser) TableName() string {
} }
type TestPost struct { type TestPost struct {
ID int `db:"id"` ID int `db:"id"`
Title string `db:"title"` Title string `db:"title"`
Content string `db:"content"` Content string `db:"content"`
UserID int `db:"user_id"` UserID int `db:"user_id"`
User *TestUser `bun:"rel:belongs-to,join:user_id=id"` User *TestUser `bun:"rel:belongs-to,join:user_id=id"`
Comments []TestComment `bun:"rel:has-many,join:id=post_id"` Comments []TestComment `bun:"rel:has-many,join:id=post_id"`
} }
+43 -35
View File
@@ -25,10 +25,10 @@ func newMockDatabase() *mockDatabase {
} }
} }
func (m *mockDatabase) NewSelect() SelectQuery { return &mockSelectQuery{} } func (m *mockDatabase) NewSelect() SelectQuery { return &mockSelectQuery{} }
func (m *mockDatabase) NewInsert() InsertQuery { return &mockInsertQuery{db: m} } func (m *mockDatabase) NewInsert() InsertQuery { return &mockInsertQuery{db: m} }
func (m *mockDatabase) NewUpdate() UpdateQuery { return &mockUpdateQuery{db: m} } func (m *mockDatabase) NewUpdate() UpdateQuery { return &mockUpdateQuery{db: m} }
func (m *mockDatabase) NewDelete() DeleteQuery { return &mockDeleteQuery{db: m} } func (m *mockDatabase) NewDelete() DeleteQuery { return &mockDeleteQuery{db: m} }
func (m *mockDatabase) RunInTransaction(ctx context.Context, fn func(Database) error) error { func (m *mockDatabase) RunInTransaction(ctx context.Context, fn func(Database) error) error {
return fn(m) return fn(m)
} }
@@ -57,27 +57,31 @@ func (m *mockDatabase) DriverName() string {
// Mock SelectQuery // Mock SelectQuery
type mockSelectQuery struct{} type mockSelectQuery struct{}
func (m *mockSelectQuery) Model(model interface{}) SelectQuery { return m } func (m *mockSelectQuery) Model(model interface{}) SelectQuery { return m }
func (m *mockSelectQuery) Table(name string) SelectQuery { return m } func (m *mockSelectQuery) Table(name string) SelectQuery { return m }
func (m *mockSelectQuery) Column(columns ...string) SelectQuery { return m } func (m *mockSelectQuery) Column(columns ...string) SelectQuery { return m }
func (m *mockSelectQuery) ColumnExpr(query string, args ...interface{}) SelectQuery { return m } func (m *mockSelectQuery) ColumnExpr(query string, args ...interface{}) SelectQuery { return m }
func (m *mockSelectQuery) Where(condition string, args ...interface{}) SelectQuery { return m } func (m *mockSelectQuery) Where(condition string, args ...interface{}) SelectQuery { return m }
func (m *mockSelectQuery) WhereOr(query string, args ...interface{}) SelectQuery { return m } func (m *mockSelectQuery) WhereOr(query string, args ...interface{}) SelectQuery { return m }
func (m *mockSelectQuery) Join(query string, args ...interface{}) SelectQuery { return m } func (m *mockSelectQuery) Join(query string, args ...interface{}) SelectQuery { return m }
func (m *mockSelectQuery) LeftJoin(query string, args ...interface{}) SelectQuery { return m } func (m *mockSelectQuery) LeftJoin(query string, args ...interface{}) SelectQuery { return m }
func (m *mockSelectQuery) Preload(relation string, conditions ...interface{}) SelectQuery { return m } func (m *mockSelectQuery) Preload(relation string, conditions ...interface{}) SelectQuery { return m }
func (m *mockSelectQuery) PreloadRelation(relation string, apply ...func(SelectQuery) SelectQuery) SelectQuery { return m } func (m *mockSelectQuery) PreloadRelation(relation string, apply ...func(SelectQuery) SelectQuery) SelectQuery {
func (m *mockSelectQuery) JoinRelation(relation string, apply ...func(SelectQuery) SelectQuery) SelectQuery { return m } return m
func (m *mockSelectQuery) Order(order string) SelectQuery { return m } }
func (m *mockSelectQuery) OrderExpr(order string, args ...interface{}) SelectQuery { return m } func (m *mockSelectQuery) JoinRelation(relation string, apply ...func(SelectQuery) SelectQuery) SelectQuery {
func (m *mockSelectQuery) Limit(n int) SelectQuery { return m } return m
func (m *mockSelectQuery) Offset(n int) SelectQuery { return m } }
func (m *mockSelectQuery) Group(group string) SelectQuery { return m } func (m *mockSelectQuery) Order(order string) SelectQuery { return m }
func (m *mockSelectQuery) OrderExpr(order string, args ...interface{}) SelectQuery { return m }
func (m *mockSelectQuery) Limit(n int) SelectQuery { return m }
func (m *mockSelectQuery) Offset(n int) SelectQuery { return m }
func (m *mockSelectQuery) Group(group string) SelectQuery { return m }
func (m *mockSelectQuery) Having(condition string, args ...interface{}) SelectQuery { return m } func (m *mockSelectQuery) Having(condition string, args ...interface{}) SelectQuery { return m }
func (m *mockSelectQuery) Scan(ctx context.Context, dest interface{}) error { return nil } func (m *mockSelectQuery) Scan(ctx context.Context, dest interface{}) error { return nil }
func (m *mockSelectQuery) ScanModel(ctx context.Context) error { return nil } func (m *mockSelectQuery) ScanModel(ctx context.Context) error { return nil }
func (m *mockSelectQuery) Count(ctx context.Context) (int, error) { return 0, nil } func (m *mockSelectQuery) Count(ctx context.Context) (int, error) { return 0, nil }
func (m *mockSelectQuery) Exists(ctx context.Context) (bool, error) { return false, nil } func (m *mockSelectQuery) Exists(ctx context.Context) (bool, error) { return false, nil }
// Mock InsertQuery // Mock InsertQuery
type mockInsertQuery struct { type mockInsertQuery struct {
@@ -98,9 +102,9 @@ func (m *mockInsertQuery) Value(column string, value interface{}) InsertQuery {
m.values[column] = value m.values[column] = value
return m return m
} }
func (m *mockInsertQuery) OnConflict(action string) InsertQuery { return m } func (m *mockInsertQuery) OnConflict(action string) InsertQuery { return m }
func (m *mockInsertQuery) ExcludeColumn(columns ...string) InsertQuery { return m } func (m *mockInsertQuery) ExcludeColumn(columns ...string) InsertQuery { return m }
func (m *mockInsertQuery) Returning(columns ...string) InsertQuery { return m } func (m *mockInsertQuery) Returning(columns ...string) InsertQuery { return m }
func (m *mockInsertQuery) Exec(ctx context.Context) (Result, error) { func (m *mockInsertQuery) Exec(ctx context.Context) (Result, error) {
m.db.insertCalls = append(m.db.insertCalls, m.values) m.db.insertCalls = append(m.db.insertCalls, m.values)
m.db.lastID++ m.db.lastID++
@@ -132,8 +136,8 @@ func (m *mockUpdateQuery) SetMap(values map[string]interface{}) UpdateQuery {
return m return m
} }
func (m *mockUpdateQuery) Where(condition string, args ...interface{}) UpdateQuery { return m } func (m *mockUpdateQuery) Where(condition string, args ...interface{}) UpdateQuery { return m }
func (m *mockUpdateQuery) ExcludeColumn(columns ...string) UpdateQuery { return m } func (m *mockUpdateQuery) ExcludeColumn(columns ...string) UpdateQuery { return m }
func (m *mockUpdateQuery) Returning(columns ...string) UpdateQuery { return m } func (m *mockUpdateQuery) Returning(columns ...string) UpdateQuery { return m }
func (m *mockUpdateQuery) Exec(ctx context.Context) (Result, error) { func (m *mockUpdateQuery) Exec(ctx context.Context) (Result, error) {
// Record the update call // Record the update call
m.db.updateCalls = append(m.db.updateCalls, m.setValues) m.db.updateCalls = append(m.db.updateCalls, m.setValues)
@@ -171,9 +175,13 @@ func (m *mockResult) RowsAffected() int64 { return m.rowsAffected }
type mockModelRegistry struct{} type mockModelRegistry struct{}
func (m *mockModelRegistry) GetModel(name string) (interface{}, error) { return nil, nil } func (m *mockModelRegistry) GetModel(name string) (interface{}, error) { return nil, nil }
func (m *mockModelRegistry) GetModelByEntity(schema, entity string) (interface{}, error) { return nil, nil } func (m *mockModelRegistry) GetModelByEntity(schema, entity string) (interface{}, error) {
return nil, nil
}
func (m *mockModelRegistry) RegisterModel(name string, model interface{}) error { return nil } func (m *mockModelRegistry) RegisterModel(name string, model interface{}) error { return nil }
func (m *mockModelRegistry) GetAllModels() map[string]interface{} { return make(map[string]interface{}) } func (m *mockModelRegistry) GetAllModels() map[string]interface{} {
return make(map[string]interface{})
}
// Mock RelationshipInfoProvider // Mock RelationshipInfoProvider
type mockRelationshipProvider struct { type mockRelationshipProvider struct {
@@ -198,9 +206,9 @@ func (m *mockRelationshipProvider) RegisterRelation(modelTypeName, relationName
// Test Models // Test Models
type Department struct { type Department struct {
ID int64 `json:"id" bun:"id,pk"` ID int64 `json:"id" bun:"id,pk"`
Name string `json:"name"` Name string `json:"name"`
Employees []*Employee `json:"employees,omitempty"` Employees []*Employee `json:"employees,omitempty"`
} }
func (d Department) TableName() string { return "departments" } func (d Department) TableName() string { return "departments" }
@@ -227,9 +235,9 @@ func (t Task) TableName() string { return "tasks" }
func (t Task) GetIDName() string { return "ID" } func (t Task) GetIDName() string { return "ID" }
type Comment struct { type Comment struct {
ID int64 `json:"id" bun:"id,pk"` ID int64 `json:"id" bun:"id,pk"`
Text string `json:"text"` Text string `json:"text"`
TaskID int64 `json:"task_id"` TaskID int64 `json:"task_id"`
} }
func (c Comment) TableName() string { return "comments" } func (c Comment) TableName() string { return "comments" }
+15 -14
View File
@@ -1,3 +1,4 @@
//go:build integration
// +build integration // +build integration
package resolvespec package resolvespec
@@ -22,12 +23,12 @@ import (
// Test models // Test models
type TestUser struct { type TestUser struct {
ID uint `gorm:"primaryKey" json:"id"` ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null" json:"name"` Name string `gorm:"not null" json:"name"`
Email string `gorm:"uniqueIndex;not null" json:"email"` Email string `gorm:"uniqueIndex;not null" json:"email"`
Age int `json:"age"` Age int `json:"age"`
Active bool `gorm:"default:true" json:"active"` Active bool `gorm:"default:true" json:"active"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
Posts []TestPost `gorm:"foreignKey:UserID" json:"posts,omitempty"` Posts []TestPost `gorm:"foreignKey:UserID" json:"posts,omitempty"`
} }
@@ -36,13 +37,13 @@ func (TestUser) TableName() string {
} }
type TestPost struct { type TestPost struct {
ID uint `gorm:"primaryKey" json:"id"` ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"not null" json:"user_id"` UserID uint `gorm:"not null" json:"user_id"`
Title string `gorm:"not null" json:"title"` Title string `gorm:"not null" json:"title"`
Content string `json:"content"` Content string `json:"content"`
Published bool `gorm:"default:false" json:"published"` Published bool `gorm:"default:false" json:"published"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
User *TestUser `gorm:"foreignKey:UserID" json:"user,omitempty"` User *TestUser `gorm:"foreignKey:UserID" json:"user,omitempty"`
Comments []TestComment `gorm:"foreignKey:PostID" json:"comments,omitempty"` Comments []TestComment `gorm:"foreignKey:PostID" json:"comments,omitempty"`
} }
@@ -55,7 +56,7 @@ type TestComment struct {
PostID uint `gorm:"not null" json:"post_id"` PostID uint `gorm:"not null" json:"post_id"`
Content string `gorm:"not null" json:"content"` Content string `gorm:"not null" json:"content"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
Post *TestPost `gorm:"foreignKey:PostID" json:"post,omitempty"` Post *TestPost `gorm:"foreignKey:PostID" json:"post,omitempty"`
} }
func (TestComment) TableName() string { func (TestComment) TableName() string {