2023-12-08 16:30:55 +02:00
|
|
|
package zerrors_test
|
2020-03-18 15:45:24 +01:00
|
|
|
|
|
|
|
import (
|
2025-01-09 12:46:36 +01:00
|
|
|
"errors"
|
2020-03-18 15:45:24 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-04-03 13:43:43 +03:00
|
|
|
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2020-03-18 15:45:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrorMethod(t *testing.T) {
|
2023-12-08 16:30:55 +02:00
|
|
|
err := zerrors.ThrowError(nil, "id", "msg")
|
2020-03-18 15:45:24 +01:00
|
|
|
expected := "ID=id Message=msg"
|
|
|
|
assert.Equal(t, expected, err.Error())
|
|
|
|
|
2023-12-08 16:30:55 +02:00
|
|
|
err = zerrors.ThrowError(err, "subID", "subMsg")
|
2020-03-18 15:45:24 +01:00
|
|
|
subExptected := "ID=subID Message=subMsg Parent=(ID=id Message=msg)"
|
|
|
|
assert.Equal(t, subExptected, err.Error())
|
|
|
|
}
|
2025-01-09 12:46:36 +01:00
|
|
|
|
|
|
|
func TestIsZitadelError(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
err error
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "zitadel error",
|
|
|
|
err: zerrors.ThrowInvalidArgument(nil, "id", "msg"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "other error",
|
|
|
|
err: errors.New("just a random error"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, zerrors.IsZitadelError(tt.err), "IsZitadelError(%v)", tt.err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|