-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
33c809e
to
eeda767
Compare
2f16422
to
7b189ae
Compare
// TODO(johanbrandhorst): Use new conversion later when possible | ||
// any := protodesc.ToFileDescriptorProto((&anypb.Any{}).ProtoReflect().Descriptor().ParentFile()) | ||
// status := protodesc.ToFileDescriptorProto((&statuspb.Status{}).ProtoReflect().Descriptor().ParentFile()) |
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.
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"]`, |
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.
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}`, |
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.
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\"")}, |
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.
More JSON tests replaced
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): |
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.
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) { |
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.
Replace this nonsense with explicit status unmarshalling
7b189ae
to
af0bb36
Compare
rv.Set(reflect.Append(rv, bv.Elem())) | ||
} | ||
return 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 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"}}` |
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.
More JSON testing changes
af0bb36
to
39fa0ac
Compare
// TODO(johanbrandhorst): Change this to true before v2 | ||
EmitUnpopulated: false, | ||
// TODO(johanbrandhorst): Change this to false before v2 | ||
UseProtoNames: true, |
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.
These changes will be the next PR
39fa0ac
to
1b9c7a9
Compare
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.
1b9c7a9
to
183caa7
Compare
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. |
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.