-
Notifications
You must be signed in to change notification settings - Fork 26
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
impl(generator/protobuf): optional and repeated fields #74
impl(generator/protobuf): optional and repeated fields #74
Conversation
128e8dc
to
e37b936
Compare
Support repeated and optional fields. Maybe the largest contribution here is to introduce a way to unit test the Protobuf translator.
generator/internal/genclient/translator/protobuf/protobuf_test.go
Outdated
Show resolved
Hide resolved
generator/internal/genclient/translator/protobuf/protobuf_test.go
Outdated
Show resolved
Hide resolved
generator/internal/genclient/translator/protobuf/protobuf_test.go
Outdated
Show resolved
Hide resolved
|
||
api := translator.makeAPI() | ||
|
||
if message := api.State.MessageByID[".test.Fake"]; message != nil { |
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 think that this will panic if message is nil. Instead do:
message, ok := api.StateMessageById[".test.Fake"]
if !ok {
t.Fatalf("Cannot find message %s in API State", "Fake")
}
checkMessage(...)
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.
Done.
Name: "Fake", | ||
Documentation: "A test message.", | ||
Fields: []*genclient.Field{ | ||
{Repeated: true, Documentation: "A repeated field tag = 1", Name: "f_double", JSONName: "fDouble", ID: ".test.Fake.f_double", Typez: genclient.DOUBLE_TYPE}, |
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.
ditto re indent
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.
Done.
generator/internal/genclient/translator/protobuf/protobuf_test.go
Outdated
Show resolved
Hide resolved
e37b936
to
06902d4
Compare
|
||
func TestScalar(t *testing.T) { | ||
contents := ` | ||
syntax = "proto3"; |
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.
nit: I think this would be easier to read if we made this its own file in a testdata
folder
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.
Maybe, but it would be harder to know what files go with what test. I find it easier to change the tests if the inputs, test code, and expected outputs are all in one place.
I will defer to you an Julie on Golang stuff in any case.
}) | ||
} | ||
|
||
func newCodeGeneratorRequest(name, contents string, t *testing.T) *pluginpb.CodeGeneratorRequest { |
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.
nit: generally I would expect to see t as the first parameter to the test. Also to improve test reporting should there be a failure consider marking this function as a helper function. You would call t.Helper
at the start of the function.
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.
Done.
Support repeated and optional fields. Maybe the largest contribution here is to
introduce a way to unit test the Protobuf translator.