diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cfa567238..3a69d4002 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,6 +27,12 @@ jobs: env: RUST_LOG: debug RUST_BACKTRACE: 1 + - name: Run mock_server_logs test + run: cargo test -p pact_ffi returns_mock_server_logs -- --nocapture --include-ignored + working-directory: rust + env: + RUST_LOG: debug + RUST_BACKTRACE: 1 - name: Build Components run: cargo build working-directory: rust diff --git a/rust/pact_ffi/tests/tests.rs b/rust/pact_ffi/tests/tests.rs index 1f0ce774d..0b9e872d2 100644 --- a/rust/pact_ffi/tests/tests.rs +++ b/rust/pact_ffi/tests/tests.rs @@ -9,7 +9,9 @@ use bytes::Bytes; use expectest::prelude::*; use itertools::Itertools; use libc::c_char; +use log::LevelFilter; use maplit::*; +use pact_ffi::log::pactffi_log_to_buffer; use pact_models::bodies::OptionalBody; use pact_models::PactSpecification; use pretty_assertions::assert_eq; @@ -19,14 +21,14 @@ use tempfile::TempDir; use serde_json::{json, Value}; use rstest::rstest; use regex::Regex; - #[allow(deprecated)] use pact_ffi::mock_server::{ pactffi_cleanup_mock_server, pactffi_create_mock_server, pactffi_create_mock_server_for_pact, pactffi_mock_server_mismatches, - pactffi_write_pact_file + pactffi_write_pact_file, + pactffi_mock_server_logs, }; #[allow(deprecated)] use pact_ffi::mock_server::handles::{ @@ -1406,3 +1408,30 @@ fn matching_definition_expressions_matcher() { } }; } + +// Run independently as this log settings are global, and other tests affect this one. +// cargo test -p pact_ffi returns_mock_server_logs -- --nocapture --include-ignored +#[ignore] +#[test] +fn returns_mock_server_logs() { + let pact_json = include_str!("post-pact.json"); + let pact_json_c = CString::new(pact_json).expect("Could not construct C string from json"); + let address = CString::new("127.0.0.1:0").unwrap(); + #[allow(deprecated)] + let port = pactffi_create_mock_server(pact_json_c.as_ptr(), address.as_ptr(), false); + expect!(port).to(be_greater_than(0)); + pactffi_log_to_buffer(LevelFilter::Debug.into()); + let client = Client::default(); + client.post(format!("http://127.0.0.1:{}/path", port).as_str()) + .header(CONTENT_TYPE, "application/json") + .body(r#"{"foo":"no-very-bar"}"#) + .send().expect("Sent POST request to mock server"); + + let logs = unsafe { + CStr::from_ptr(pactffi_mock_server_logs(port)).to_string_lossy().into_owned() + }; + println!("{}",logs); + assert_ne!(logs,"", "logs are empty"); + + pactffi_cleanup_mock_server(port); +} \ No newline at end of file diff --git a/rust/pact_models/Cargo.toml b/rust/pact_models/Cargo.toml index 0235a603b..84bcb0eb1 100644 --- a/rust/pact_models/Cargo.toml +++ b/rust/pact_models/Cargo.toml @@ -45,7 +45,7 @@ semver = "1.0.17" serde = { version = "1.0.163", features = ["derive"] } serde_json = "1.0.96" sxd-document = { version = "0.3.2", optional = true } -tracing = "0.1.37" # This needs to be the same version across all the libs (i.e. Pact FFI and plugin driver) +tracing = "0.1.40" # This needs to be the same version across all the libs (i.e. Pact FFI and plugin driver) [target.'cfg(not(target_family = "wasm"))'.dependencies] fs2 = "0.4.3" @@ -64,7 +64,7 @@ pretty_assertions = "1.3.0" rstest = "0.19.0" speculate = "0.1.2" test-log = { version = "0.2.11", features = ["trace"] } -tracing-subscriber = { version = "0.3.16", features = ["env-filter", "tracing-log", "fmt"] } +tracing-subscriber = { version = "0.3.18", features = ["env-filter", "tracing-log", "fmt"] } trim-margin = "0.1.0" [build-dependencies] diff --git a/rust/scripts/ci-musl-build.sh b/rust/scripts/ci-musl-build.sh index d1f015754..27cd41935 100755 --- a/rust/scripts/ci-musl-build.sh +++ b/rust/scripts/ci-musl-build.sh @@ -5,3 +5,4 @@ set -ex rustc --print cfg cargo build cargo test +cargo test -p pact_ffi returns_mock_server_logs -- --nocapture --include-ignored