Skip to content

Commit 0034ba3

Browse files
authored
generate representative proto definitions (#72)
* generate representative proto definitions * generate proto pb files, and start rewriting tests * add specialized test for empty_service case * DRY and simplify cases * start stubbing tests * complete stubbing and cleanup * flesh out test coverage * linting
1 parent 9cde2d4 commit 0034ba3

57 files changed

Lines changed: 9734 additions & 2463 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

mix.exs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,24 @@ defmodule GrpcReflection.MixProject do
2020
test_coverage: [
2121
ignore_modules: [
2222
~r/^Grpc\./,
23-
~r/^Helloworld\./,
24-
~r/^TestserviceV2\./,
25-
~r/^TestserviceV3\./,
23+
~r/^Google\./,
24+
~r/^ScalarTypes\./,
25+
~r/^Streaming\./,
26+
~r/^EmptyService\./,
27+
~r/^EdgeCases\./,
28+
~r/^Proto2Features\./,
29+
~r/^CustomizedPrefix\./,
30+
~r/^ImportsTest\./,
31+
~r/^CommonTypes\./,
32+
~r/^GlobalService$/,
33+
~r/^GlobalRequest$/,
34+
~r/^GlobalResponse$/,
35+
~r/^Nested\./,
36+
~r/^WellKnownTypes\./,
37+
~r/^PackageA\./,
38+
~r/^PackageB\./,
39+
~r/^NestedEnumConflict\./,
40+
~r/^RecursiveMessage\./,
2641
GrpcReflection.TestEndpoint,
2742
GrpcReflection.TestEndpoint.Endpoint
2843
]

priv/protos/common_types.proto

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
syntax = "proto3";
2+
3+
package common;
4+
5+
// Common messages to be imported by other proto files
6+
7+
message Address {
8+
string street = 1;
9+
string city = 2;
10+
string state = 3;
11+
string postal_code = 4;
12+
string country = 5;
13+
}
14+
15+
message Coordinates {
16+
double latitude = 1;
17+
double longitude = 2;
18+
double altitude = 3;
19+
}
20+
21+
message Money {
22+
string currency_code = 1;
23+
int64 units = 2;
24+
int32 nanos = 3;
25+
}
26+
27+
enum Priority {
28+
PRIORITY_UNSPECIFIED = 0;
29+
LOW = 1;
30+
MEDIUM = 2;
31+
HIGH = 3;
32+
CRITICAL = 4;
33+
}
34+
35+
message TimeRange {
36+
int64 start_time = 1;
37+
int64 end_time = 2;
38+
}
Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
1-
syntax = "proto2";
1+
syntax = "proto3";
22

3-
import "google/protobuf/timestamp.proto";
4-
import "google/protobuf/any.proto";
5-
6-
package testserviceV2;
3+
package custom_prefix;
74

5+
// This proto demonstrates Elixir-specific custom module prefix option
86
import "elixirpb.proto";
9-
option (elixirpb.file).module_prefix = "HLW";
10-
11-
service TestService {
12-
rpc CallFunction (TestRequest) returns (TestReply) {}
13-
}
14-
15-
message TestRequest {
16-
required string name = 1;
17-
optional Enum enum = 2;
18-
oneof test_oneof {
19-
string label = 3;
20-
int32 value = 4;
21-
}
22-
map<string, int32> g = 5;
23-
repeated google.protobuf.Any instrument = 6;
24-
extensions 10 to 20;
25-
}
26-
27-
message Location {
28-
optional double latitude = 1;
29-
optional double longitude = 2;
30-
}
7+
option (elixirpb.file).module_prefix = "CustomizedPrefix";
318

32-
extend TestRequest {
33-
optional string data = 10;
34-
optional Location location = 11;
9+
// Simple service to test custom module prefix generation
10+
service PrefixService {
11+
rpc Echo (EchoRequest) returns (EchoResponse) {}
3512
}
3613

37-
message TestReply {
38-
required google.protobuf.Timestamp today = 2;
14+
message EchoRequest {
15+
string message = 1;
3916
}
4017

41-
enum Enum {
42-
A = 0;
43-
B = 1;
18+
message EchoResponse {
19+
string reply = 1;
4420
}

priv/protos/edge_cases.proto

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
syntax = "proto3";
2+
3+
package edge_cases;
4+
5+
// Service with unusual but valid patterns
6+
service EdgeCaseService {
7+
// Method names with underscores and different conventions
8+
// protoc compiles these fine, but the GRPC upstream stub does not
9+
// rpc process_data (Request) returns (Response) {}
10+
// rpc ProcessData (Request) returns (Response) {}
11+
// rpc PROCESS_DATA (Request) returns (Response) {}
12+
13+
// Empty request or response
14+
rpc EmptyInput(EmptyInputRequest) returns (EmptyInputResponse) {}
15+
rpc EmptyOutput(EmptyOutputRequest) returns (EmptyOutputResponse) {}
16+
rpc BothEmpty(BothEmptyRequest) returns (BothEmptyResponse) {}
17+
// We don't handle circular relations yet
18+
// rpc Complicated(ComplicatedRequest) returns (ComplicatedResponse) {}
19+
}
20+
21+
message EmptyInputRequest {}
22+
message EmptyInputResponse {
23+
string data = 1;
24+
}
25+
message EmptyOutputRequest {
26+
string data = 1;
27+
}
28+
message EmptyOutputResponse {}
29+
message BothEmptyRequest {}
30+
message BothEmptyResponse {}
31+
32+
// message Request {
33+
// string data = 1;
34+
// }
35+
36+
// message Response {
37+
// string result = 1;
38+
// }
39+
40+
message ComplicatedRequest {
41+
SparseFieldNumbers numbers = 1;
42+
ManyFields fields = 2;
43+
DetailedStatus status = 3;
44+
MultipleOneofs oneofs = 4;
45+
NestedMaps nested_maps = 5;
46+
CircularA circular = 6;
47+
WithReservedFields reserved_fields = 7;
48+
UnicodeTest unicode_test = 8;
49+
}
50+
message ComplicatedResponse {
51+
SparseFieldNumbers numbers = 1;
52+
ManyFields fields = 2;
53+
DetailedStatus status = 3;
54+
MultipleOneofs oneofs = 4;
55+
NestedMaps nested_maps = 5;
56+
CircularA circular = 6;
57+
WithReservedFields reserved_fields = 7;
58+
UnicodeTest unicode_test = 8;
59+
}
60+
61+
// Unusual field numbering
62+
message SparseFieldNumbers {
63+
string field_1 = 1;
64+
string field_536870911 = 536870911; // Max field number (2^29 - 1)
65+
}
66+
67+
// Many fields
68+
message ManyFields {
69+
string field_001 = 1;
70+
string field_002 = 2;
71+
string field_003 = 3;
72+
string field_004 = 4;
73+
string field_005 = 5;
74+
string field_006 = 6;
75+
string field_007 = 7;
76+
string field_008 = 8;
77+
string field_009 = 9;
78+
string field_010 = 10;
79+
string field_011 = 11;
80+
string field_012 = 12;
81+
string field_013 = 13;
82+
string field_014 = 14;
83+
string field_015 = 15;
84+
string field_016 = 16;
85+
string field_017 = 17;
86+
string field_018 = 18;
87+
string field_019 = 19;
88+
string field_020 = 20;
89+
}
90+
91+
// Complex enum
92+
enum DetailedStatus {
93+
// Enum with zero value (required in proto3)
94+
DETAILED_STATUS_UNSPECIFIED = 0;
95+
96+
// Various naming patterns
97+
status_active = 1;
98+
STATUS_INACTIVE = 2;
99+
Status_Pending = 3;
100+
101+
// Negative enum values (valid but unusual)
102+
ERROR_STATE = -1;
103+
CRITICAL_ERROR = -100;
104+
105+
// Large enum values
106+
MAX_STATUS = 2147483647; // Max int32
107+
}
108+
109+
// Multiple oneofs in one message
110+
message MultipleOneofs {
111+
oneof first_choice {
112+
string option_a1 = 1;
113+
int32 option_a2 = 2;
114+
}
115+
116+
oneof second_choice {
117+
string option_b1 = 3;
118+
int32 option_b2 = 4;
119+
}
120+
121+
oneof third_choice {
122+
string option_c1 = 5;
123+
int32 option_c2 = 6;
124+
}
125+
126+
string regular_field = 7;
127+
}
128+
129+
// Nested maps
130+
message NestedMaps {
131+
map<string, InnerMap> outer_map = 1;
132+
map<int32, string> int_key_map = 2;
133+
map<int64, int64> numeric_map = 3;
134+
map<bool, string> bool_key_map = 4;
135+
}
136+
137+
message InnerMap {
138+
map<string, string> data = 1;
139+
map<string, int32> counts = 2;
140+
}
141+
142+
// Circular reference patterns (different from recursive_message.proto)
143+
message CircularA {
144+
CircularB b_field = 1;
145+
string data = 2;
146+
}
147+
148+
message CircularB {
149+
CircularC c_field = 1;
150+
string data = 2;
151+
}
152+
153+
message CircularC {
154+
CircularA a_field = 1;
155+
string data = 2;
156+
}
157+
158+
// Reserved with various patterns
159+
message WithReservedFields {
160+
string active_field_1 = 1;
161+
162+
reserved 2, 15, 9 to 11;
163+
reserved "foo", "bar", "old_field";
164+
165+
string active_field_16 = 16;
166+
167+
reserved 100 to max;
168+
}
169+
170+
// Unicode and special characters in comments
171+
message UnicodeTest {
172+
// Field with emoji in comment: 🚀 rocket
173+
string rocket_field = 1;
174+
175+
// Mathematical symbols: ∑ ∫ π
176+
double pi_field = 2;
177+
178+
// Various languages: 你好 مرحبا שלום
179+
string greeting = 3;
180+
}

priv/protos/empty_service.proto

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
syntax = "proto2";
1+
syntax = "proto3";
22

3-
service EmptyService {
4-
5-
}
3+
package empty_service;
4+
5+
// Empty service (no methods) - edge case
6+
service EmptyService {}

priv/protos/global_service.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
3+
// File with no package declaration - valid but unusual
4+
// Messages and services are in the global namespace
5+
6+
service GlobalService {
7+
rpc GlobalMethod (GlobalRequest) returns (GlobalResponse) {}
8+
}
9+
10+
message GlobalRequest {
11+
string data = 1;
12+
}
13+
14+
message GlobalResponse {
15+
string result = 1;
16+
}

priv/protos/helloworld.proto

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)