Skip to content

Commit

Permalink
chore: Update flaky mock server test
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jan 29, 2024
1 parent ddd2449 commit 2aa8016
Showing 1 changed file with 3 additions and 36 deletions.
39 changes: 3 additions & 36 deletions tests/mock_server_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::fs;
use std::panic::catch_unwind;
use std::path::Path;
use base64::Engine;
Expand All @@ -20,7 +19,7 @@ use pact_protobuf_plugin::utils::find_message_type_by_name;
async fn mock_server_block() {
let mut pact_builder = PactBuilderAsync::new_v4("null-and-void", "protobuf-plugin");
let _mock_server = pact_builder
.using_plugin("protobuf", Some("0".to_string())).await
.using_plugin("protobuf", None).await
.synchronous_message_interaction("doesn't matter, won't be called", |mut i| async move {
let proto_file = Path::new("tests/simple.proto")
.canonicalize().unwrap().to_string_lossy().to_string();
Expand Down Expand Up @@ -48,37 +47,7 @@ async fn mock_server_block() {
}

#[test_log::test]
#[ignore] // TODO: This test sometimes fails with transport error and other times
// "application/protobuf;application/grpc" was not found in the plugin register
fn mock_server_with_no_requests() {
let current_exe = std::env::current_exe().unwrap();
let current_dir = current_exe.parent().unwrap();
let test_bin_dir = current_dir.parent().unwrap();
let plugin_bin = if cfg!(windows) {
test_bin_dir.join("pact-protobuf-plugin.exe")
} else {
test_bin_dir.join("pact-protobuf-plugin")
};

if plugin_bin.exists() {
let plugin_dir = home::home_dir().unwrap().join(".pact/plugins/protobuf-0");
fs::create_dir_all(plugin_dir.clone()).unwrap();
let manifest_file = plugin_dir.join("pact-plugin.json");
fs::write(manifest_file, json!({
"manifestVersion": 1,
"pluginInterfaceVersion": 1,
"name": "protobuf",
"version": "0",
"executableType": "exec",
"entryPoint": "pact-protobuf-plugin",
"pluginConfig": {
"protocVersion": "3.19.1",
"downloadUrl": "https://github.com/protocolbuffers/protobuf/releases/download"
}
}).to_string()).unwrap();
let plugin_file = plugin_dir.join("pact-protobuf-plugin");
fs::copy(plugin_bin, plugin_file).unwrap();

let result = catch_unwind(|| {
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
Expand All @@ -87,12 +56,10 @@ fn mock_server_with_no_requests() {
runtime.block_on(mock_server_block())
});

fs::remove_dir_all(plugin_dir).unwrap();

let error = result.unwrap_err();
let error_message = panic_message::panic_message(&error);
expect!(error_message).to(be_equal_to("plugin mock server failed verification:\n 1) Test/GetTest: Did not receive any requests for path 'Test/GetTest'\n"));
}
expect!(error_message).to(be_equal_to(
"plugin mock server failed verification:\n 1) Test/GetTest: Did not receive any requests for path 'Test/GetTest'\n"));
}

#[test_log::test(tokio::test(flavor = "multi_thread"))]
Expand Down

0 comments on commit 2aa8016

Please sign in to comment.