Skip to content

Commit 5f29c5a

Browse files
committed
Cover external protobuf enum edges
1 parent 1b19ac2 commit 5f29c5a

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ module SchemaDefinition
4848
end
4949
}.to raise_error(Errors::SchemaError, a_string_including("both map to the same proto type name `package_`"))
5050
end
51+
52+
it "detects proto type name collisions after enum configuration blocks run" do
53+
proto_status = ::Data.define(:enums).new(enums: [])
54+
55+
expect {
56+
define_proto_schema do |s|
57+
s.enum_type "CurrentStatus" do |t|
58+
t.value "ACTIVE"
59+
t.external_proto_enum proto_status,
60+
proto: "myapp.types.Status",
61+
import: "myapp/types/status.proto"
62+
end
63+
64+
s.enum_type "PreviousStatus" do |t|
65+
t.value "ACTIVE"
66+
t.external_proto_enum proto_status,
67+
proto: "myapp.types.Status",
68+
import: "myapp/types/status.proto"
69+
end
70+
end
71+
}.to raise_error(Errors::SchemaError, a_string_including(
72+
"Type names `CurrentStatus` and `PreviousStatus`",
73+
"same proto type name `myapp.types.Status`"
74+
))
75+
end
5176
end
5277
end
5378
end

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
@@ -877,11 +877,21 @@ def self.enums
877877
end
878878
end
879879

880+
proto_status_c = ::Class.new do
881+
def self.enums
882+
[
883+
::Data.define(:name).new(name: :ACTIVE),
884+
::Data.define(:name).new(name: :INACTIVE)
885+
]
886+
end
887+
end
888+
880889
results = define_proto_schema_results do |s|
881890
s.enum_type "Status" do |t|
882891
t.values "ACTIVE", "INACTIVE"
883892
t.external_proto_enum proto_status_a
884893
t.external_proto_enum proto_status_b
894+
t.external_proto_enum proto_status_c
885895
end
886896

887897
s.object_type "Account" do |t|
@@ -911,6 +921,7 @@ def self.enums
911921
proto = define_proto_schema do |s|
912922
s.enum_type "Status" do |t|
913923
t.values "ACTIVE", "INACTIVE"
924+
expect(t.proto_name).to eq("Status")
914925
t.external_proto_enum proto_status,
915926
proto: "myapp.types.Status",
916927
import: "myapp/types/status.proto"

0 commit comments

Comments
 (0)