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

Fix regression caused by resolveOptions #18

Merged
merged 6 commits into from
Jan 27, 2022
Merged

Fix regression caused by resolveOptions #18

merged 6 commits into from
Jan 27, 2022

Conversation

chelnak
Copy link
Contributor

@chelnak chelnak commented Jan 26, 2022

If opts was nil, resolveOptions would only update the local copy of opts. The pointer was never being updated and was therefore nil when passed to the New*Client methods.

Closes #17

Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

Thanks for catching this and thanks for the fix. I would like to see this solved in a slightly different manner though. To me it doesn't make sense to be passing in nil to resolveOptions since it works by modifying the passed in options. Rather we should solve this by fixing the callers to make sure they are passing in valid api.ClientOptions. Does that make sense? Additionally, if you are feeling up for it it would be great to add a test or two for resolveOptions. I should have added some when I created the function but overlooked it.

@chelnak
Copy link
Contributor Author

chelnak commented Jan 26, 2022

Hey, that sounds good. I'll push some changes + new tests this afternoon.

Cheers,
Craig

@chelnak
Copy link
Contributor Author

chelnak commented Jan 26, 2022

@samcoe I was wondering if it was still desirable to allow the consumer to pass nil for ClientOptions.

e.g:
gh.HTTPClient(nil)

Then it would be up to the client methods to pass a valid api. ClientOptions.

func HTTPClient(opts *api.ClientOptions) (*http.Client, error) {
	if opts == nil {
		opts = &api.ClientOptions{}
	}
.....

The other option would be to ask he consumer to provide an empty api.ClientOptions.

@samcoe
Copy link
Contributor

samcoe commented Jan 26, 2022

My thought would be that it should be up to the client methods to pass a valid api.ClientOptions to resolveOptions even if they received nil, so exactly as you proposed 👍

@chelnak
Copy link
Contributor Author

chelnak commented Jan 26, 2022

I've pushed an implementation. I couldn't decide whether to include a nil check in resolveOptions so I left it out. I don't think it will ever be an issue to the consumer given that the client methods now handle the opts. Saying that though.. I'm more than happy to add something in if it's preferable!

Currently pondering on tests... it feels tricky because of config.Load() and mocking it would mean exporting some more things from the config package..

or we could pass in config to resolveOptions e.g

func resolveOptions(clientOptions **api.ClientOptions, cfg config.Config) error {
...

however I'm fairly fresh with Go so I might be overlooking something obvious.

If opts was nil, resolveOptions would only update the local copy of
opts. The pointer was never being updated and was therefore nil when
passed to the New*Client methods.
We shouldn't allow passing nil to resolveOptions so this commit
moves the responsibility up into the client methods.
Passing in config.Config as a dependency enables us to provide
mocked config when testing.
Exporting FromString means that we can use it in external tests
when mocking configuraton.
This commit adds test for the resolveOptions implementation. It also
consumes the exported FromString function from the config
package to give us a mocked config.Config instance.
@chelnak
Copy link
Contributor Author

chelnak commented Jan 26, 2022

Added some tests and rebased 👍

Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

Great work @chelnak, thanks for adding tests. Code looks good. I pushed one small change removing the double pointer argument that was remnants from the first approach and was unnecessary now.

@samcoe samcoe merged commit c41a127 into cli:trunk Jan 27, 2022
@chelnak
Copy link
Contributor Author

chelnak commented Jan 27, 2022

@samcoe appreciated 😄

@chelnak chelnak deleted the fix_resolve_options branch January 27, 2022 09:16
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.

resolveOptions not updating ClientOptions
2 participants