mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-26 12:27:14 +00:00
Add UnexpectedQueryTypeError
This commit is contained in:
@@ -57,3 +57,19 @@ func NewOrgNameNotChangedError(errID string) error {
|
||||
func (err *OrgNameNotChangedError) Error() string {
|
||||
return fmt.Sprintf("ID=%s Message=organization name has not changed", err.ID)
|
||||
}
|
||||
|
||||
type UnexpectedQueryTypeError[T any] struct {
|
||||
ID string
|
||||
assertedType T
|
||||
}
|
||||
|
||||
func NewUnexpectedQueryTypeError[T any](errID string, assertedType T) error {
|
||||
return &UnexpectedQueryTypeError[T]{
|
||||
ID: errID,
|
||||
assertedType: assertedType,
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UnexpectedQueryTypeError[T]) Error() string {
|
||||
return fmt.Sprintf("ID=%s Message=unexpected query type '%T'", u.ID, u.assertedType)
|
||||
}
|
||||
|
||||
42
backend/v3/domain/errors_test.go
Normal file
42
backend/v3/domain/errors_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUnexpectedQueryTypeError_Error(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
id string
|
||||
typeVal any
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "string type",
|
||||
id: "id1",
|
||||
typeVal: "test",
|
||||
expected: "ID=id1 Message=unexpected query type 'string'",
|
||||
},
|
||||
{
|
||||
name: "int type",
|
||||
id: "id2",
|
||||
typeVal: 42,
|
||||
expected: "ID=id2 Message=unexpected query type 'int'",
|
||||
},
|
||||
{
|
||||
name: "struct type",
|
||||
id: "id3",
|
||||
typeVal: struct{}{},
|
||||
expected: "ID=id3 Message=unexpected query type 'struct {}'",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := NewUnexpectedQueryTypeError(tt.id, tt.typeVal)
|
||||
assert.Equal(t, tt.expected, err.Error())
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user