Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarthik Nayak <knayak@gitlab.com>2023-11-29 20:03:28 +0300
committerKarthik Nayak <knayak@gitlab.com>2023-11-30 18:15:59 +0300
commit96c37cba249a36d5979d78ff6d2e686fb1a0328b (patch)
treeab7d8c7e554ecc95f899d72da229e0ed09f24d7b /internal/streamcache
parent232812c92f18f03372f73284c079d90e3c532923 (diff)
errors: Use `errors.As()` for type assertion
Currently for type assertion of errors, we use the `err.(<Interface>)` form. This works, but is not compatible with wrapped errors. So let's use `errors.As()` instead.
Diffstat (limited to 'internal/streamcache')
-rw-r--r--internal/streamcache/cache_test.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/internal/streamcache/cache_test.go b/internal/streamcache/cache_test.go
index f3a1bd57b..c8fdc82a6 100644
--- a/internal/streamcache/cache_test.go
+++ b/internal/streamcache/cache_test.go
@@ -365,8 +365,10 @@ func TestCache_unWriteableFile(t *testing.T) {
_, err := io.WriteString(w, "hello")
return err
})
- require.IsType(t, &os.PathError{}, err)
- require.Equal(t, "write", err.(*os.PathError).Op)
+
+ var pathErr *os.PathError
+ require.True(t, errors.As(err, &pathErr))
+ require.Equal(t, "write", pathErr.Op)
}
func TestCache_unCloseableFile(t *testing.T) {
@@ -385,8 +387,10 @@ func TestCache_unCloseableFile(t *testing.T) {
}
_, _, err := c.Fetch(ctx, "key", io.Discard, func(w io.Writer) error { return nil })
- require.IsType(t, &os.PathError{}, err)
- require.Equal(t, "close", err.(*os.PathError).Op)
+
+ var pathErr *os.PathError
+ require.True(t, errors.As(err, &pathErr))
+ require.Equal(t, "close", pathErr.Op)
}
func TestCache_cannotOpenFileForReading(t *testing.T) {
@@ -406,8 +410,9 @@ func TestCache_cannotOpenFileForReading(t *testing.T) {
_, _, err := c.Fetch(ctx, "key", io.Discard, func(w io.Writer) error { return nil })
err = errors.Unwrap(err)
- require.IsType(t, &os.PathError{}, err)
- require.Equal(t, "open", err.(*os.PathError).Op)
+ var pathErr *os.PathError
+ require.True(t, errors.As(err, &pathErr))
+ require.Equal(t, "open", pathErr.Op)
}
func TestWaiter(t *testing.T) {