diff --git a/README.md b/README.md index 89494ba..6be3d96 100644 --- a/README.md +++ b/README.md @@ -41,17 +41,20 @@ Assume you have the following `.proto` file defining `Foo` and `Qux` messages: ```protobuf syntax = "proto3"; -package test; +package api.v1; +option go_package = "github.com/afritzler/protoequal/test/api/v1"; +// The Foo message with Bar, Baz fields and a nested message Qux. message Foo { - string bar = 1; - string baz = 2; - Qux qux = 3; + string bar = 1; // Bar field + string baz = 2; // Baz field + Qux qux = 3; // Qux is a nested message } +// The Qux message with Driver and Handle fields. message Qux { - string driver = 1; - string handle = 2; + string driver = 1; // Driver field + string handle = 2; // Handle field } ``` @@ -69,7 +72,7 @@ import ( "google.golang.org/protobuf/proto" . "github.com/afritzler/protoequal" - "github.com/afritzler/protoequal/test" + "github.com/afritzler/protoequal/test/api/v1" "github.com/onsi/gomega" ) diff --git a/matchers_test.go b/matchers_test.go index b6fda12..bfce0da 100644 --- a/matchers_test.go +++ b/matchers_test.go @@ -3,11 +3,11 @@ package matchers_test import ( "testing" + v1 "github.com/afritzler/protoequal/test/api/v1" "github.com/onsi/gomega" "google.golang.org/protobuf/proto" matchers "github.com/afritzler/protoequal" - "github.com/afritzler/protoequal/test" ) func TestProtoEqualMatcher(t *testing.T) { @@ -22,18 +22,18 @@ func TestProtoEqualMatcher(t *testing.T) { }{ { name: "Should match identical messages", - actual: &test.Foo{ + actual: &v1.Foo{ Bar: "test-bar", Baz: "test-baz", - Qux: &test.Qux{ + Qux: &v1.Qux{ Driver: "foo-driver", Handle: "foo-handle", }, }, - expected: &test.Foo{ + expected: &v1.Foo{ Bar: "test-bar", Baz: "test-baz", - Qux: &test.Qux{ + Qux: &v1.Qux{ Driver: "foo-driver", Handle: "foo-handle", }, @@ -42,18 +42,18 @@ func TestProtoEqualMatcher(t *testing.T) { }, { name: "Should not match different messages", - actual: &test.Foo{ + actual: &v1.Foo{ Bar: "test-bar", Baz: "test-baz", - Qux: &test.Qux{ + Qux: &v1.Qux{ Driver: "foo-driver", Handle: "foo-handle", }, }, - expected: &test.Foo{ + expected: &v1.Foo{ Bar: "different-bar", Baz: "test-baz", - Qux: &test.Qux{ + Qux: &v1.Qux{ Driver: "foo-driver", Handle: "foo-handle", }, @@ -62,18 +62,18 @@ func TestProtoEqualMatcher(t *testing.T) { }, { name: "Should not match messages with different nested fields", - actual: &test.Foo{ + actual: &v1.Foo{ Bar: "test-bar", Baz: "test-baz", - Qux: &test.Qux{ + Qux: &v1.Qux{ Driver: "foo-driver", Handle: "foo-handle", }, }, - expected: &test.Foo{ + expected: &v1.Foo{ Bar: "test-bar", Baz: "test-baz", - Qux: &test.Qux{ + Qux: &v1.Qux{ Driver: "different-driver", Handle: "foo-handle", }, diff --git a/test/test.pb.go b/test/api/v1/test.pb.go similarity index 55% rename from test/test.pb.go rename to test/api/v1/test.pb.go index 7511e43..14db6a6 100644 --- a/test/test.pb.go +++ b/test/api/v1/test.pb.go @@ -2,9 +2,9 @@ // versions: // protoc-gen-go v1.35.1 // protoc (unknown) -// source: test.proto +// source: api/v1/test.proto -package test +package v1 import ( reflect "reflect" @@ -34,7 +34,7 @@ type Foo struct { func (x *Foo) Reset() { *x = Foo{} - mi := &file_test_proto_msgTypes[0] + mi := &file_api_v1_test_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -46,7 +46,7 @@ func (x *Foo) String() string { func (*Foo) ProtoMessage() {} func (x *Foo) ProtoReflect() protoreflect.Message { - mi := &file_test_proto_msgTypes[0] + mi := &file_api_v1_test_proto_msgTypes[0] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -59,7 +59,7 @@ func (x *Foo) ProtoReflect() protoreflect.Message { // Deprecated: Use Foo.ProtoReflect.Descriptor instead. func (*Foo) Descriptor() ([]byte, []int) { - return file_test_proto_rawDescGZIP(), []int{0} + return file_api_v1_test_proto_rawDescGZIP(), []int{0} } func (x *Foo) GetBar() string { @@ -95,7 +95,7 @@ type Qux struct { func (x *Qux) Reset() { *x = Qux{} - mi := &file_test_proto_msgTypes[1] + mi := &file_api_v1_test_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -107,7 +107,7 @@ func (x *Qux) String() string { func (*Qux) ProtoMessage() {} func (x *Qux) ProtoReflect() protoreflect.Message { - mi := &file_test_proto_msgTypes[1] + mi := &file_api_v1_test_proto_msgTypes[1] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -120,7 +120,7 @@ func (x *Qux) ProtoReflect() protoreflect.Message { // Deprecated: Use Qux.ProtoReflect.Descriptor instead. func (*Qux) Descriptor() ([]byte, []int) { - return file_test_proto_rawDescGZIP(), []int{1} + return file_api_v1_test_proto_rawDescGZIP(), []int{1} } func (x *Qux) GetDriver() string { @@ -137,43 +137,44 @@ func (x *Qux) GetHandle() string { return "" } -var File_test_proto protoreflect.FileDescriptor +var File_api_v1_test_proto protoreflect.FileDescriptor -var file_test_proto_rawDesc = []byte{ - 0x0a, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x74, 0x65, - 0x73, 0x74, 0x22, 0x46, 0x0a, 0x03, 0x46, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, 0x61, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x62, - 0x61, 0x7a, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, 0x61, 0x7a, 0x12, 0x1b, 0x0a, - 0x03, 0x71, 0x75, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x74, 0x65, 0x73, - 0x74, 0x2e, 0x51, 0x75, 0x78, 0x52, 0x03, 0x71, 0x75, 0x78, 0x22, 0x35, 0x0a, 0x03, 0x51, 0x75, - 0x78, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x61, 0x6e, - 0x64, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x61, 0x6e, 0x64, 0x6c, - 0x65, 0x42, 0x26, 0x5a, 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x61, 0x66, 0x72, 0x69, 0x74, 0x7a, 0x6c, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, - 0x71, 0x75, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, +var file_api_v1_test_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x22, 0x48, 0x0a, 0x03, 0x46, + 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x62, 0x61, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x7a, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x62, 0x61, 0x7a, 0x12, 0x1d, 0x0a, 0x03, 0x71, 0x75, 0x78, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x51, 0x75, 0x78, + 0x52, 0x03, 0x71, 0x75, 0x78, 0x22, 0x35, 0x0a, 0x03, 0x51, 0x75, 0x78, 0x12, 0x16, 0x0a, 0x06, + 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x72, + 0x69, 0x76, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x42, 0x2d, 0x5a, 0x2b, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x66, 0x72, 0x69, 0x74, + 0x7a, 0x6c, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, 0x71, 0x75, 0x61, 0x6c, 0x2f, + 0x74, 0x65, 0x73, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( - file_test_proto_rawDescOnce sync.Once - file_test_proto_rawDescData = file_test_proto_rawDesc + file_api_v1_test_proto_rawDescOnce sync.Once + file_api_v1_test_proto_rawDescData = file_api_v1_test_proto_rawDesc ) -func file_test_proto_rawDescGZIP() []byte { - file_test_proto_rawDescOnce.Do(func() { - file_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_test_proto_rawDescData) +func file_api_v1_test_proto_rawDescGZIP() []byte { + file_api_v1_test_proto_rawDescOnce.Do(func() { + file_api_v1_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_v1_test_proto_rawDescData) }) - return file_test_proto_rawDescData + return file_api_v1_test_proto_rawDescData } -var file_test_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_test_proto_goTypes = []any{ - (*Foo)(nil), // 0: test.Foo - (*Qux)(nil), // 1: test.Qux +var file_api_v1_test_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_api_v1_test_proto_goTypes = []any{ + (*Foo)(nil), // 0: api.v1.Foo + (*Qux)(nil), // 1: api.v1.Qux } -var file_test_proto_depIdxs = []int32{ - 1, // 0: test.Foo.qux:type_name -> test.Qux +var file_api_v1_test_proto_depIdxs = []int32{ + 1, // 0: api.v1.Foo.qux:type_name -> api.v1.Qux 1, // [1:1] is the sub-list for method output_type 1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name @@ -181,27 +182,27 @@ var file_test_proto_depIdxs = []int32{ 0, // [0:1] is the sub-list for field type_name } -func init() { file_test_proto_init() } -func file_test_proto_init() { - if File_test_proto != nil { +func init() { file_api_v1_test_proto_init() } +func file_api_v1_test_proto_init() { + if File_api_v1_test_proto != nil { return } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_test_proto_rawDesc, + RawDescriptor: file_api_v1_test_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, - GoTypes: file_test_proto_goTypes, - DependencyIndexes: file_test_proto_depIdxs, - MessageInfos: file_test_proto_msgTypes, + GoTypes: file_api_v1_test_proto_goTypes, + DependencyIndexes: file_api_v1_test_proto_depIdxs, + MessageInfos: file_api_v1_test_proto_msgTypes, }.Build() - File_test_proto = out.File - file_test_proto_rawDesc = nil - file_test_proto_goTypes = nil - file_test_proto_depIdxs = nil + File_api_v1_test_proto = out.File + file_api_v1_test_proto_rawDesc = nil + file_api_v1_test_proto_goTypes = nil + file_api_v1_test_proto_depIdxs = nil } diff --git a/test/test.proto b/test/api/v1/test.proto similarity index 80% rename from test/test.proto rename to test/api/v1/test.proto index a24ab01..38c9f36 100644 --- a/test/test.proto +++ b/test/api/v1/test.proto @@ -1,7 +1,7 @@ syntax = "proto3"; -package test; -option go_package = "github.com/afritzler/protoequal/test"; +package api.v1; +option go_package = "github.com/afritzler/protoequal/test/api/v1"; // The Foo message with Bar, Baz fields and a nested message Qux. message Foo {