mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-08 07:10:56 +03:00
improve test cases coverage
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user