mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-29 02:13:30 +00:00
* Abstracting the `OrganizationRepository` in `CommandOpts` to allow for mock implementations during testing. * Generating mocks for `OrganizationRepository` and `OrganizationDomainRepository` using `mockgen`. * Updating the `UpdateOrgCommand` tests to use the new mock repositories, which simplifies the test setup and removes the need for `dbmock`. * Enhancing the `database.Change`, `database.Column`, and `database.Condition` interfaces to implement `gomock.Matcher`, enabling more effective use of gomock for matching database operations in tests. * Introducing a `noopdb` package that provides a no-operation database client for testing purposes.
103 lines
2.3 KiB
Go
103 lines
2.3 KiB
Go
package database
|
|
|
|
import "go.uber.org/mock/gomock"
|
|
|
|
type Columns []Column
|
|
|
|
// WriteQualified implements [Column].
|
|
func (m Columns) WriteQualified(builder *StatementBuilder) {
|
|
for i, col := range m {
|
|
if i > 0 {
|
|
builder.WriteString(", ")
|
|
}
|
|
col.WriteQualified(builder)
|
|
}
|
|
}
|
|
|
|
// WriteUnqualified implements [Column].
|
|
func (m Columns) WriteUnqualified(builder *StatementBuilder) {
|
|
for i, col := range m {
|
|
if i > 0 {
|
|
builder.WriteString(", ")
|
|
}
|
|
col.WriteUnqualified(builder)
|
|
}
|
|
}
|
|
|
|
// Column represents a column in a database table.
|
|
type Column interface {
|
|
gomock.Matcher
|
|
// Write(builder *StatementBuilder)
|
|
WriteQualified(builder *StatementBuilder)
|
|
WriteUnqualified(builder *StatementBuilder)
|
|
}
|
|
|
|
type column struct {
|
|
table string
|
|
name string
|
|
}
|
|
|
|
// Matches implements [Column].
|
|
func (c column) Matches(x any) bool {
|
|
toMatch, ok := x.(*column)
|
|
if !ok {
|
|
return false
|
|
}
|
|
return c.table == toMatch.table && c.name == toMatch.name
|
|
}
|
|
|
|
// String implements [Column].
|
|
func (c column) String() string {
|
|
return "database.column"
|
|
}
|
|
|
|
func NewColumn(table, name string) Column {
|
|
return column{table: table, name: name}
|
|
}
|
|
|
|
// WriteQualified implements [Column].
|
|
func (c column) WriteQualified(builder *StatementBuilder) {
|
|
builder.Grow(len(c.table) + len(c.name) + 1)
|
|
builder.WriteString(c.table)
|
|
builder.WriteRune('.')
|
|
builder.WriteString(c.name)
|
|
}
|
|
|
|
// WriteUnqualified implements [Column].
|
|
func (c column) WriteUnqualified(builder *StatementBuilder) {
|
|
builder.WriteString(c.name)
|
|
}
|
|
|
|
var _ Column = (*column)(nil)
|
|
|
|
// // ignoreCaseColumn represents two database columns, one for the
|
|
// // original value and one for the lower case value.
|
|
// type ignoreCaseColumn interface {
|
|
// Column
|
|
// WriteIgnoreCase(builder *StatementBuilder)
|
|
// }
|
|
|
|
// func NewIgnoreCaseColumn(col Column, suffix string) ignoreCaseColumn {
|
|
// return ignoreCaseCol{
|
|
// column: col,
|
|
// suffix: suffix,
|
|
// }
|
|
// }
|
|
|
|
// type ignoreCaseCol struct {
|
|
// column Column
|
|
// suffix string
|
|
// }
|
|
|
|
// // WriteIgnoreCase implements [ignoreCaseColumn].
|
|
// func (c ignoreCaseCol) WriteIgnoreCase(builder *StatementBuilder) {
|
|
// c.column.WriteQualified(builder)
|
|
// builder.WriteString(c.suffix)
|
|
// }
|
|
|
|
// // WriteQualified implements [ignoreCaseColumn].
|
|
// func (c ignoreCaseCol) WriteQualified(builder *StatementBuilder) {
|
|
// c.column.WriteQualified(builder)
|
|
// builder.WriteString(c.suffix)
|
|
// }
|