mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-23 16:02:14 +00:00
# Which Problems Are Solved This is a small refactoring for tests in `backend/v3/domain` package to use `assert.ErrorIs` instead of `assert.Equal` for error assertion. # How the Problems Are Solved - Add custom `Is()` function to `MultipleObjectsUpdatedError` error - Substitute `assert.Equal` with `assert.ErrorIs` in instance and organization tests # Additional Context This was part of #11035
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type wrongIDPTypeError struct {
|
|
expected IDPType
|
|
got string
|
|
}
|
|
|
|
func NewIDPWrongTypeError(expected IDPType, got fmt.Stringer) error {
|
|
return &wrongIDPTypeError{
|
|
expected: expected,
|
|
got: got.String(),
|
|
}
|
|
}
|
|
|
|
func (e *wrongIDPTypeError) Error() string {
|
|
return fmt.Sprintf("wrong idp type returned, expected: %v, got: %v", e.expected, e.got)
|
|
}
|
|
|
|
func (e *wrongIDPTypeError) Is(target error) bool {
|
|
_, ok := target.(*wrongIDPTypeError)
|
|
return ok
|
|
}
|
|
|
|
type MultipleObjectsUpdatedError struct {
|
|
Msg string
|
|
Expected int64
|
|
Actual int64
|
|
}
|
|
|
|
func NewMultipleObjectsUpdatedError(expected, actual int64) error {
|
|
return &MultipleObjectsUpdatedError{
|
|
Expected: expected,
|
|
Actual: actual,
|
|
}
|
|
}
|
|
|
|
func (err *MultipleObjectsUpdatedError) Error() string {
|
|
return fmt.Sprintf("Message=expecting %d row(s) updated, got %d", err.Expected, err.Actual)
|
|
}
|
|
|
|
func (err *MultipleObjectsUpdatedError) Is(target error) bool {
|
|
_, ok := target.(*MultipleObjectsUpdatedError)
|
|
return ok
|
|
}
|
|
|
|
type UnexpectedQueryTypeError[T any] struct {
|
|
assertedType T
|
|
}
|
|
|
|
func NewUnexpectedQueryTypeError[T any](assertedType T) error {
|
|
return &UnexpectedQueryTypeError[T]{
|
|
assertedType: assertedType,
|
|
}
|
|
}
|
|
|
|
func (u *UnexpectedQueryTypeError[T]) Error() string {
|
|
return fmt.Sprintf("Message=unexpected query type '%T'", u.assertedType)
|
|
}
|
|
|
|
type UnexpectedTextQueryOperationError[T any] struct {
|
|
assertedType T
|
|
}
|
|
|
|
func NewUnexpectedTextQueryOperationError[T any](assertedType T) error {
|
|
return &UnexpectedTextQueryOperationError[T]{
|
|
assertedType: assertedType,
|
|
}
|
|
}
|
|
|
|
func (u *UnexpectedTextQueryOperationError[T]) Error() string {
|
|
return fmt.Sprintf("Message=unexpected text query operation type '%T'", u.assertedType)
|
|
}
|