sendgrid-go
sendgrid-go copied to clipboard
Cannot mock API by X-Mock header using Prism Windows
Issue Summary
I'm working on struct-ing
out a bit more of the SendGrid API for a project, and am diving into testing the first few endpoints I've been building out (in hopes to provide some PR's in the future!)
However, when running tests using prism and the provided SendGrid OAI spec (see below), I cannot mock anything else besides the "default" response code an endpoint provides. The X-Mock header doesn't seem to affect output from prism.
Steps to Reproduce
OS: Windows 10
Using: prism.exe (x64)
Version: 2.0.9
command: prism.exe mock -d -s https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json
The above utilizes an X-Mock
header to specify the response code to mock back. However, even when mocking endpoints like POST /alerts
(below) without a request body, and with X-Mock
header set to 400
, I still get a 201 response code and a 201 response body.
Example code:
// assuming prism is running, mocking the API w/ the above command
// and running on the default port of 4010:
req, _:= http.NewRequest("POST", "localhost:4010/v3/alerts", nil)
req.Header.Set("Authorization", "Bearer SENDGRID_APIKEY")
req.Header.Set("Accept", "application/json")
req.Header.Set("X-Mock", "400")
response, err := http.DefaultClient.Do(req)
// here, response.StatusCode is 201, and the response body shows the
// mocked 201 response object, and err is nil
response status code: 201
response body:
{"created_at":1451520930,"email_to":"[email protected]","frequency":"daily","id":48,"type":"stats_notification","updated_at":1451520930}
I have tried altering the oai-stoplight.json
beforeScript
functions but to no avail...
Technical details:
- sendgrid-go Version: master (latest commit: 588320a743278a1824a54d232a7e9f36df6f6c99)
- Go Version: 1.10.1 windows/amd64
Thanks for reporting this @chrisprijic,
I've added this to our backlog for review. In the mean time, perhaps the prism documentation or the StopLight team might have some insight.
With Best Regards,
Elmer
Answer from: stoplightio/prism#147
Looks like the new version of prism uses __code=400
(or any status code) as a query param to allow specified output. They'll get back to me about where this documentation is, or where you can have a reference for this.
As for this repo and my issue, I'll leave it up to you on how to handle this -- if prism's version needs to be explicitly stated or if you want to update to the newest prism way of mocking a particular response.
If you want to update, I'd be happy to provide a PR for it. I'll check out the contributing docs tomorrow morning regardless.
@thinkingserious did you guys update to the new version of Prism? If you did, let's make some time next week to migrate you over properly. Let me know.
Hi @pytlesk4,
We are now running a pre-loaded Prism in a Docker container, like so. I would love to learn how to get upgraded to the latest version.
How about Tuesday 11am PST?
Thanks!
With Best Regards,
Elmer
Hello @chrisprijic,
We use this older version of Prism (here are the docs) in this manner.
The functionality you want is available in the newest version of Prism. If you would like to help us with upgrading to the newest version, a PR would be most welcome :) Note that we have been moving towards setting up Prism within a Docker container, like so.
With Best Regards,
Elmer
P.S. Thanks to @pytlesk4 for helping out!
Here is an example of it with golang: https://github.com/pytlesk4/sendgrid-go/tree/prism-2.0
This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.