-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiserror_test.go
36 lines (31 loc) · 922 Bytes
/
iserror_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package hamcrest_test
import (
"fmt"
"testing"
. "github.com/pepinns/go-hamcrest"
)
type isErrStruct struct {
}
func Test_IsError(t *testing.T) {
baseError := fmt.Errorf("BaseError")
t.Run("succeeds using an error", func(t *testing.T) {
err := fmt.Errorf("error")
Assert(t).That(err, IsError(err))
})
t.Run("succeeds using a wrapped error", func(t *testing.T) {
err := fmt.Errorf("error: %w", baseError)
Assert(t).That(err, IsError(baseError))
})
t.Run("fails when errors mismatch", func(t *testing.T) {
err := fmt.Errorf("error1")
err2 := fmt.Errorf("error2")
Assert(t).That(err, Not(IsError(err2)))
})
t.Run("fails when wrapped errors mismatch", func(t *testing.T) {
err := fmt.Errorf("error2: %w", fmt.Errorf("error3"))
Assert(t).That(err, Not(IsError(baseError)))
})
t.Run("fails when input is not an error", func(t *testing.T) {
Assert(t).That(42, Not(IsError(baseError)))
})
}