mirror of https://github.com/databricks/cli.git
acc: Fix RecordRequests to support requests without body (#2333)
## Changes Do not paste request body into output if it's not a valid JSON. ## Tests While working on #2334 I found that if I try to record a test that calls /api/2.0/preview/scim/v2/Me which has no request body, it crashes.
This commit is contained in:
parent
8d849fe868
commit
878fa80322
|
@ -34,7 +34,8 @@ type Request struct {
|
|||
Headers http.Header `json:"headers,omitempty"`
|
||||
Method string `json:"method"`
|
||||
Path string `json:"path"`
|
||||
Body any `json:"body"`
|
||||
Body any `json:"body,omitempty"`
|
||||
RawBody string `json:"raw_body,omitempty"`
|
||||
}
|
||||
|
||||
func New(t testutil.TestingT) *Server {
|
||||
|
@ -119,13 +120,19 @@ func (s *Server) Handle(pattern string, handler HandlerFunc) {
|
|||
}
|
||||
}
|
||||
|
||||
s.Requests = append(s.Requests, Request{
|
||||
req := Request{
|
||||
Headers: headers,
|
||||
Method: r.Method,
|
||||
Path: r.URL.Path,
|
||||
Body: json.RawMessage(body),
|
||||
})
|
||||
}
|
||||
|
||||
if json.Valid(body) {
|
||||
req.Body = json.RawMessage(body)
|
||||
} else {
|
||||
req.RawBody = string(body)
|
||||
}
|
||||
|
||||
s.Requests = append(s.Requests, req)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
|
Loading…
Reference in New Issue