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: generator options are parsed into a standalone struct #479

Merged
merged 5 commits into from
Nov 19, 2020

Conversation

software-dov
Copy link
Contributor

Lifts some generator options into a separate structure.
Lifts option parameter parsing logic into a standalone function.
Adds parsing logic for permitted transports.

Also adds unit tests for parsing transport options

Lifts some generator options into a separate structure.
Lifts option parameter parsing logic into a standalone function.
Adds parsing logic for permitted transports.

Also adds unit tests for parsing transport options
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 13, 2020
Comment on lines 536 to 537
if tst.expectErr {
if err == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually very confusing: for some reason, if I lift the err == nil check into the top level expression, it causes spurious test failures for the last test case. Does anyone have any idea as to why this might be?

Copy link
Contributor

Choose a reason for hiding this comment

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

if tst.expectErr && (err == nil) doesn't work? Weird....

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion for debugging this: have the test print ("%v", err). I worry this may hide a simple bug, so we should try to resolve this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I figured it out: the test struct is storing the expected options by value, but ParseOptions is returning by pointer, so the comparison fails because sometimes the returned options is nil, and the expected options cannot be nil. Changing the expected options field to a pointer fixed this.

}

// Default is just grpc
if opts.transports == nil {
opts.transports = []Transport{grpc}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider moving this assignment to line 102 to better group the initialization together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the current placement better communicates the intention that this is a default value if the user doesn't provide a transport= argument.

grpcConfPath string
serviceConfigPath string
sampleOnly bool
transports []Transport
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe Java assumes that either gRPC or REST will be used at a particular time. Does this array imply that callers can pass in both transport types?

Copy link
Contributor

Choose a reason for hiding this comment

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

As per the design doc, the generators will support specifying which transports to generate code for via the transport option, which takes a +-separated list. The eventual default will be grpc+rest. The end developer can then specify which of these generated transports to use when communicating with the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is the implication. Python allows multiple transports to be generated for the surface with runtime choice via dependency injection. This is supported by the spec: see this heading.

internal/gengapic/gengapic.go Outdated Show resolved Hide resolved
grpcConfPath string
serviceConfigPath string
sampleOnly bool
transports []Transport
Copy link
Contributor

Choose a reason for hiding this comment

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

As per the design doc, the generators will support specifying which transports to generate code for via the transport option, which takes a +-separated list. The eventual default will be grpc+rest. The end developer can then specify which of these generated transports to use when communicating with the server.

internal/gengapic/gengapic.go Outdated Show resolved Hide resolved
internal/gengapic/gengapic.go Outdated Show resolved Hide resolved
internal/gengapic/gengapic.go Outdated Show resolved Hide resolved
internal/gengapic/gengapic.go Outdated Show resolved Hide resolved
internal/gengapic/gengapic.go Outdated Show resolved Hide resolved
internal/gengapic/gengapic_test.go Show resolved Hide resolved
internal/gengapic/gengapic_test.go Outdated Show resolved Hide resolved
Comment on lines 536 to 537
if tst.expectErr {
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

if tst.expectErr && (err == nil) doesn't work? Weird....

@software-dov
Copy link
Contributor Author

It's quite inexplicable and caused me at least an hour of frustration before I just gave up.

Add more parsing tests
Comment tweak
Check for unexpected error
Use reflect.DeepEqual instead of handrolled equality checks
Add additional option parsing tests
Copy link
Contributor

@vchudnov-g vchudnov-g left a comment

Choose a reason for hiding this comment

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

Just minor comments, nothing blocking.

(Although we should find out what's behind needing to do a nested if in the test, rather than a conjunction: I fear it hides a simple but potentially important bug.)

internal/gengapic/doc_file.go Outdated Show resolved Hide resolved
internal/gengapic/gengapic_test.go Outdated Show resolved Hide resolved
internal/gengapic/gengapic_test.go Outdated Show resolved Hide resolved
Comment on lines 536 to 537
if tst.expectErr {
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion for debugging this: have the test print ("%v", err). I worry this may hide a simple bug, so we should try to resolve this.

@software-dov software-dov added automerge Summon MOG for automerging and removed automerge Summon MOG for automerging labels Nov 19, 2020
@software-dov software-dov merged commit e25da26 into googleapis:master Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants