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

Generate custom tags for oneof fileds (#611) #612

Merged
merged 1 commit into from
Sep 8, 2019
Merged

Generate custom tags for oneof fileds (#611) #612

merged 1 commit into from
Sep 8, 2019

Conversation

krhubert
Copy link
Contributor

No description provided.

@krhubert krhubert changed the title Generate json and custom tags for oneof fileds (#611) Generate custom tags for oneof fileds (#611) Sep 2, 2019
@jmarais
Copy link
Contributor

jmarais commented Sep 5, 2019

Hi. Thanks for the pullrequest. It seems like the oneof tags were collateral damage of a large generator refactor.

@jmarais
Copy link
Contributor

jmarais commented Sep 5, 2019

Can we please also get a test for this issue?

I think it would make sense to add a simple oneof message under"
test/tags/tags.proto
And then use a xml custom tag with a marshal/unmarshal like the other tests to validate that the correct customtag has been generated.

@krhubert
Copy link
Contributor Author

krhubert commented Sep 5, 2019

@jmarais I think it's ready to review.

In tests I skip the Marshal for json and XML because I will have to implement custom marshaler for oneof interface.

Copy link
Contributor

@jmarais jmarais left a comment

Choose a reason for hiding this comment

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

The generator change looks good.

Do you have a suggestion for a test in order to validate a custom moretags field?
I will feel more confident if we can get a test in order to validate this behavior in order to prevent it reoccurring in the future.

With regards to the travis job. Remember to make in the root of the project in order to regenerate all the protos with the generator change.

@@ -86,29 +90,34 @@ func TestJson(t *testing.T) {
if msg2.MyField2 != msg1.MyField2 {
t.Fatalf("proto field2 %s != %s", msg2.MyField2, msg1.MyField2)
}
if msg2.MyField3 != msg2.MyField3 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think this test works. We will have to check field3 after the first Outside unmarshal above. If I add that check the intermittently fail because it is just dropping MyField3. Currently, this last check doesn't catch anything becuase with the second marshal/unmarshal MyField3 always stays empty.

msg2 := &Outside{
Inside: &Inside{
Field1: &field1,
},
Field2: &field2,
Filed: &Outside_Field3{
Field3: field3,
},
}
if msg1.GetField1() != msg2.GetField1() {
t.Fatalf("field1 expected %s got %s", msg2.GetField1(), msg1.GetField1())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Field3Value was added to the starting data, and added to msg2, however we are not validating that field3 match the expected value after the unmarshal.
We would need an additional:

	if msg1.GetField3() != msg2.GetField3() {
		t.Fatalf("field3 expected %s got %s", msg2.GetField3(), msg1.GetField3())
	}

check. If I add this check the test does fail.

@krhubert
Copy link
Contributor Author

krhubert commented Sep 5, 2019

About comments for tests look on the answer below.

Do you have a suggestion for a test in order to validate a custom moretags field?

What do you think about using reflection and get a tag, instead of marshal/unmarshal with json/xml?

With regards to the travis job. Remember to make in the root of the project in order to regenerate all the protos with the generator change.

Yes, I miss that. Also I found something interesting - in tags.proto syntax is set to proto2, but the generated test.pb.go declares GoGoProtoPackageIsVersion3 - why it so?

@jmarais
Copy link
Contributor

jmarais commented Sep 5, 2019

What do you think about using reflection and get a tag, instead of marshal/unmarshal with json/xml?

That is a good suggestion. I think that will make for a nice test.

but the generated test.pb.go declares GoGoProtoPackageIsVersion3 - why it so?

That is just a constant generated by the protoc-gen-gogo plugin when generating the *.pb.go files. The constant's definition is in proto package. It gives us a compile time check between the generated code and the current proto package.

- add test case in tags.proto file
@krhubert
Copy link
Contributor Author

krhubert commented Sep 6, 2019

@jmarais I regenerated proto definitions plus replace the test to make use of reflection.

Copy link
Contributor

@jmarais jmarais left a comment

Choose a reason for hiding this comment

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

Looks good.

@jmarais jmarais merged commit 3f2ed6d into gogo:master Sep 8, 2019
timpalpant pushed a commit to timpalpant/protobuf that referenced this pull request Oct 6, 2019
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.

2 participants