Repository: googleapis/api-linter
Pull request #111 (2019-07-15 19:10:41)

Updated protoreflect library to latest version and fixed breaking changes for client code


Patch:
diff --git a/go.mod b/go.mod
index b3eb178..39bbb58 100644
--- a/go.mod
+++ b/go.mod
@@ -11,6 +11,6 @@ require (
 	golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3 // indirect
 	golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect
 	golang.org/x/tools v0.0.0-20180928181343-b3c0be4c978b // indirect
-	google.golang.org/protobuf v0.0.0-20190620205513-8c86fc5e7dbb
+	google.golang.org/protobuf v0.0.0-20190715184412-3d8e369c4e5f
 	gopkg.in/yaml.v2 v2.2.2
 )
diff --git a/go.sum b/go.sum
index 6eecfda..acf9d44 100644
--- a/go.sum
+++ b/go.sum
@@ -66,6 +66,8 @@ google.golang.org/protobuf v0.0.0-20190617175724-bd7b7a9e0c26/go.mod h1:+FOB8T5/
 google.golang.org/protobuf v0.0.0-20190620020611-d888139e7b59/go.mod h1:of3pt14Y+dOxz2tBOHXEoapPpKFC15/0zWhPAddkfsU=
 google.golang.org/protobuf v0.0.0-20190620205513-8c86fc5e7dbb h1:Rt6Lb4RxAELQU0uyIZTqVdj9179KaZdDvCEDkUdupHI=
 google.golang.org/protobuf v0.0.0-20190620205513-8c86fc5e7dbb/go.mod h1:yGm7aNHn9Bp1NIvj6+CVUkcJshu+Usshfd3A+YxEuI8=
+google.golang.org/protobuf v0.0.0-20190715184412-3d8e369c4e5f h1:CWLaSX+UXIJ6DJHhwzgUmwhSSzBFBnEvQ7vnFpcGLWc=
+google.golang.org/protobuf v0.0.0-20190715184412-3d8e369c4e5f/go.mod h1:yGm7aNHn9Bp1NIvj6+CVUkcJshu+Usshfd3A+YxEuI8=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=


Test patch:
diff --git a/lint/linter_test.go b/lint/linter_test.go
index b392346..219a2a2 100644
--- a/lint/linter_test.go
+++ b/lint/linter_test.go
@@ -20,6 +20,7 @@ import (
 	"strings"
 	"testing"
 
+	"google.golang.org/protobuf/proto"
 	"google.golang.org/protobuf/types/descriptorpb"
 )
 
