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>2021-02-05 02:43:57 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-02-05 06:47:16 +0300
commit89b0aa23f7ee209038ca4db52357c1673c234d68 (patch)
tree5ac8ec275c7fa24dccf5ae0858136b9feb0d568e /internal/httpfs
parent754454c5ca27893406d5b1d329395bf4f633dc2b (diff)
Make NewFileSystemPath return error
Diffstat (limited to 'internal/httpfs')
-rw-r--r--internal/httpfs/http_fs.go7
-rw-r--r--internal/httpfs/http_fs_test.go8
2 files changed, 9 insertions, 6 deletions
diff --git a/internal/httpfs/http_fs.go b/internal/httpfs/http_fs.go
index ae9aa269..274bca57 100644
--- a/internal/httpfs/http_fs.go
+++ b/internal/httpfs/http_fs.go
@@ -8,7 +8,6 @@ package httpfs
import (
"errors"
- "log"
"net/http"
"os"
"path"
@@ -27,19 +26,19 @@ type fileSystemPaths struct {
// NewFileSystemPath creates a new fileSystemPaths that can be used to register
// a file:// protocol with an http.Transport
-func NewFileSystemPath(allowedPaths []string) http.FileSystem {
+func NewFileSystemPath(allowedPaths []string) (http.FileSystem, error) {
for k, path := range allowedPaths {
var err error
allowedPaths[k], err = filepath.Abs(path)
if err != nil {
- log.Fatal(err)
+ return nil, err
}
}
return &fileSystemPaths{
allowedPaths: allowedPaths,
- }
+ }, nil
}
// Open a file by name if it exists inside the allowedPaths
diff --git a/internal/httpfs/http_fs_test.go b/internal/httpfs/http_fs_test.go
index b8606d9d..3d1092b6 100644
--- a/internal/httpfs/http_fs_test.go
+++ b/internal/httpfs/http_fs_test.go
@@ -62,7 +62,8 @@ func TestFSOpen(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
- p := NewFileSystemPath(test.allowedPaths)
+ p, err := NewFileSystemPath(test.allowedPaths)
+ require.NoError(t, err)
got, err := p.Open(test.fileName)
if test.expectedErrMsg != "" {
@@ -140,7 +141,10 @@ func TestFileSystemPathCanServeHTTP(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
transport := httptransport.NewTransport()
- transport.RegisterProtocol("file", http.NewFileTransport(NewFileSystemPath([]string{test.path})))
+ fs, err := NewFileSystemPath([]string{test.path})
+ require.NoError(t, err)
+
+ transport.RegisterProtocol("file", http.NewFileTransport(fs))
client := &http.Client{
Transport: transport,