Skip to content

Commit

Permalink
demo bug with conflicting names
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-is-hate committed May 7, 2024
1 parent 905967e commit 7af25bc
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 55 deletions.
14 changes: 9 additions & 5 deletions integrated_tests/imported_message/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
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(())
}
4 changes: 2 additions & 2 deletions integrated_tests/imported_message/imported/imported.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions integrated_tests/imported_message/primary/primary.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
96 changes: 48 additions & 48 deletions integrated_tests/imported_message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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();
}
}
39 changes: 39 additions & 0 deletions integrated_tests/imported_message/zimported/zimported.proto
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 7af25bc

Please sign in to comment.