Support mocking external services
- Dominant language
- Go
- Stars
- 300
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Description
Gost creates a custom `http.Client` to support calling an http handler directly bypassing the TCP/TLS layer.
It would be useful to extend, or create an alternate version, that can be configured with different hostnames mapping to different HTTP handlers.
A useful use case is replacing an identity provider, so the test outcome isn't dependent on an actual IDP running, as well as the overhead of communication with an external service. This also removes the need for test accounts in an external IDP.
An example: The web site has the following link:
```html
```
The IDL should obviously be configurable in the app, as well as it's own root url, when it generates links back to itself. For testing HTTP should be fine, but whether or not the links are actually HTTP or HTTPS probably shouldn't matter when the handler just calls a `ServeHTTP` function anyway.
An http client should support multiple hosts (hostname and port), and possibly allow unmatched hostnames to fallback to the default HTTP client, sending an outgoing request, which could be configured like this:
```go
c := TestHttpClient{ // Find a better name perhaps?
AllowExternalRequests: true,
}
c.HostHandler("my-app.example.com", CreateMyAppRootHandler())
c.HostHandler("idp.example.com", CreateMockedIdentityProvider())
// or c.HostHandler("idp.example.com:8000", CreateMockedIdentityProvider())
b := browser.Browser{
client: c.Client(),
}
win, _ := b.Open("http://my-app.example.com/")
win.Document().FindElementById("login-link").Click()
// go through login flow, and get back to own browser
```
Contributor guide
Research direction
Start by examining the custom http.Client path and how requests reach ServeHTTP handlers. Define how HostHandler maps hostnames and ports, how the default client handles unmatched hosts, and how Client integrates with browser.Browser. The work is done when the example can route application and identity-provider requests through separate handlers without requiring external services.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- testing, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100