Skip to content

Commit 2b39fb5

Browse files
committed
Cover external protobuf enum edges
1 parent f72a55b commit 2b39fb5

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

elasticgraph-proto_ingestion/spec/unit/elastic_graph/proto_ingestion/schema_definition/schema_edge_cases_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ def self.enums
6666
))
6767
end
6868

69+
it "raises when an externally sourced enum value conflicts with the generated zero value" do
70+
proto_status = ::Class.new do
71+
def self.enums
72+
[::Data.define(:name).new(name: :UNSPECIFIED)]
73+
end
74+
end
75+
76+
results = define_proto_schema_results do |s|
77+
s.enum_type "Status" do |t|
78+
t.value "ACTIVE"
79+
t.external_proto_enum proto_status
80+
end
81+
82+
s.object_type "Account" do |t|
83+
t.field "id", "ID"
84+
t.field "status", "Status"
85+
t.index "accounts"
86+
end
87+
end
88+
89+
expect {
90+
results.proto_schema
91+
}.to raise_error(Errors::SchemaError, a_string_including(
92+
"Enum `Status` value `UNSPECIFIED`",
93+
"conflicts with the generated zero value `STATUS_UNSPECIFIED`"
94+
))
95+
end
96+
6997
it "raises when an enum value conflicts with the generated zero value" do
7098
expect {
7199
define_proto_schema do |s|

elasticgraph-proto_ingestion/spec/unit/elastic_graph/proto_ingestion/schema_definition/schema_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,11 +849,21 @@ def self.enums
849849
end
850850
end
851851

852+
proto_status_c = ::Class.new do
853+
def self.enums
854+
[
855+
::Data.define(:name).new(name: :ACTIVE),
856+
::Data.define(:name).new(name: :INACTIVE)
857+
]
858+
end
859+
end
860+
852861
results = define_proto_schema_results do |s|
853862
s.enum_type "Status" do |t|
854863
t.values "ACTIVE", "INACTIVE"
855864
t.external_proto_enum proto_status_a
856865
t.external_proto_enum proto_status_b
866+
t.external_proto_enum proto_status_c
857867
end
858868

859869
s.object_type "Account" do |t|
@@ -883,6 +893,7 @@ def self.enums
883893
proto = define_proto_schema do |s|
884894
s.enum_type "Status" do |t|
885895
t.values "ACTIVE", "INACTIVE"
896+
expect(t.proto_name).to eq("Status")
886897
t.external_proto_enum proto_status,
887898
proto: "myapp.types.Status",
888899
import: "myapp/types/status.proto"

0 commit comments

Comments
 (0)