-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Take into account package names when looking for message types i…
…n the descriptors
- Loading branch information
1 parent
4587ac7
commit d9ce8fb
Showing
8 changed files
with
3,728 additions
and
21 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "imported_message" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
tokio = { version = "1", features = ["full"] } | ||
anyhow = "1.0.43" | ||
tonic = "0.8.3" | ||
prost = "0.11.9" | ||
prost-types = "0.11.9" | ||
tracing = { version = "0.1", features = [ "log-always" ] } | ||
tracing-subscriber = { version = "0.3", features = ["env-filter"] } | ||
|
||
[dev-dependencies] | ||
expectest = "0.12.0" | ||
env_logger = "0.10.1" | ||
pact-plugin-driver = "0.4.6" | ||
pact_consumer = "1.0.5" | ||
serde_json = "1.0.66" | ||
maplit = "1.0.2" | ||
|
||
[build-dependencies] | ||
tonic-build = "0.8.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
tonic_build::configure().include_file("mod.rs").compile( | ||
&["primary/primary.proto", "imported/imported.proto"], | ||
&["."], | ||
)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/imported"; | ||
option java_multiple_files = true; | ||
option java_package = "io.grpc.examples.imported"; | ||
option java_outer_classname = "ImportedProto"; | ||
|
||
package imported; | ||
|
||
service Imported { | ||
rpc GetRectangle(RectangleLocationRequest) returns (RectangleLocationResponse) {} | ||
} | ||
|
||
message Rectangle { | ||
// The width of the rectangle. | ||
int32 width = 1; | ||
|
||
// The length of the rectangle. | ||
int32 length = 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 width = 1; | ||
int32 length = 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 location = 1; | ||
} | ||
|
||
message Point { | ||
int32 latitude = 1; | ||
int32 longitude = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
// Copyright 2015 gRPC authors. | ||
// | ||
syntax = "proto3"; | ||
|
||
option go_package = "github.com/pact-foundation/pact-go/v2/examples/grpc/primary"; | ||
option java_multiple_files = true; | ||
option java_package = "io.grpc.examples.primary"; | ||
option java_outer_classname = "PrimaryProto"; | ||
|
||
import "imported/imported.proto"; | ||
|
||
package primary; | ||
|
||
service Primary { | ||
rpc GetRectangle(RectangleLocationRequest) returns (RectangleLocationResponse) {} | ||
} | ||
|
||
// A latitude-longitude rectangle, represented as two diagonally opposite | ||
// points "lo" and "hi". | ||
message Rectangle { | ||
// One corner of the rectangle. | ||
imported.Point lo = 1; | ||
|
||
// The other corner of the rectangle. | ||
imported.Point hi = 2; | ||
} | ||
|
||
// A request payload to get a Rectangle. | ||
message RectangleLocationRequest { | ||
// The width of the rectangle. | ||
int32 x = 1; | ||
int32 y = 2; | ||
int32 width = 3; | ||
int32 length = 4; | ||
} | ||
|
||
// A response payload containing a Rectangle. | ||
message RectangleLocationResponse { | ||
// The location of the rectangle. | ||
Rectangle rectangle = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
tonic::include_proto!("mod"); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
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 super::*; | ||
|
||
#[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!({ | ||
"pact:proto": proto_file, | ||
"pact:proto-service": "Primary/GetRectangle", | ||
"pact:content-type": "application/protobuf", | ||
"pact:protobuf-config": { | ||
"additionalIncludes": [ proto_include ] | ||
}, | ||
"request": { | ||
"x": "matching(number, 180)", | ||
"y": "matching(number, 200)", | ||
"width": "matching(number, 10)", | ||
"length": "matching(number, 20)" | ||
}, | ||
"response": { | ||
"rectangle": { | ||
"lo": { | ||
"latitude": "matching(number, 180)", | ||
"longitude": "matching(number, 99)" | ||
}, | ||
"hi": { | ||
"latitude": "matching(number, 200)", | ||
"longitude": "matching(number, 99)" | ||
} | ||
} | ||
} | ||
})) | ||
.await; | ||
i | ||
}, | ||
) | ||
.await | ||
.start_mock_server_async(Some("protobuf/transport/grpc")) | ||
.await; | ||
|
||
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 response = client.get_rectangle(request_message.into_request()).await; | ||
let _response_message = response.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.