Skip to content

Commit 88b8a17

Browse files
authored
testserver: log error on "method not allowed" same as "not found" (#2933)
This extends the diagnostics we have for 404 to 405 errors. Today, if you call testserver and there is no path registered, you'll get 404 and a nice error message suggesting which setting to add to config. If you call some path that is present but does not have handler for the required method, you'll get 405 silently and without errors. The deploy-artifact-path-type test had to be fixed since it relied on undefined handler before and now it fails.
1 parent b70cea9 commit 88b8a17

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

acceptance/bundle/telemetry/deploy-artifact-path-type/test.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ Response.Body = '''
1313
[[Server]]
1414
Pattern = "PUT /api/2.0/fs/directories/Volumes/main/a/b/c/.internal"
1515
Response.StatusCode = 200
16+
17+
[[Server]]
18+
Pattern = "GET /api/2.0/fs/directories/Volumes/main/a/b/c/.internal"
19+
Response.Body = '{}'
20+
# I'm adding 405 because that's what this test originally do. It's somewhat
21+
# surprising though that CLI can receive 405 and that does not result in error anywhere.
22+
Response.StatusCode = 405

libs/testserver/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func New(t testutil.TestingT) *Server {
190190
}
191191

192192
// Set up the not found handler as fallback
193-
router.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
193+
notFoundFunc := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
194194
pattern := r.Method + " " + r.URL.Path
195195
bodyBytes, err := io.ReadAll(r.Body)
196196
var body string
@@ -227,6 +227,8 @@ Response.Body = '<response body here>'
227227
t.Errorf("Response write error: %s", err)
228228
}
229229
})
230+
router.NotFoundHandler = notFoundFunc
231+
router.MethodNotAllowedHandler = notFoundFunc
230232

231233
return s
232234
}

0 commit comments

Comments
 (0)