1
0
mirror of https://github.com/go-kratos/kratos.git synced 2024-12-26 20:54:38 +02:00
kratos/errors/wrap_test.go

28 lines
504 B
Go
Raw Permalink Normal View History

package errors
import (
"fmt"
"testing"
)
type mockErr struct{}
func (*mockErr) Error() string {
return "mock error"
}
func TestWarp(t *testing.T) {
var err error = &mockErr{}
err2 := fmt.Errorf("wrap %w", err)
if err != Unwrap(err2) {
t.Errorf("got %v want: %v", err, Unwrap(err2))
}
if !Is(err2, err) {
t.Errorf("Is(err2, err) got %v want: %v", Is(err2, err), true)
}
err3 := &mockErr{}
if !As(err2, &err3) {
t.Errorf("As(err2, &err3) got %v want: %v", As(err2, &err3), true)
}
}