diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-09-02 07:26:10 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-09-09 14:13:10 +0300 |
commit | 5ba8177bf2acbd44676065185797ca69a6ef56bb (patch) | |
tree | f7621116f16b4e53740a0b214e98f696d77df423 /internal | |
parent | 6b9b03db88911c9939d5fc1d92d4b15912cc7665 (diff) |
refactor: avoid os.Is.. in favor of errors.Is
Diffstat (limited to 'internal')
-rw-r--r-- | internal/serving/disk/symlink/path_test.go | 10 | ||||
-rw-r--r-- | internal/vfs/local/root_test.go | 8 | ||||
-rw-r--r-- | internal/vfs/local/vfs.go | 11 |
3 files changed, 17 insertions, 12 deletions
diff --git a/internal/serving/disk/symlink/path_test.go b/internal/serving/disk/symlink/path_test.go index 400432c2..21880efa 100644 --- a/internal/serving/disk/symlink/path_test.go +++ b/internal/serving/disk/symlink/path_test.go @@ -6,6 +6,8 @@ package symlink_test import ( "context" + "errors" + "io/fs" "os" "path/filepath" "runtime" @@ -20,7 +22,7 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/vfs/local" ) -var fs = vfs.Instrumented(&local.VFS{}) +var localFs = vfs.Instrumented(&local.VFS{}) type EvalSymlinksTest struct { // If dest is empty, the path is created; otherwise the dest is symlinked to the path. @@ -70,7 +72,7 @@ func simpleJoin(path ...string) string { } func testEvalSymlinks(t *testing.T, wd, path, want string) { - root, err := fs.Root(context.Background(), wd) + root, err := localFs.Root(context.Background(), wd) require.NoError(t, err) have, err := symlink.EvalSymlinks(context.Background(), root, path) @@ -125,7 +127,7 @@ func TestEvalSymlinksIsNotExist(t *testing.T) { root, _ := testhelpers.TmpDir(t, "symlink_tests") _, err := symlink.EvalSymlinks(context.Background(), root, "notexist") - if !os.IsNotExist(err) { + if !errors.Is(err, fs.ErrNotExist) { t.Errorf("expected the file is not found, got %v\n", err) } @@ -136,7 +138,7 @@ func TestEvalSymlinksIsNotExist(t *testing.T) { defer os.Remove("link") _, err = symlink.EvalSymlinks(context.Background(), root, "link") - if !os.IsNotExist(err) { + if !errors.Is(err, fs.ErrNotExist) { t.Errorf("expected the file is not found, got %v\n", err) } } diff --git a/internal/vfs/local/root_test.go b/internal/vfs/local/root_test.go index 1cf505bf..a835bae3 100644 --- a/internal/vfs/local/root_test.go +++ b/internal/vfs/local/root_test.go @@ -2,7 +2,9 @@ package local import ( "context" + "errors" "io" + "io/fs" "os" "path/filepath" "testing" @@ -95,7 +97,7 @@ func TestReadlink(t *testing.T) { target, err := root.Readlink(ctx, test.path) if test.expectedIsNotExist { - require.Equal(t, test.expectedIsNotExist, os.IsNotExist(err), "IsNotExist") + require.Equal(t, test.expectedIsNotExist, errors.Is(err, fs.ErrNotExist), "IsNotExist") return } @@ -211,7 +213,7 @@ func TestLstat(t *testing.T) { fi, err := root.Lstat(ctx, test.path) if test.expectedIsNotExist { - require.Equal(t, test.expectedIsNotExist, os.IsNotExist(err), "IsNotExist") + require.Equal(t, test.expectedIsNotExist, errors.Is(err, fs.ErrNotExist), "IsNotExist") return } @@ -271,7 +273,7 @@ func TestOpen(t *testing.T) { } if test.expectedIsNotExist { - require.Equal(t, test.expectedIsNotExist, os.IsNotExist(err), "IsNotExist") + require.Equal(t, test.expectedIsNotExist, errors.Is(err, fs.ErrNotExist), "IsNotExist") return } diff --git a/internal/vfs/local/vfs.go b/internal/vfs/local/vfs.go index ea54e8e8..5cca94fd 100644 --- a/internal/vfs/local/vfs.go +++ b/internal/vfs/local/vfs.go @@ -3,6 +3,7 @@ package local import ( "context" "errors" + "io/fs" "os" "path/filepath" @@ -14,21 +15,21 @@ var errNotDirectory = errors.New("path needs to be a directory") type VFS struct{} -func (fs VFS) Root(ctx context.Context, path string) (vfs.Root, error) { +func (localFs VFS) Root(ctx context.Context, path string) (vfs.Root, error) { rootPath, err := filepath.Abs(path) if err != nil { return nil, err } rootPath, err = filepath.EvalSymlinks(rootPath) - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { return nil, &vfs.ErrNotExist{Inner: err} } else if err != nil { return nil, err } fi, err := os.Lstat(rootPath) - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { return nil, &vfs.ErrNotExist{Inner: err} } else if err != nil { return nil, err @@ -41,11 +42,11 @@ func (fs VFS) Root(ctx context.Context, path string) (vfs.Root, error) { return &Root{rootPath: rootPath}, nil } -func (fs *VFS) Name() string { +func (localFs *VFS) Name() string { return "local" } -func (fs *VFS) Reconfigure(*config.Config) error { +func (localFs *VFS) Reconfigure(*config.Config) error { // noop return nil } |