Files
zitadel/backend/v3/domain/errors.go
T
Marco A.andGitHub 2793abf1e3 chore(domain): Assert errors using ErrorIS for instance and organization tests (#11789)
# 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
2026-03-06 19:20:54 +01:00

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)
}