diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-02-03 22:39:46 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-02-03 22:52:19 +0300 |
commit | b7d42ef5004b59d1885dcd332eaab64805d2578c (patch) | |
tree | a7167159ae9808b82bc88c114ffd7afd9773ecf3 /internal/httpfs/http_fs_test.go | |
parent | f2fd9a8e0b4778991adf054ef8f3a7244200a60d (diff) |
test: migrate to assertions using modern error checking
Diffstat (limited to 'internal/httpfs/http_fs_test.go')
-rw-r--r-- | internal/httpfs/http_fs_test.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/internal/httpfs/http_fs_test.go b/internal/httpfs/http_fs_test.go index 991c6017..01101984 100644 --- a/internal/httpfs/http_fs_test.go +++ b/internal/httpfs/http_fs_test.go @@ -2,6 +2,7 @@ package httpfs import ( "io" + "io/fs" "net/http" "net/url" "os" @@ -21,7 +22,7 @@ func TestFSOpen(t *testing.T) { allowedPaths []string fileName string expectedContent string - expectedErrMsg string + expectedErr error }{ "file_allowed_in_file_path": { allowedPaths: []string{wd + "/testdata"}, @@ -34,19 +35,19 @@ func TestFSOpen(t *testing.T) { expectedContent: "subdir/file2.txt\n", }, "file_not_in_allowed_path": { - allowedPaths: []string{wd + "/testdata/subdir"}, - fileName: wd + "/testdata/file1.txt", - expectedErrMsg: os.ErrPermission.Error(), + allowedPaths: []string{wd + "/testdata/subdir"}, + fileName: wd + "/testdata/file1.txt", + expectedErr: fs.ErrPermission, }, "file_does_not_exist": { - allowedPaths: []string{wd + "/testdata"}, - fileName: wd + "/testdata/unknown.txt", - expectedErrMsg: "no such file or directory", + allowedPaths: []string{wd + "/testdata"}, + fileName: wd + "/testdata/unknown.txt", + expectedErr: fs.ErrNotExist, }, "relative_path_not_allowed": { - allowedPaths: []string{"testdata"}, - fileName: "testdata/file1.txt", - expectedErrMsg: os.ErrPermission.Error(), + allowedPaths: []string{"testdata"}, + fileName: "testdata/file1.txt", + expectedErr: fs.ErrPermission, }, "dot_dot_in_file_resolved": { allowedPaths: []string{wd + "/testdata"}, @@ -54,9 +55,9 @@ func TestFSOpen(t *testing.T) { expectedContent: "file1.txt\n", }, "dot_dot_in_file_resolved_not_allowed": { - allowedPaths: []string{wd + "/testdata/subdir"}, - fileName: wd + "/../httpfs/testdata/file1.txt", - expectedErrMsg: os.ErrPermission.Error(), + allowedPaths: []string{wd + "/testdata/subdir"}, + fileName: wd + "/../httpfs/testdata/file1.txt", + expectedErr: fs.ErrPermission, }, } @@ -66,9 +67,8 @@ func TestFSOpen(t *testing.T) { require.NoError(t, err) got, err := p.Open(test.fileName) - if test.expectedErrMsg != "" { - require.Error(t, err) - require.Contains(t, err.Error(), test.expectedErrMsg) + if test.expectedErr != nil { + require.ErrorIs(t, err, test.expectedErr) return } |