-
Notifications
You must be signed in to change notification settings - Fork 129
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 dynamic servers support #142
Add dynamic servers support #142
Conversation
The fixtures for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @asobrien, thank you for taking the time to add this contribution to the library, we really appreciate it.
There are only a few comments/changes I've requested, mainly to increase consistency across the library, and a comment about update pointers which it would be good to get your opinion on.
With regards to testing, you'll need to run make test
with a valid API token, which will execute the requests against the API and record the results (with the API token redacted) for subsequent runs. Also take a look at the helpers @devkitx added in his version of this in #143, specifically here: /~https://github.com/fastly/go-fastly/pull/143/files#diff-997cff4762ab0b7c60bcaf50fcc36d6e. Hope that helps.
Let us know if you have any further questions.
Thanks for the comments!
I don't have API credentials to access to the baked-in test service. Do maintainers generally run the tests against this service to generate the fixtures? Or, alternatively should a contributor run the test against a Fastly service they have access to and then update the fixtures accordingly? I'm just trying to get a handle on the process around this. The only issue with running the tests against an "unofficial" service, is that the version number recorded in the responses become somewhat arbitrary. Just noting that if this is the recommended route, it may be worth allowing the test service ID to be defined via an env var and adding a recorder Filter that modifies the request/response to keep a consistent service ID.
I've included nearly identical helpers. I don't have a baked in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few clarification questions.
@phamann I've updated this PR to use pointers for optional fields in structs (see It would be possible for all the fields in the input structs to be pointers, but this requires adding new nil pointer checks (e.g., here) that differs from the rest of the library. These value fields are also required in each input struct, so there's no real need from them to be pointers. I did modify the Pool update test case to ensure we can actually set a "zero" value (see here and here) A didn't modify the response structs to use pointer fields either. My thoughts around this are: keeping these as value fields keeps the response consistent with the rest of the library (no need to start dereferencing the reponses). Moreover, as far as I can tell, the Fastly API always populates all the fields in the response which means that we don't need to rely on pointer fields to omit missing fields. I added some helper functions (cf. 2767792) to make it easier for a user to set optional fields. I also generated the fixtures (and replaced the test service id to match that baked into the test client). Let me know what you think about how optional fields are being handled in the Pool and Server resources and if that's what you had in mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looking good to me now.
Next steps:
- I want @philippschulte to have a quick review
- With regards to only using pointers in the optional fields. I'm going to ask the opinion of some others, as whilst I like it, its inconsistent with another private branch we have which is also introducing pointers for update inputs.
Hopefully we can get the above approved and merged in the next couple of days. Once again thank you for all of the work you've put into this and your patience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asobrien thanks for your contribution! Using pointers does solve the zero value issue. However, since the library uses github.com/ajg/form"
to encode the request struct I am wondering if we can avoid pointers. The package does provide a KeepZeros function which the go-fastly
library is already using. I have already tried to fix this issue a couple of months ago but haven't really had the time to dig into it. @phamann I have already asked for an opinion on this issue internally. Please have a look here.
There must be a way to avoid using pointers. If we decide not to find an alternative then I am fine with using pointers and the PR looks good to me. The convenience functions for creating pointer types are useful and the go-github
client provides them too.
Sorrty @philippschulte forgot to push before I got distracted. Should be there now. |
26b41a5
to
eb57d2e
Compare
@asobrien looks good but also please update |
@philippschulte I'm not sure there's a way to get rid of pointers in the input. Looking into the KeepZeros option in Getting rid of the @phamann I looked into the API response (for the Pool resource) in a little more depth, and it seems like the Fastly API doesn't explicitly set unset fields to the default value but rather sets them to
without using pointers in the response struct, it's not possible to tell whether those fields are unset ( |
Fixed in 621dd64 |
@asobrien that is exactly what I found out about the For consistency please use a pointer for |
@philippschulte Will do! I went through the library, and it looks like none of the response structures currently use a In this race, I've got no horse. I just wanted to point it out since it makes a break with the existing response structs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asobrien you're absolutely right! Too many structs 😄. Sorry about the confusion! Thanks again for all the hard work you put into this PR!
No problem. Just to clarify: we should use a If yes, let me revert and clean up the last commit and then we should be good to go. |
@asobrien yes please revert it! My fault, sorry 😭 |
@philippschulte fixed in 0f6b649 |
This adds support for the API's dynamic servers to the client via the
Pool
andServer
resources.