diff --git a/integrated_tests/imported_message/build.rs b/integrated_tests/imported_message/build.rs index 45f1530..a5c87ec 100644 --- a/integrated_tests/imported_message/build.rs +++ b/integrated_tests/imported_message/build.rs @@ -1,7 +1,11 @@ fn main() -> Result<(), Box> { - tonic_build::configure().include_file("mod.rs").compile( - &["primary/primary.proto", "imported/imported.proto"], - &["."], - )?; - Ok(()) + tonic_build::configure().include_file("mod.rs").compile( + &[ + "primary/primary.proto", + "imported/imported.proto", + "zimported/zimported.proto", + ], + &["."], + )?; + Ok(()) } diff --git a/integrated_tests/imported_message/imported/imported.proto b/integrated_tests/imported_message/imported/imported.proto index b4d3e98..ed9749a 100644 --- a/integrated_tests/imported_message/imported/imported.proto +++ b/integrated_tests/imported_message/imported/imported.proto @@ -23,8 +23,8 @@ message Rectangle { // Request message for GetRectangle method. This message has different fields, // but the same name as a message defined in primary.proto message RectangleLocationRequest { - int32 width = 1; - int32 length = 2; + int32 a = 1; + int32 b = 2; } // Response message for GetRectangle method. This message has different fields, diff --git a/integrated_tests/imported_message/primary/primary.proto b/integrated_tests/imported_message/primary/primary.proto index 8f7450d..dd5cc27 100644 --- a/integrated_tests/imported_message/primary/primary.proto +++ b/integrated_tests/imported_message/primary/primary.proto @@ -9,6 +9,7 @@ option java_package = "io.grpc.examples.primary"; option java_outer_classname = "PrimaryProto"; import "imported/imported.proto"; +import "zimported/zimported.proto"; package primary; diff --git a/integrated_tests/imported_message/src/lib.rs b/integrated_tests/imported_message/src/lib.rs index 63348aa..55302bf 100644 --- a/integrated_tests/imported_message/src/lib.rs +++ b/integrated_tests/imported_message/src/lib.rs @@ -2,41 +2,41 @@ tonic::include_proto!("mod"); #[cfg(test)] mod tests { - use std::path::Path; + use std::path::Path; - use crate::primary::primary_client::PrimaryClient; - use pact_consumer::mock_server::StartMockServerAsync; - use pact_consumer::prelude::*; - use serde_json::json; - use tonic::IntoRequest; - use tracing::info; + use crate::primary::primary_client::PrimaryClient; + use pact_consumer::mock_server::StartMockServerAsync; + use pact_consumer::prelude::*; + use serde_json::json; + use tonic::IntoRequest; + use tracing::info; - use super::*; + use super::*; - #[tokio::test(flavor = "multi_thread", worker_threads = 1)] - async fn test_proto_client() { - let _ = env_logger::builder().is_test(true).try_init(); + #[tokio::test(flavor = "multi_thread", worker_threads = 1)] + async fn test_proto_client() { + let _ = env_logger::builder().is_test(true).try_init(); - let mut pact_builder = PactBuilderAsync::new_v4("grpc-consumer-rust", "imported_message"); - let mock_server = pact_builder - .using_plugin("protobuf", None) - .await - .synchronous_message_interaction( - "package namespace not respected", - |mut i| async move { - let proto_file = Path::new("primary/primary.proto") - .canonicalize() - .unwrap() - .to_string_lossy() - .to_string(); - let proto_include = Path::new(".") - .canonicalize() - .unwrap() - .to_string_lossy() - .to_string(); - info!("proto_file: {}", proto_file); - info!("proto_include: {}", proto_include); - i.contents_from(json!({ + let mut pact_builder = PactBuilderAsync::new_v4("grpc-consumer-rust", "imported_message"); + let mock_server = pact_builder + .using_plugin("protobuf", None) + .await + .synchronous_message_interaction( + "package namespace not respected", + |mut i| async move { + let proto_file = Path::new("primary/primary.proto") + .canonicalize() + .unwrap() + .to_string_lossy() + .to_string(); + let proto_include = Path::new(".") + .canonicalize() + .unwrap() + .to_string_lossy() + .to_string(); + info!("proto_file: {}", proto_file); + info!("proto_include: {}", proto_include); + i.contents_from(json!({ "pact:proto": proto_file, "pact:proto-service": "Primary/GetRectangle", "pact:content-type": "application/protobuf", @@ -62,25 +62,25 @@ mod tests { } } })) + .await; + i + }, + ) + .await + .start_mock_server_async(Some("protobuf/transport/grpc")) .await; - i - }, - ) - .await - .start_mock_server_async(Some("protobuf/transport/grpc")) - .await; - let url = mock_server.url(); + let url = mock_server.url(); - let mut client = PrimaryClient::connect(url.to_string()).await.unwrap(); - let request_message = primary::RectangleLocationRequest { - x: 180, - y: 200, - width: 10, - length: 20, - }; + let mut client = PrimaryClient::connect(url.to_string()).await.unwrap(); + let request_message = primary::RectangleLocationRequest { + x: 180, + y: 200, + width: 10, + length: 20, + }; - let response = client.get_rectangle(request_message.into_request()).await; - let _response_message = response.unwrap(); - } + let response = client.get_rectangle(request_message.into_request()).await; + let _response_message = response.unwrap(); + } } diff --git a/integrated_tests/imported_message/zimported/zimported.proto b/integrated_tests/imported_message/zimported/zimported.proto new file mode 100644 index 0000000..da74267 --- /dev/null +++ b/integrated_tests/imported_message/zimported/zimported.proto @@ -0,0 +1,39 @@ + +syntax = "proto3"; + +option go_package = "github.com/pact-foundation/pact-go/v2/examples/grpc/zimported"; +option java_multiple_files = true; +option java_package = "io.grpc.examples.zimported"; +option java_outer_classname = "ImportedProto"; + +package zimported; + +service ZImported { + rpc GetRectangle(RectangleLocationRequest) returns (RectangleLocationResponse) {} +} + +message Rectangle { + // The width of the rectangle. + int32 zwidth = 1; + + // The length of the rectangle. + int32 zlength = 2; +} + +// Request message for GetRectangle method. This message has different fields, +// but the same name as a message defined in primary.proto +message RectangleLocationRequest { + int32 zx = 1; + int32 zb = 2; +} + +// Response message for GetRectangle method. This message has different fields, +// but the same name as a message defined in primary.proto +message RectangleLocationResponse { + Point zlocation = 1; +} + +message Point { + int32 zlatitude = 1; + int32 zlongitude = 2; +}