-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotfound_test.go
34 lines (29 loc) · 1.17 KB
/
notfound_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
package errs
import (
"database/sql"
"errors"
"fmt"
"os"
)
func ExampleErrNotFound() {
var ErrUserNotFound = fmt.Errorf("user %w", ErrNotFound)
fmt.Println(`IsErrNotFound(ErrUserNotFound):`, IsErrNotFound(ErrUserNotFound))
fmt.Println(`IsErrNotFound(ErrNotFound):`, IsErrNotFound(ErrNotFound))
fmt.Println(`IsErrNotFound(sql.ErrNoRows):`, IsErrNotFound(sql.ErrNoRows))
fmt.Println(`IsErrNotFound(os.ErrNotExist):`, IsErrNotFound(os.ErrNotExist))
fmt.Println(`IsErrNotFound(Errorf("resource %w", ErrNotFound)):`, IsErrNotFound(Errorf("resource %w", ErrNotFound)))
fmt.Println()
fmt.Println(`IsErrNotFound(nil):`, IsErrNotFound(nil))
fmt.Println(`errors.Is(sql.ErrNoRows, ErrNotFound):`, errors.Is(sql.ErrNoRows, ErrNotFound))
fmt.Println(`errors.Is(os.ErrNotExist, ErrNotFound):`, errors.Is(os.ErrNotExist, ErrNotFound))
// Output:
// IsErrNotFound(ErrUserNotFound): true
// IsErrNotFound(ErrNotFound): true
// IsErrNotFound(sql.ErrNoRows): true
// IsErrNotFound(os.ErrNotExist): true
// IsErrNotFound(Errorf("resource %w", ErrNotFound)): true
//
// IsErrNotFound(nil): false
// errors.Is(sql.ErrNoRows, ErrNotFound): false
// errors.Is(os.ErrNotExist, ErrNotFound): false
}