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

all: replace all uses of golang/protobuf/proto #1358

Merged
merged 1 commit into from
May 19, 2020
Merged

Conversation

johanbrandhorst
Copy link
Collaborator

We have to keep using the old ptypes, descriptor
and plugin packages since rules_go forces us to use them.
Eventually rules_go should move to the new API and we can
purge the use of the golang/protobuf package altogether.

@codecov-io
Copy link

codecov-io commented May 17, 2020

Codecov Report

Merging #1358 into v2 will increase coverage by 0.19%.
The diff coverage is 61.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##               v2    #1358      +/-   ##
==========================================
+ Coverage   53.95%   54.14%   +0.19%     
==========================================
  Files          40       40              
  Lines        4302     4316      +14     
==========================================
+ Hits         2321     2337      +16     
+ Misses       1725     1724       -1     
+ Partials      256      255       -1     
Impacted Files Coverage Δ
examples/internal/server/a_bit_of_everything.go 0.00% <0.00%> (ø)
internal/codegenerator/parse_req.go 100.00% <ø> (ø)
internal/descriptor/registry.go 58.71% <ø> (ø)
...-gen-grpc-gateway/internal/gengateway/generator.go 37.86% <0.00%> (ø)
protoc-gen-swagger/main.go 26.12% <ø> (ø)
runtime/marshal_httpbodyproto.go 76.92% <0.00%> (ø)
runtime/marshal_proto.go 55.55% <ø> (ø)
runtime/marshaler_registry.go 85.71% <ø> (ø)
runtime/mux.go 61.06% <ø> (ø)
runtime/proto2_convert.go 0.00% <ø> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6cd4e05...2f16422. Read the comment docs.

Comment on lines +228 to +230
// TODO(johanbrandhorst): Use new conversion later when possible
// any := protodesc.ToFileDescriptorProto((&anypb.Any{}).ProtoReflect().Descriptor().ParentFile())
// status := protodesc.ToFileDescriptorProto((&statuspb.Status{}).ProtoReflect().Descriptor().ParentFile())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not possible yet because rules_go locks us into the older ptypes

{
endpoint: fmt.Sprintf("http://localhost:%d/responsestrings/foo", port),
expectedCode: http.StatusOK,
expectedBody: `["hello","foo"]`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tests that relied on exact JSON formatting have had to be rewritten to marshal to types before comparing (see golang/protobuf#1121)

requestContent io.Reader
}{
{
name: "get url query values",
httpMethod: "GET",
contentType: "application/json",
apiURL: fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/params/get/foo?double_value=%v&bool_value=%v", port, 1234.56, true),
wantContent: `{"single_nested":{"name":"foo"},"double_value":1234.56,"bool_value":true}`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

More converted tests

@@ -1051,11 +1053,36 @@ func TestApplyTemplateExtensions(t *testing.T) {
if want, is, name := "2.0", result.Swagger, "Swagger"; !reflect.DeepEqual(is, want) {
t.Errorf("applyTemplate(%#v).%s = %s want to be %s", file, name, is, want)
}
if want, is, name := []extension{
{key: "x-bar", value: json.RawMessage("[\n \"baz\"\n ]")},
{key: "x-foo", value: json.RawMessage("\"bar\"")},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

More JSON tests replaced

Comment on lines +51 to +56
switch {
case err != nil && !spec.wanterr:
t.Errorf("got unexpected error\n%#v", err)
case err == nil && spec.wanterr:
t.Errorf("did not error when expecte")
case !proto.Equal(ts, spec.output):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced direct error comparison with boolean test (we don't care what the error looks like).

continue
}

if got, want := body["message"].(string), spec.msg; !strings.Contains(got, want) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replace this nonsense with explicit status unmarshalling

rv.Set(reflect.Append(rv, bv.Elem()))
}
return nil
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to add this to support marshalling slices of proto messages, not sure how this worked before.

}{
{
input: &examplepb.ResponseBodyOut{
Response: &examplepb.ResponseBodyOut_Response{Data: "abcdef"},
},
verifier: func(json string) {
expected := `{"response":{"data":"abcdef"}}`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

More JSON testing changes

Comment on lines +20 to +23
// TODO(johanbrandhorst): Change this to true before v2
EmitUnpopulated: false,
// TODO(johanbrandhorst): Change this to false before v2
UseProtoNames: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These changes will be the next PR

We have to keep using the old ptypes, descriptor
and plugin packages since rules_go forces us to use them.
Eventually rules_go should move to the new API and we can
purge the use of the golang/protobuf package altogether.
@johanbrandhorst
Copy link
Collaborator Author

Alright, as this is a pretty substantial PR I've annotated the larger changes made. Please take a look if you have time @achew22. I'll merge in a day regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants