@@ -163,6 +163,27 @@ components:
163163 logResponseBody (rr )
164164 fmt .Println ()
165165
166+ // ================================================================================
167+ fmt .Println ("# A request with an invalid HTTP method, to a valid path, is rejected with an HTTP 405 Method Not Allowed" )
168+ body = map [string ]string {
169+ "invalid" : "not expected" ,
170+ }
171+
172+ data , err = json .Marshal (body )
173+ must (err )
174+
175+ req , err = http .NewRequest (http .MethodPatch , "/resource" , bytes .NewReader (data ))
176+ must (err )
177+ req .Header .Set ("Content-Type" , "application/json" )
178+
179+ rr = httptest .NewRecorder ()
180+
181+ server .ServeHTTP (rr , req )
182+
183+ fmt .Printf ("Received an HTTP %d response. Expected HTTP 405\n " , rr .Code )
184+ logResponseBody (rr )
185+ fmt .Println ()
186+
166187 // ================================================================================
167188 fmt .Println ("# A request that is well-formed is passed through to the Handler" )
168189 body = map [string ]string {
@@ -207,6 +228,10 @@ components:
207228 // Received an HTTP 400 response. Expected HTTP 400
208229 // Response body: request body has an error: doesn't match schema: property "invalid" is unsupported
209230 //
231+ // # A request with an invalid HTTP method, to a valid path, is rejected with an HTTP 405 Method Not Allowed
232+ // Received an HTTP 405 response. Expected HTTP 405
233+ // Response body: method not allowed
234+ //
210235 // # A request that is well-formed is passed through to the Handler
211236 // POST /resource was called
212237 // Received an HTTP 204 response. Expected HTTP 204
0 commit comments