From 2d1c2725e451245409f0f7a23c404d6242c07b9d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 15 Jan 2023 16:52:39 +0000 Subject: [PATCH] webdav: fix tests after go1.20 upgrade Before this change we were sending webdav requests to the go http FileServer. In go1.20 these (rightly) started returning errors which caused the tests to fail. The test has been changed to properly mock up an About query and response so an end to end test of adding headers is possible. --- backend/webdav/webdav_internal_test.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/webdav/webdav_internal_test.go b/backend/webdav/webdav_internal_test.go index 8789e8413..20dee468b 100644 --- a/backend/webdav/webdav_internal_test.go +++ b/backend/webdav/webdav_internal_test.go @@ -24,15 +24,23 @@ var ( // prepareServer the test server and return a function to tidy it up afterwards // with each request the headers option tests are executed func prepareServer(t *testing.T) (configmap.Simple, func()) { - // file server - fileServer := http.FileServer(http.Dir("")) - - // test the headers are there then pass on to fileServer + // test the headers are there send send a dummy response to About handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { what := fmt.Sprintf("%s %s: Header ", r.Method, r.URL.Path) assert.Equal(t, headers[1], r.Header.Get(headers[0]), what+headers[0]) assert.Equal(t, headers[3], r.Header.Get(headers[2]), what+headers[2]) - fileServer.ServeHTTP(w, r) + fmt.Fprintf(w, ` + + /remote.php/webdav/ + + + -3 + 376461895 + + HTTP/1.1 200 OK + + +`) }) // Make the test server @@ -68,7 +76,7 @@ func TestHeaders(t *testing.T) { f, tidy := prepare(t) defer tidy() - // any request will do + // send an About response since that is all the dummy server can return _, err := f.Features().About(context.Background()) require.NoError(t, err) }