-
Notifications
You must be signed in to change notification settings - Fork 51
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
Changes from 1 commit
bdf669f
e025034
b6cda62
d2d2391
f10420b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,3 +499,46 @@ func Test_isLRO(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func Test_transportParse(t *testing.T) { | ||
software-dov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _, tst := range []struct { | ||
param string | ||
expectedOpts options | ||
expectErr bool | ||
}{ | ||
{ | ||
software-dov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
param: "transport=grpc,go-gapic-package=path;pkg", | ||
expectedOpts: options{ | ||
transports: []Transport{grpc}, | ||
pkgPath: "path", | ||
pkgName: "pkg", | ||
outDir: "path", | ||
}, | ||
expectErr: false, | ||
}, | ||
{ | ||
param: "transport=rest+grpc,go-gapic-package=path;pkg", | ||
expectedOpts: options{ | ||
transports: []Transport{rest, grpc}, | ||
pkgPath: "path", | ||
pkgName: "pkg", | ||
outDir: "path", | ||
}, | ||
expectErr: false, | ||
}, | ||
{ | ||
param: "transport=tcp,go-gapic-package=path;pkg", | ||
expectedOpts: options{}, | ||
expectErr: true, | ||
}, | ||
} { | ||
opts, err := ParseOptions(&tst.param) | ||
if tst.expectErr { | ||
software-dov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually very confusing: for some reason, if I lift the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion for debugging this: have the test print There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
t.Errorf("ParseOptions(%s) expected error", tst.param) | ||
} | ||
} else if !OptsEqual(opts, &tst.expectedOpts) { | ||
t.Errorf("ParseOptions(%s) = %v, want %v", tst.param, opts, tst.expectedOpts) | ||
} | ||
} | ||
} |
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.
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?
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.
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 begrpc+rest
. The end developer can then specify which of these generated transports to use when communicating with the server.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.
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.