improve test cases coverage

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2023-04-08 10:01:48 +02:00
parent 184b99d500
commit f03f1b0156
11 changed files with 192 additions and 96 deletions

View File

@@ -52,12 +52,19 @@ const (
statvfsPath = "/api/v1/statvfs"
)
// HTTPFsCallbacks defines additional callbacks to customize the HTTPfs responses
type HTTPFsCallbacks struct {
Readdir func(string) []os.FileInfo
}
// StartTestHTTPFs starts a test HTTP service that implements httpfs
// and listens on the specified port
func StartTestHTTPFs(port int) error {
func StartTestHTTPFs(port int, callbacks *HTTPFsCallbacks) error {
fs := httpFsImpl{
port: port,
port: port,
callbacks: callbacks,
}
return fs.Run()
}
@@ -75,6 +82,7 @@ type httpFsImpl struct {
basePath string
port int
unixSocketPath string
callbacks *HTTPFsCallbacks
}
type apiResponse struct {
@@ -358,6 +366,11 @@ func (fs *httpFsImpl) readdir(w http.ResponseWriter, r *http.Request) {
for _, fi := range list {
result = append(result, getStatFromInfo(fi))
}
if fs.callbacks != nil && fs.callbacks.Readdir != nil {
for _, fi := range fs.callbacks.Readdir(name) {
result = append(result, getStatFromInfo(fi))
}
}
render.JSON(w, r, result)
}