Skip to content
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

Add httpError to Expectation #10

Open
richardfuchs opened this issue Feb 16, 2022 · 0 comments
Open

Add httpError to Expectation #10

richardfuchs opened this issue Feb 16, 2022 · 0 comments

Comments

@richardfuchs
Copy link

Is this repository still under development?
Are PRs welcome?

It would be nice to have "httpError" in this client.

Currently the following Expectation is implemented:

type Expectation struct {
	Request  RequestMatcher `json:"httpRequest,omitempty"`
	Response Response       `json:"httpResponse,omitempty"`
	Priority int32          `json:"priority,omitempty"`
}

but the MockServer also supports "httpError" link - the json for this would look somehow like this:

{
    "httpRequest": {
        "path": "..."
    },
    "httpError" : {
        "dropConnection" : true
    }
}

How can the "httpError" be added to the Expectation?

Sadly the solutions seems to be breaking:
The MockServer only accepts "httpResponse" or "httpError" in the Expectation
This means, that "httpResponse" or "httpError" must be omitted in the json

There is already a "omitempty"-flag on Response - however, this cannot be used properly.
The reason is, that the "omitempty" does not work on structs (like Response) - as structs do not have an empty value in go.
This problem could be solved using a pointer - as a pointer can be nil.

This solution could look like this

type Expectation struct {
	Request  RequestMatcher `json:"httpRequest,omitempty"`
	Response *Response      `json:"httpResponse,omitempty"`
	Error    *Error         `json:"httpError,omitempty"`
	Priority int32          `json:"priority,omitempty"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant