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

Mockable interfaces #216

Open
hajapy opened this issue Feb 6, 2025 · 2 comments
Open

Mockable interfaces #216

hajapy opened this issue Feb 6, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@hajapy
Copy link

hajapy commented Feb 6, 2025

Hi there, thanks for the library. Looking forward to beta.

One thing I noticed with the current version is it is difficult to mock the api using mockgen. The RequestOption accepted by the methods I'd like to mock makes use of internal types: https://github.com/openai/openai-go/blob/main/option/requestoption.go#L23

Would it be possible to make sure these interfaces are fully public so we can mock them out in tests?

Thanks!

@jacobzim-stl jacobzim-stl added the enhancement New feature or request label Feb 7, 2025
@jacobzim-stl
Copy link
Collaborator

I think mocking would be a great feature to support, so we'll discuss it internally.

My only hesitation would be about breaking changes. We'll need the freedom to make changes to the structure of the RequestConfig type. But we could replace RequestConfig with an interface, like so

type RequestOption = func(*requestconfig.RequestConfig) error
type RequestOption = func(option.RequestConfigurable) error

type RequestConfigurable interface {
	SetTimeout(time.Duration)
	// ...
}

However, it could break your mocking program every time we add an option. Then again, perhaps that's better than not being able to mock at all.

@sfllaw
Copy link

sfllaw commented Feb 14, 2025

Instead of making everything mockable, maybe we could be inspired by net/http/httptest.Server.Client? This returns an *http.Client which is wired up to a test server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants