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

feat(client): allow tests to assign a fake requester #319

Closed
wants to merge 1 commit into from

Conversation

flotter
Copy link
Contributor

@flotter flotter commented Oct 18, 2023

The client test suite used by all client command tests fakes the doer today, which is a private internal Requester implementation detail. Derived projects using the client Requester for extended commands needs to fake the Requester interface.

This PR adds a client method SetRequester(rw Requester) to allow test code to fake the requester. This has to be public to allow an external package to fake this.

Pending work remain to properly refactor the existing client test code to Fake the Requester instead of the doer. This is captured as an outstanding issue here: #315

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we spent all those calls to agree that we'd have no external requesters for now, and the very first trivial PR allows setting an external Requester, with no mention of these conversations? :)

@flotter
Copy link
Contributor Author

flotter commented Oct 18, 2023

I will take a slightly different approach as used elsewhere in Pebble:

func (s *BasePebbleSuite) RedirectClientToTestServer(handler func(http.ResponseWriter, *http.Request)) {
        server := httptest.NewServer(http.HandlerFunc(handler))
        s.BaseTest.AddCleanup(func() { server.Close() })
        cli.ClientConfig.BaseURL = server.URL
        s.BaseTest.AddCleanup(func() { cli.ClientConfig.BaseURL = "" })
}

@flotter flotter closed this Oct 18, 2023
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

Successfully merging this pull request may close these issues.

2 participants