From e7f6987ae8dafa619963affcf6ccaec978946082 Mon Sep 17 00:00:00 2001 From: Stefana Dranca Date: Thu, 19 Oct 2023 14:02:13 +0100 Subject: [PATCH] implemented feedback --- .../Server/ReflectionService.swift | 9 ++++----- .../ReflectionServiceIntegrationTests.swift | 12 +++++++++++- .../ReflectionServiceUnitTests.swift | 14 +++++++------- .../GRPCReflectionServiceTests/Utils.swift | 6 ------ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Sources/GRPCReflectionService/Server/ReflectionService.swift b/Sources/GRPCReflectionService/Server/ReflectionService.swift index 7c1dd7600..fe388a0ec 100644 --- a/Sources/GRPCReflectionService/Server/ReflectionService.swift +++ b/Sources/GRPCReflectionService/Server/ReflectionService.swift @@ -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] } } @@ -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 { diff --git a/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift b/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift index 487a68161..651ac0c3c 100644 --- a/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift +++ b/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift @@ -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), """ @@ -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) } } diff --git a/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift b/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift index b4d119069..7b7f60b14 100644 --- a/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift +++ b/Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift @@ -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. @@ -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) @@ -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) @@ -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 { diff --git a/Tests/GRPCTests/GRPCReflectionServiceTests/Utils.swift b/Tests/GRPCTests/GRPCReflectionServiceTests/Utils.swift index 596fd13da..faea453cb 100644 --- a/Tests/GRPCTests/GRPCReflectionServiceTests/Utils.swift +++ b/Tests/GRPCTests/GRPCReflectionServiceTests/Utils.swift @@ -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 } - } -}