-
Couldn't load subscription status.
- Fork 24
adding a method to be able to find requests matching a stub requests #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| const ( | ||
| wiremockAdminURN = "__admin" | ||
| wiremockAdminMappingsURN = "__admin/mappings" | ||
| wiremockAdminFindURN = "__admin/requests/find" | ||
| ) | ||
|
|
||
| // A Client implements requests to the wiremock server | ||
|
|
@@ -107,3 +108,36 @@ func (c *Client) ResetAllScenarios() error { | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| // FindFor finds requests that were made for a StubRule | ||
| func (c *Client) FindRequestsFor(stubRule *StubRule) (map[string]interface{}, error) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we only use the request? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure let me try to refactor that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @walkerus the main reasoning to re-use But if you feel strongly about using request alone then we have to create builders for request just like StubRule we have to create a corresponding function like below Let me know your thoughts around this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh or @walkerus did you mean we could build the but then the users need to know that they must use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the multiple comments or if we could build a new set of builder for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks nice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks @walkerus will try to make changes accordingly |
||
| //to find requests matching a stub, we need only the request portion of the stub | ||
| requestBody, err := json.Marshal(&stubRule.request) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("build stub request error: %s", err.Error()) | ||
| } | ||
|
|
||
| res, err := http.Post(fmt.Sprintf("%s/%s", c.url, wiremockAdminFindURN), "application/json", bytes.NewBuffer(requestBody)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("stub request error: %s", err.Error()) | ||
| } | ||
| defer res.Body.Close() | ||
|
|
||
| bodyBytes, err := ioutil.ReadAll(res.Body) | ||
| if res.StatusCode != http.StatusOK { | ||
| if err != nil { | ||
| return nil, fmt.Errorf("read response error: %s", err.Error()) | ||
| } | ||
|
|
||
| return nil, fmt.Errorf("bad response status: %d, response: %s", res.StatusCode, string(bodyBytes)) | ||
| } | ||
|
|
||
| var response map[string]interface{} | ||
| err = json.Unmarshal(bodyBytes, &response) | ||
|
|
||
| if err != nil { | ||
| return nil, fmt.Errorf("error: %s unmarshalling response: %s", err, response) | ||
| } | ||
|
|
||
| return response, nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the sake of keeping this PR small returning a
map[string]interface{}else we can work on modelling out the expected response as a structThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if we had a structure, at least
requests []map[string]interface{}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will address this