Skip to content

Commit

Permalink
Merge pull request #2562 from square/bquenaudon.2023-08-16.extensiontest
Browse files Browse the repository at this point in the history
Add test for extensions in proto path
  • Loading branch information
oldergod authored Aug 16, 2023
2 parents 8641b6a + 125c587 commit 34ad696
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,74 @@ class SchemaTest {
assertThat(schema.protoFile("squareup/domain/message.proto")).isNotNull()
}

@Test
fun extensionInProtoPathDontLoad() {
val schema = buildSchema {
add(
"a/original.proto".toPath(),
"""
|syntax = "proto2";
|package a;
|message A {
| optional string one = 1;
|}
""".trimMargin(),
)
addProtoPath(
"b/extension.proto".toPath(),
"""
|syntax = "proto2";
|package b;
|import "a/original.proto";
|extend a.A {
| optional string two = 2;
|}
""".trimMargin(),
)
}
val fields = (schema.getType("a.A") as MessageType).fields
assertThat(fields).hasSize(1)
with(fields[0]) {
assertThat(namespaces).isEqualTo(listOf("a", "A"))
assertThat(name).isEqualTo("one")
assertThat(isExtension).isEqualTo(false)
}
}

@Test
fun extensionInSourceLoadsEvenIfParentMessageIsInProtoPath() {
val schema = buildSchema {
addProtoPath(
"a/original.proto".toPath(),
"""
|syntax = "proto2";
|package a;
|message A {
| optional string one = 1;
|}
""".trimMargin(),
)
add(
"b/extension.proto".toPath(),
"""
|syntax = "proto2";
|package b;
|import "a/original.proto";
|extend a.A {
| optional string two = 2;
|}
""".trimMargin(),
)
}
val fields = (schema.getType("a.A") as MessageType).fields
assertThat(fields).hasSize(1)
with(fields[0]) {
assertThat(namespaces).isEqualTo(listOf("b"))
assertThat(name).isEqualTo("two")
assertThat(isExtension).isEqualTo(true)
}
}

@Test
fun optionsWithRelativePathUsedInExtensions() {
val schema = buildSchema {
Expand Down

0 comments on commit 34ad696

Please sign in to comment.