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

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2022-02-24 00:22:52 +0300
committerJaime Martinez <jmartinez@gitlab.com>2022-02-24 00:22:52 +0300
commit2bee7f9d4e4e3e87b3e5c682061c9b1db3218ea1 (patch)
tree693c51657cfa9dd29b0308202a3b9dbb3a0644e8 /internal/httpfs
parent3ea4ea135e0d52b9717e2fd703f8e5136b95b868 (diff)
parentb7d42ef5004b59d1885dcd332eaab64805d2578c (diff)
Merge branch 'refactor/test-erroris' into 'master'
test: migrate to assertions using modern error checking See merge request gitlab-org/gitlab-pages!684
Diffstat (limited to 'internal/httpfs')
-rw-r--r--internal/httpfs/http_fs_test.go32
1 files changed, 16 insertions, 16 deletions
diff --git a/internal/httpfs/http_fs_test.go b/internal/httpfs/http_fs_test.go
index 25003726..10a1ef7b 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"
@@ -22,7 +23,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"},
@@ -35,19 +36,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"},
@@ -55,9 +56,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,
},
}
@@ -67,9 +68,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
}