2022-01-01 17:01:51 +02:00
|
|
|
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)
|
2022-01-14 04:02:42 +02:00
|
|
|
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)
|
|
|
|
}
|
2022-01-01 17:01:51 +02:00
|
|
|
err3 := &mockErr{}
|
2022-01-14 04:02:42 +02:00
|
|
|
if !As(err2, &err3) {
|
|
|
|
t.Errorf("As(err2, &err3) got %v want: %v", As(err2, &err3), true)
|
|
|
|
}
|
2022-01-01 17:01:51 +02:00
|
|
|
}
|