-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
30 lines (23 loc) · 936 Bytes
/
errors_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
package fs
import (
"errors"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/ungerik/go-fs/fsimpl"
)
func TestErrDoesNotExist(t *testing.T) {
notExistingFile := Local.RootDir().Join(fsimpl.RandomString())
assert.False(t, notExistingFile.Exists(), "file does not exist")
_, err := notExistingFile.OpenReader()
assert.Equal(t, NewErrDoesNotExist(notExistingFile), err, "can't open notExistingFile")
assert.True(t, errors.Is(err, os.ErrNotExist), "ErrDoesNotExist wraps os.ErrNotExist")
wrapped := fmt.Errorf("wrapped error: %w", err)
assert.NotEqual(t, NewErrDoesNotExist(notExistingFile), wrapped, "wrapped error is not equal")
assert.True(t, errors.Is(wrapped, os.ErrNotExist), "ErrDoesNotExist wraps os.ErrNotExist")
var target ErrDoesNotExist
ok := errors.As(wrapped, &target)
assert.True(t, ok, "wrapped as ErrDoesNotExist")
assert.Equal(t, target, err, "wrapped as ErrDoesNotExist")
}