Add UnexpectedQueryTypeError

This commit is contained in:
Marco Ardizzone
2025-09-22 10:28:57 +02:00
parent 80902651bd
commit 4f6fb494cb
2 changed files with 58 additions and 0 deletions

View File

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

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