@@ -135,6 +136,7 @@ func TestLinter_LintProtos_RulePanics(t *testing.T) {
 
 		fd := new(descriptorpb.FileDescriptorProto)
 		fd.SourceCodeInfo = new(descriptorpb.SourceCodeInfo)
+		fd.Name = proto.String("test.proto")
 
 		l := New(r, []Config{{
 			IncludedPaths: []string{"**"},
diff --git a/lint/registry_test.go b/lint/registry_test.go
index 5457677..f71541e 100644
--- a/lint/registry_test.go
+++ b/lint/registry_test.go
@@ -4,6 +4,7 @@ import (
 	"testing"
 
 	"github.com/googleapis/api-linter/testutil"
+	"google.golang.org/protobuf/reflect/protoreflect"
 	"google.golang.org/protobuf/types/descriptorpb"
 )
 
@@ -35,10 +36,15 @@ message Foo {
 		t.Fatalf("makeRegistryFromAllFiles() returned error %q; want nil", err)
 	}
 
-	foo, err := reg.FindMessageByName("Foo")
+	fooDesc, err := reg.FindDescriptorByName("Foo")
 
 	if err != nil {
-		t.Fatalf("reg.FindMessageByName(%q) returned error %q; want nil", fooProto.GetName(), err)
+		t.Fatalf("reg.FindDescriptorByName(%q) returned error %q; want nil", fooProto.GetName(), err)
+	}
+
+	foo, ok := fooDesc.(protoreflect.MessageDescriptor)
+	if !ok {
+		t.Fatalf("reg.FindDescriptorByname(%q) returned a non-message descriptor: %+v", fooProto.GetName(), fooDesc)
 	}
 
 	if foo.Fields().Len() != 1 {
@@ -98,10 +104,14 @@ message Baz {
 		t.Fatalf("makeRegistryFromAllFiles() returned error %q; want nil", err)
 	}
 
-	foo, err := reg.FindMessageByName("Foo")
+	fooDesc, err := reg.FindDescriptorByName("Foo")
 	if err != nil {
 		t.Fatalf("reg.FindMessageByName(%q) returned error %q; want nil", "Foo", err)
 	}
+	foo, ok := fooDesc.(protoreflect.MessageDescriptor)
+	if !ok {
+		t.Fatalf("reg.FindDescriptorByname(%q) returned a non-message descriptor: %+v", fooProto.GetName(), fooDesc)
+	}
 
 	if foo.Fields().Len() != 1 {
 		t.Fatalf("foo.Fields().Len()=%d; want 1", foo.Fields().Len())
@@ -117,10 +127,14 @@ message Baz {
 		t.Fatalf("foo.Fields().Get(0).IsPlaceholder()=true; want false")
 	}
 
-	baz, err := reg.FindMessageByName("Baz")
+	bazDesc, err := reg.FindDescriptorByName("Baz")
 	if err != nil {
 		t.Fatalf("reg.FindMessageByName(%q) returned error %q; want nil", "Baz", err)
 	}
+	baz, ok := bazDesc.(protoreflect.MessageDescriptor)
+	if !ok {
+		t.Fatalf("reg.FindDescriptorByname(%q) returned a non-message descriptor: %+v", bazProto.GetName(), bazDesc)
+	}
 
 	if baz.Fields().Len() != 2 {
 		t.Fatalf("baz.Fields.Len()=%d; want 2", baz.Fields().Len())
@@ -175,10 +189,14 @@ message Foo {
 		t.Fatalf("makeRegistryFromAllFiles() returned error %q; want nil", err)
 	}
 
-	foo, err := reg.FindMessageByName("Foo")
+	fooDesc, err := reg.FindDescriptorByName("Foo")
 	if err != nil {
 		t.Fatalf("Failed to find Foo message: %s.", err)
 	}
+	foo, ok := fooDesc.(protoreflect.MessageDescriptor)
+	if !ok {
+		t.Fatalf("reg.FindDescriptorByname(%q) returned a non-message descriptor: %+v", fooProto.GetName(), fooDesc)
+	}
 
 	if foo.Fields().Len() != 1 {
 		t.Fatalf("foo.Fields().Len()=%d; want 1", foo.Fields().Len())
diff --git a/rules/0131_test.go b/rules/0131_test.go
index 4038db9..4cf4c6b 100644
--- a/rules/0131_test.go
+++ b/rules/0131_test.go
@@ -49,7 +49,7 @@ func TestGetRequestMessageName(t *testing.T) {
 		errPrefix := "AIP-131 Request Name"
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: lint.NewProtoRequest returned error %v", errPrefix, err)
@@ -105,7 +105,7 @@ func TestGetRequestMessageNameField(t *testing.T) {
 		errPrefix := "AIP-131 Request Name Field"
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: lint.NewProtoRequest returned error %v", errPrefix, err)
@@ -173,7 +173,7 @@ func TestGetRequestMessageUnknownFields(t *testing.T) {
 		errPrefix := "AIP-131 Request Unknown Fields"
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: lint.NewProtoRequest returned error %v", errPrefix, err)
@@ -230,7 +230,7 @@ func TestGetResponseMessageName(t *testing.T) {
 		errPrefix := "AIP-131 Response Message Name"
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: lint.NewProtoRequest returned error %v", errPrefix, err)
diff --git a/rules/0132_test.go b/rules/0132_test.go
index 0cfb68c..5f6ce08 100644
--- a/rules/0132_test.go
+++ b/rules/0132_test.go
@@ -52,7 +52,7 @@ func TestListRequestMessageName(t *testing.T) {
 		errPrefix := "AIP-132 Request Name"
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: lint.NewProtoRequest returned error %v", errPrefix, err)
@@ -112,7 +112,7 @@ func TestListRequestMessageParentField(t *testing.T) {
 		errPrefix := "AIP-132 Request Parent Field"
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: lint.NewProtoRequest returned error %v", errPrefix, err)
@@ -184,7 +184,7 @@ func TestListRequestMessageUnknownFields(t *testing.T) {
 		errPrefix := "AIP-132 Request Unknown Fields"
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: lint.NewProtoRequest returned error %v", errPrefix, err)
@@ -240,7 +240,7 @@ func TestListResponseMessageName(t *testing.T) {
 		errPrefix := "AIP-132 Response Message Name"
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: lint.NewProtoRequest returned error %v", errPrefix, err)
diff --git a/rules/check_field_names_use_lower_snake_case_test.go b/rules/check_field_names_use_lower_snake_case_test.go
index 2c2930b..29cbd07 100644
--- a/rules/check_field_names_use_lower_snake_case_test.go
+++ b/rules/check_field_names_use_lower_snake_case_test.go
@@ -50,7 +50,7 @@ func TestFieldNamesUseLowerSnakeCaseRule(t *testing.T) {
 
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: lint.NewProtoRequest returned error %v", errPrefix, err)
diff --git a/rules/check_proto_syntax_version_test.go b/rules/check_proto_syntax_version_test.go
index 822a8fb..daf59e8 100644
--- a/rules/check_proto_syntax_version_test.go
+++ b/rules/check_proto_syntax_version_test.go
@@ -41,7 +41,7 @@ func TestProtoVersionRule(t *testing.T) {
 
 		req, err := lint.NewProtoRequest(testutil.MustCreateFileDescriptorProto(
 			t,
-			testutil.FileDescriptorSpec{Template: tmpl, Data: test},
+			testutil.FileDescriptorSpec{Filename: "test.proto", Template: tmpl, Data: test},
 		), nil)
 		if err != nil {
 			t.Errorf("%s: NewProtoRequest returned error %v", errPrefix, err)
diff --git a/rules/rules_test.go b/rules/rules_test.go
index bbce3ae..2748075 100644
--- a/rules/rules_test.go
+++ b/rules/rules_test.go
@@ -22,6 +22,7 @@ var testdatadir = func(lib string) string {
 
 func TestTestData_ApiCommonProtos(t *testing.T) {
 	fd := testutil.MustCreateFileDescriptorProto(t, testutil.FileDescriptorSpec{
+		Filename: "test.proto",
 		Template: `syntax = "proto3";
 
 import "google/api/auth.proto";