From 8ab76b8bb2b0956fc27baec0d63fe18abbd23b3c Mon Sep 17 00:00:00 2001 From: George Barnett Date: Thu, 14 Nov 2024 13:35:20 +0000 Subject: [PATCH] Fix tests are changes in core Motivation: We changed some names in the code gen lib in grpc-swift. Modifications: Use newer naming. Result: Compiles against main --- .../ProtobufCodeGenParser.swift | 33 ++++++++++--------- .../ProtobufCodeGenParserTests.swift | 30 ++++++++--------- .../ProtobufCodeGeneratorTests.swift | 8 ++--- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/Sources/GRPCProtobufCodeGen/ProtobufCodeGenParser.swift b/Sources/GRPCProtobufCodeGen/ProtobufCodeGenParser.swift index 734cf06..e7e0a10 100644 --- a/Sources/GRPCProtobufCodeGen/ProtobufCodeGenParser.swift +++ b/Sources/GRPCProtobufCodeGen/ProtobufCodeGenParser.swift @@ -15,11 +15,9 @@ */ internal import Foundation +internal import GRPCCodeGen internal import SwiftProtobufPluginLibrary -internal import struct GRPCCodeGen.CodeGenerationRequest -internal import struct GRPCCodeGen.SourceGenerator - /// Parses a ``FileDescriptor`` object into a ``CodeGenerationRequest`` object. internal struct ProtobufCodeGenParser { let input: FileDescriptor @@ -68,7 +66,7 @@ internal struct ProtobufCodeGenParser { "GRPCProtobuf.ProtobufDeserializer<\(messageType)>()" } let services = self.input.services.map { - CodeGenerationRequest.ServiceDescriptor( + ServiceDescriptor( descriptor: $0, package: input.package, protobufNamer: self.namer, @@ -88,41 +86,41 @@ internal struct ProtobufCodeGenParser { } extension ProtobufCodeGenParser { - fileprivate var codeDependencies: [CodeGenerationRequest.Dependency] { - var codeDependencies: [CodeGenerationRequest.Dependency] = [ + fileprivate var codeDependencies: [Dependency] { + var codeDependencies: [Dependency] = [ .init(module: "GRPCProtobuf", accessLevel: .internal) ] // Adding as dependencies the modules containing generated code or types for // '.proto' files imported in the '.proto' file we are parsing. codeDependencies.append( contentsOf: (self.protoToModuleMappings.neededModules(forFile: self.input) ?? []).map { - CodeGenerationRequest.Dependency(module: $0, accessLevel: self.accessLevel) + Dependency(module: $0, accessLevel: self.accessLevel) } ) // Adding extra imports passed in as an option to the plugin. codeDependencies.append( contentsOf: self.extraModuleImports.sorted().map { - CodeGenerationRequest.Dependency(module: $0, accessLevel: self.accessLevel) + Dependency(module: $0, accessLevel: self.accessLevel) } ) return codeDependencies } } -extension CodeGenerationRequest.ServiceDescriptor { +extension GRPCCodeGen.ServiceDescriptor { fileprivate init( - descriptor: ServiceDescriptor, + descriptor: SwiftProtobufPluginLibrary.ServiceDescriptor, package: String, protobufNamer: SwiftProtobufNamer, file: FileDescriptor ) { let methods = descriptor.methods.map { - CodeGenerationRequest.ServiceDescriptor.MethodDescriptor( + GRPCCodeGen.MethodDescriptor( descriptor: $0, protobufNamer: protobufNamer ) } - let name = CodeGenerationRequest.Name( + let name = Name( base: descriptor.name, // The service name from the '.proto' file is expected to be in upper camel case generatedUpperCase: descriptor.name, @@ -131,7 +129,7 @@ extension CodeGenerationRequest.ServiceDescriptor { // Packages that are based on the path of the '.proto' file usually // contain dots. For example: "grpc.test". - let namespace = CodeGenerationRequest.Name( + let namespace = Name( base: package, generatedUpperCase: protobufNamer.formattedUpperCasePackage(file: file), generatedLowerCase: protobufNamer.formattedLowerCasePackage(file: file) @@ -141,9 +139,12 @@ extension CodeGenerationRequest.ServiceDescriptor { } } -extension CodeGenerationRequest.ServiceDescriptor.MethodDescriptor { - fileprivate init(descriptor: MethodDescriptor, protobufNamer: SwiftProtobufNamer) { - let name = CodeGenerationRequest.Name( +extension GRPCCodeGen.MethodDescriptor { + fileprivate init( + descriptor: SwiftProtobufPluginLibrary.MethodDescriptor, + protobufNamer: SwiftProtobufNamer + ) { + let name = Name( base: descriptor.name, // The method name from the '.proto' file is expected to be in upper camel case generatedUpperCase: descriptor.name, diff --git a/Tests/GRPCProtobufCodeGenTests/ProtobufCodeGenParserTests.swift b/Tests/GRPCProtobufCodeGenTests/ProtobufCodeGenParserTests.swift index 6e814bb..a94c816 100644 --- a/Tests/GRPCProtobufCodeGenTests/ProtobufCodeGenParserTests.swift +++ b/Tests/GRPCProtobufCodeGenTests/ProtobufCodeGenParserTests.swift @@ -61,9 +61,9 @@ final class ProtobufCodeGenParserTests: XCTestCase { self.testCommonHelloworldParsedRequestFields(for: parsedCodeGenRequest) - let expectedMethod = CodeGenerationRequest.ServiceDescriptor.MethodDescriptor( + let expectedMethod = MethodDescriptor( documentation: "/// Sends a greeting.\n", - name: CodeGenerationRequest.Name( + name: Name( base: "SayHello", generatedUpperCase: "SayHello", generatedLowerCase: "sayHello" @@ -76,14 +76,14 @@ final class ProtobufCodeGenParserTests: XCTestCase { guard let method = parsedCodeGenRequest.services.first?.methods.first else { return XCTFail() } XCTAssertEqual(method, expectedMethod) - let expectedService = CodeGenerationRequest.ServiceDescriptor( + let expectedService = ServiceDescriptor( documentation: "/// The greeting service definition.\n", - name: CodeGenerationRequest.Name( + name: Name( base: "Greeter", generatedUpperCase: "Greeter", generatedLowerCase: "greeter" ), - namespace: CodeGenerationRequest.Name( + namespace: Name( base: "helloworld", generatedUpperCase: "Helloworld", generatedLowerCase: "helloworld" @@ -143,9 +143,9 @@ final class ProtobufCodeGenParserTests: XCTestCase { self.testCommonHelloworldParsedRequestFields(for: parsedCodeGenRequest) - let expectedMethod = CodeGenerationRequest.ServiceDescriptor.MethodDescriptor( + let expectedMethod = MethodDescriptor( documentation: "/// Sends a greeting.\n", - name: CodeGenerationRequest.Name( + name: Name( base: "SayHello", generatedUpperCase: "SayHello", generatedLowerCase: "sayHello" @@ -158,14 +158,14 @@ final class ProtobufCodeGenParserTests: XCTestCase { guard let method = parsedCodeGenRequest.services.first?.methods.first else { return XCTFail() } XCTAssertEqual(method, expectedMethod) - let expectedService = CodeGenerationRequest.ServiceDescriptor( + let expectedService = ServiceDescriptor( documentation: "/// The greeting service definition.\n", - name: CodeGenerationRequest.Name( + name: Name( base: "Greeter", generatedUpperCase: "Greeter", generatedLowerCase: "greeter" ), - namespace: CodeGenerationRequest.Name( + namespace: Name( base: "hello.world", generatedUpperCase: "Hello_World", generatedLowerCase: "hello_world" @@ -225,9 +225,9 @@ final class ProtobufCodeGenParserTests: XCTestCase { self.testCommonHelloworldParsedRequestFields(for: parsedCodeGenRequest) - let expectedMethod = CodeGenerationRequest.ServiceDescriptor.MethodDescriptor( + let expectedMethod = MethodDescriptor( documentation: "/// Sends a greeting.\n", - name: CodeGenerationRequest.Name( + name: Name( base: "SayHello", generatedUpperCase: "SayHello", generatedLowerCase: "sayHello" @@ -240,14 +240,14 @@ final class ProtobufCodeGenParserTests: XCTestCase { guard let method = parsedCodeGenRequest.services.first?.methods.first else { return XCTFail() } XCTAssertEqual(method, expectedMethod) - let expectedService = CodeGenerationRequest.ServiceDescriptor( + let expectedService = ServiceDescriptor( documentation: "/// The greeting service definition.\n", - name: CodeGenerationRequest.Name( + name: Name( base: "Greeter", generatedUpperCase: "Greeter", generatedLowerCase: "greeter" ), - namespace: CodeGenerationRequest.Name( + namespace: Name( base: "", generatedUpperCase: "", generatedLowerCase: "" diff --git a/Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift b/Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift index c262d8b..17c0df5 100644 --- a/Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift +++ b/Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift @@ -146,11 +146,11 @@ final class ProtobufCodeGeneratorTests: XCTestCase { @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) internal struct Hello_World_Greeter_Client: Hello_World_Greeter.ClientProtocol { private let client: GRPCCore.GRPCClient - + internal init(wrapping client: GRPCCore.GRPCClient) { self.client = client } - + /// Sends a greeting. internal func sayHello( request: GRPCCore.ClientRequest, @@ -473,11 +473,11 @@ final class ProtobufCodeGeneratorTests: XCTestCase { @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) package struct Greeter_Client: Greeter.ClientProtocol { private let client: GRPCCore.GRPCClient - + package init(wrapping client: GRPCCore.GRPCClient) { self.client = client } - + /// Sends a greeting. package func sayHello( request: GRPCCore.ClientRequest,