Skip to content

Commit

Permalink
implemented feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanadranca committed Oct 19, 2023
1 parent e46aa1f commit e7f6987
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
9 changes: 4 additions & 5 deletions Sources/GRPCReflectionService/Server/ReflectionService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,11 @@ internal struct ReflectionServiceData: Sendable {
}

internal func nameOfFileContainingExtension(
extendeeTypeName extendeeName: String,
named extendeeName: String,
fieldNumber number: Int32
) -> String? {
return self.fileNameByExtensionDescriptor[
ExtensionDescriptor(extendeeTypeName: extendeeName, fieldNumber: number)
]
let key = ExtensionDescriptor(extendeeTypeName: extendeeName, fieldNumber: number)
return self.fileNameByExtensionDescriptor[key]
}
}

Expand Down Expand Up @@ -217,7 +216,7 @@ internal final class ReflectionServiceProvider: Reflection_ServerReflectionAsync
) throws -> Reflection_ServerReflectionResponse {
guard
let fileName = self.protoRegistry.nameOfFileContainingExtension(
extendeeTypeName: extensionRequest.containingType,
named: extensionRequest.containingType,
fieldNumber: extensionRequest.extensionNumber
)
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,20 @@ final class ReflectionServiceIntegrationTests: GRPCTestCase {

let fileToFind = self.protos[0]
let dependentProtos = self.protos[1...]
var receivedProtoContainingExtension = 0
var dependenciesCount = 0
for fileDescriptorProto in receivedData {
if fileDescriptorProto == fileToFind {
receivedProtoContainingExtension += 1
XCTAssert(
fileDescriptorProto.extension.names.contains("extensionInputMessage1"),
fileDescriptorProto.extension.map { $0.name }.contains("extensionInputMessage1"),
"""
The response doesn't contain the serialized file descriptor proto \
containing the \"extensionInputMessage1\" extension.
"""
)
} else {
dependenciesCount += 1
XCTAssert(
dependentProtos.contains(fileDescriptorProto),
"""
Expand All @@ -225,5 +229,11 @@ final class ReflectionServiceIntegrationTests: GRPCTestCase {
)
}
}
XCTAssertEqual(
receivedProtoContainingExtension,
1,
"The file descriptor proto of the proto containing the extension was not received."
)
XCTAssertEqual(dependenciesCount, 3)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
let protos = makeProtosWithDependencies()
let registry = try ReflectionServiceData(fileDescriptors: protos)
let fileName = registry.nameOfFileContainingSymbol(named: "packagebar2.enumType3")
XCTAssertEqual(fileName, nil)
XCTAssertNil(fileName)
}

// Testing the serializedFileDescriptorProto method in different cases.
Expand Down Expand Up @@ -338,7 +338,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
for proto in protos {
for `extension` in proto.extension {
let registryFileName = registry.nameOfFileContainingExtension(
extendeeTypeName: `extension`.extendee,
named: `extension`.extendee,
fieldNumber: `extension`.number
)
XCTAssertEqual(registryFileName, proto.name)
Expand All @@ -359,7 +359,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
for proto in protos {
for `extension` in proto.extension {
let registryFileName = registry.nameOfFileContainingExtension(
extendeeTypeName: `extension`.extendee,
named: `extension`.extendee,
fieldNumber: `extension`.number
)
XCTAssertEqual(registryFileName, proto.name)
Expand All @@ -371,20 +371,20 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
let protos = makeProtosWithDependencies()
let registry = try ReflectionServiceData(fileDescriptors: protos)
let registryFileName = registry.nameOfFileContainingExtension(
extendeeTypeName: "InvalidType",
named: "InvalidType",
fieldNumber: 2
)
XCTAssertEqual(registryFileName, nil)
XCTAssertNil(registryFileName)
}

func testNameOfFileContainingExtensionsInvalidFieldNumber() throws {
let protos = makeProtosWithDependencies()
let registry = try ReflectionServiceData(fileDescriptors: protos)
let registryFileName = registry.nameOfFileContainingExtension(
extendeeTypeName: protos[0].extension[0].extendee,
named: protos[0].extension[0].extendee,
fieldNumber: 4
)
XCTAssertEqual(registryFileName, nil)
XCTAssertNil(registryFileName)
}

func testNameOfFileContainingExtensionsDuplicatedExtensions() throws {
Expand Down
6 changes: 0 additions & 6 deletions Tests/GRPCTests/GRPCReflectionServiceTests/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,3 @@ extension Sequence where Element == Google_Protobuf_EnumDescriptorProto {
self.map { $0.name }
}
}

extension Sequence where Element == Google_Protobuf_FieldDescriptorProto {
var names: [String] {
self.map { $0.name }
}
}

0 comments on commit e7f6987

Please sign in to comment.