From 4318a4a408611ac9a985dbe2297fd3eeeca84f24 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 6 Sep 2024 13:28:19 +0100 Subject: [PATCH 1/4] docs: point to new workshop link The DiUS pact-net workshop is out of date. We have created a new repo under the pact-foundation org https://github.com/pact-foundation/pact-workshop-dotnet which is a hard fork but applies updates to Pact-Net 4.5.x / .NET 6 It at least puts it under our control for maintenance so we can update in a timely fashion and apply contributions from the community --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e257eb31..ee15ef05 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Watch our [series](https://www.youtube.com/playlist?list=PLwy9Bnco-IpfZ72VQ7hce8 ### Tutorial (60 minutes) -[Learn everything in Pact Net in 60 minutes](https://github.com/DiUS/pact-workshop-dotnet-core-v3/) +[Learn everything in Pact Net in 60 minutes](https://github.com/pact-foundation/pact-workshop-dotnet) ### Upgrade Guides From 27df006fda110ecbfe70d57fe8c0dd329e994743 Mon Sep 17 00:00:00 2001 From: Adam Rodger Date: Sun, 8 Sep 2024 14:20:03 +0100 Subject: [PATCH 2/4] chore(ffi): Update to FFI 0.4.23 This involves a breaking change in the FFI packaging for MacOS which was introduced in version 0.4.21: https://github.com/pact-foundation/pact-reference/releases/tag/libpact_ffi-v0.4.21 --- .gitignore | 2 +- build/download-native-libs.sh | 40 +++++++++++-------- .../pacts/Fulfilment API-Orders API.json | 4 +- src/PactNet/PactNet.csproj | 4 +- .../data/v2-consumer-integration.json | 4 +- .../data/v3-consumer-integration.json | 8 ++-- .../data/v3-message-consumer-integration.json | 4 +- .../data/v3-message-integration.json | 4 +- .../data/v3-server-integration.json | 4 +- .../data/v4-combined-integration.json | 8 ++-- .../data/v4-consumer-integration.json | 8 ++-- .../data/v4-message-consumer-integration.json | 4 +- 12 files changed, 47 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 1b0b07fa..9cc9bc67 100644 --- a/.gitignore +++ b/.gitignore @@ -55,7 +55,7 @@ PactNet/Files/pact/ tools/ build/tools/ build/linux/ -build/osx/ +build/macos/ build/windows/ dist/ diff --git a/build/download-native-libs.sh b/build/download-native-libs.sh index f09c28c6..d39a379d 100755 --- a/build/download-native-libs.sh +++ b/build/download-native-libs.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -FFI_VERSION="0.4.16" +FFI_VERSION="0.4.23" FFI_BASE_URL="https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v$FFI_VERSION" GREEN="\e[32m" @@ -20,45 +20,51 @@ download_native() { # e.g. # pact_ffi-windows-x86_64.dll.gz # libpact_ffi-linux-x86_64.so.gz - # libpact_ffi-osx-x86_64.dylib.gz - src_file="$file-$os-$platform.$extension.gz" - url="$FFI_BASE_URL/$src_file" + # libpact_ffi-macos-x86_64.dylib.gz + src_file="$file-$os-$platform.$extension" + src_archive="$src_file.gz" + src_sha="$src_archive.sha256" + dest_file="$file.$extension" + url="$FFI_BASE_URL/$src_archive" sha="$url.sha256" path="$base_path/$os/$platform" - dest_file="$file.$extension.gz" mkdir -p "$path" + pushd $path > /dev/null echo -e "Downloading FFI library for ${YELLOW}$os/$platform${CLEAR}" - echo -e " Destination: ${BLUE}$path/$dest_file${CLEAR}" + echo -e " Destination: ${BLUE}$path/$src_archive${CLEAR}" echo -e " URL: ${BLUE}$url${CLEAR}" echo -n " Downloading... " - curl --silent -L "$url" -o "$path/$dest_file" - curl --silent -L "$sha" -o "$path/$dest_file.sha256" + curl --silent -L "$url" -o "$src_archive" + curl --silent -L "$sha" -o "$src_archive.sha256" echo -e "${GREEN}OK${CLEAR}" echo -n " Verifying... " if [[ "$OSTYPE" == "darwin"* ]]; then - # OSX requires an empty arg passed to -i, but this doesn't work on Lin/Win - sed -Ei '' "s|../release_artifacts/.+$|$path/$dest_file|" "$path/$dest_file.sha256" - shasum -a 256 --check --quiet "$path/$dest_file.sha256" + shasum -a 256 --check --quiet "$src_sha" else - sed -Ei "s|../release_artifacts/.+$|$path/$dest_file|" "$path/$dest_file.sha256" - sha256sum --check --quiet "$path/$dest_file.sha256" + sha256sum --check --quiet "$src_sha" fi - rm "$path/$dest_file.sha256" echo -e "${GREEN}OK${CLEAR}" echo -n " Extracting... " - gunzip -f "$path/$dest_file" + gunzip -f "$src_archive" echo -e "${GREEN}OK${CLEAR}" echo "" + + mv "$src_file" "$dest_file" + rm "$src_sha" + + popd > /dev/null } download_native "pact_ffi" "windows" "x86_64" "dll" download_native "libpact_ffi" "linux" "x86_64" "so" -download_native "libpact_ffi" "osx" "x86_64" "dylib" -download_native "libpact_ffi" "osx" "aarch64-apple-darwin" "dylib" +download_native "libpact_ffi" "macos" "x86_64" "dylib" +download_native "libpact_ffi" "macos" "aarch64" "dylib" + +echo "Successfully downloaded FFI libraries" \ No newline at end of file diff --git a/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json b/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json index 50b68e5d..24dd275e 100644 --- a/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json +++ b/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json @@ -158,8 +158,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.16", - "models": "1.1.19" + "ffi": "0.4.23", + "models": "1.2.5" }, "pactSpecification": { "version": "4.0" diff --git a/src/PactNet/PactNet.csproj b/src/PactNet/PactNet.csproj index 9085de5d..e62463af 100644 --- a/src/PactNet/PactNet.csproj +++ b/src/PactNet/PactNet.csproj @@ -36,14 +36,14 @@ PreserveNewest false - + libpact_ffi.dylib runtimes/osx-x64/native true PreserveNewest false - + libpact_ffi.dylib runtimes/osx-arm64/native true diff --git a/tests/PactNet.Tests/data/v2-consumer-integration.json b/tests/PactNet.Tests/data/v2-consumer-integration.json index 9f76184a..bee37f6d 100644 --- a/tests/PactNet.Tests/data/v2-consumer-integration.json +++ b/tests/PactNet.Tests/data/v2-consumer-integration.json @@ -74,8 +74,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.16", - "models": "1.1.19" + "ffi": "0.4.23", + "models": "1.2.5" }, "pactSpecification": { "version": "2.0.0" diff --git a/tests/PactNet.Tests/data/v3-consumer-integration.json b/tests/PactNet.Tests/data/v3-consumer-integration.json index fa2df241..6d159b92 100644 --- a/tests/PactNet.Tests/data/v3-consumer-integration.json +++ b/tests/PactNet.Tests/data/v3-consumer-integration.json @@ -96,9 +96,7 @@ } ] } - }, - "header": {}, - "query": {} + } }, "method": "POST", "path": "/things", @@ -132,8 +130,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.16", - "models": "1.1.19" + "ffi": "0.4.23", + "models": "1.2.5" }, "pactSpecification": { "version": "3.0.0" diff --git a/tests/PactNet.Tests/data/v3-message-consumer-integration.json b/tests/PactNet.Tests/data/v3-message-consumer-integration.json index 0c02ff57..a887b4a1 100644 --- a/tests/PactNet.Tests/data/v3-message-consumer-integration.json +++ b/tests/PactNet.Tests/data/v3-message-consumer-integration.json @@ -36,8 +36,8 @@ "language": "C#" }, "pactRust": { - "ffi": "0.4.16", - "models": "1.1.19" + "ffi": "0.4.23", + "models": "1.2.5" }, "pactSpecification": { "version": "3.0.0" diff --git a/tests/PactNet.Tests/data/v3-message-integration.json b/tests/PactNet.Tests/data/v3-message-integration.json index 85ba4363..783a6cf0 100644 --- a/tests/PactNet.Tests/data/v3-message-integration.json +++ b/tests/PactNet.Tests/data/v3-message-integration.json @@ -16,8 +16,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.16", - "models": "1.1.19" + "ffi": "0.4.23", + "models": "1.2.5" }, "pactSpecification": { "version": "3.0.0" diff --git a/tests/PactNet.Tests/data/v3-server-integration.json b/tests/PactNet.Tests/data/v3-server-integration.json index c9b869c0..38675ac1 100644 --- a/tests/PactNet.Tests/data/v3-server-integration.json +++ b/tests/PactNet.Tests/data/v3-server-integration.json @@ -46,8 +46,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.16", - "models": "1.1.19" + "ffi": "0.4.23", + "models": "1.2.5" }, "pactSpecification": { "version": "3.0.0" diff --git a/tests/PactNet.Tests/data/v4-combined-integration.json b/tests/PactNet.Tests/data/v4-combined-integration.json index d42e3ff5..ee46b3f3 100644 --- a/tests/PactNet.Tests/data/v4-combined-integration.json +++ b/tests/PactNet.Tests/data/v4-combined-integration.json @@ -106,9 +106,7 @@ } ] } - }, - "header": {}, - "query": {} + } }, "method": "POST", "path": "/things", @@ -187,8 +185,8 @@ "language": "C#" }, "pactRust": { - "ffi": "0.4.16", - "models": "1.1.19" + "ffi": "0.4.23", + "models": "1.2.5" }, "pactSpecification": { "version": "4.0" diff --git a/tests/PactNet.Tests/data/v4-consumer-integration.json b/tests/PactNet.Tests/data/v4-consumer-integration.json index 11d15825..d706aebe 100644 --- a/tests/PactNet.Tests/data/v4-consumer-integration.json +++ b/tests/PactNet.Tests/data/v4-consumer-integration.json @@ -106,9 +106,7 @@ } ] } - }, - "header": {}, - "query": {} + } }, "method": "POST", "path": "/things", @@ -152,8 +150,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.16", - "models": "1.1.19" + "ffi": "0.4.23", + "models": "1.2.5" }, "pactSpecification": { "version": "4.0" diff --git a/tests/PactNet.Tests/data/v4-message-consumer-integration.json b/tests/PactNet.Tests/data/v4-message-consumer-integration.json index f5124e0e..6dc2bd5e 100644 --- a/tests/PactNet.Tests/data/v4-message-consumer-integration.json +++ b/tests/PactNet.Tests/data/v4-message-consumer-integration.json @@ -41,8 +41,8 @@ "language": "C#" }, "pactRust": { - "ffi": "0.4.16", - "models": "1.1.19" + "ffi": "0.4.23", + "models": "1.2.5" }, "pactSpecification": { "version": "4.0" From 0199f010c82551c018d3b56bc903aefaf6212750 Mon Sep 17 00:00:00 2001 From: Adam Rodger Date: Sun, 8 Sep 2024 14:31:09 +0100 Subject: [PATCH 3/4] feat(verifier): Throw more specific exception when verification fails Resolves #505 --- .../PactVerificationFailedException.cs | 36 +++++++++++++++++++ .../Verifier/InteropVerifierProvider.cs | 2 +- .../Verifier/InteropVerifierProviderTests.cs | 4 +-- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/PactNet.Abstractions/Exceptions/PactVerificationFailedException.cs diff --git a/src/PactNet.Abstractions/Exceptions/PactVerificationFailedException.cs b/src/PactNet.Abstractions/Exceptions/PactVerificationFailedException.cs new file mode 100644 index 00000000..63daa057 --- /dev/null +++ b/src/PactNet.Abstractions/Exceptions/PactVerificationFailedException.cs @@ -0,0 +1,36 @@ +using System; + +namespace PactNet.Exceptions +{ + /// + /// Pact verification failed + /// + [Serializable] + public class PactVerificationFailedException : PactFailureException + { + /// + /// Initializes a new instance of the class + /// + public PactVerificationFailedException() + : this("The pact failed verification") + { + } + + /// + /// Initializes a new instance of the class + /// + /// The message that describes the error + public PactVerificationFailedException(string message) : base(message) + { + } + + /// + /// Initializes a new instance of the class + /// + /// The error message that explains the reason for the exception + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified + public PactVerificationFailedException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/src/PactNet/Verifier/InteropVerifierProvider.cs b/src/PactNet/Verifier/InteropVerifierProvider.cs index a30a5b34..c0245296 100644 --- a/src/PactNet/Verifier/InteropVerifierProvider.cs +++ b/src/PactNet/Verifier/InteropVerifierProvider.cs @@ -235,7 +235,7 @@ public void Execute() string error = result switch { - 1 => "Pact verification failed", + 1 => throw new PactVerificationFailedException("Pact verification failed"), 2 => "Failed to run the verification", _ => $"An unknown error occurred: {result}" }; diff --git a/tests/PactNet.Tests/Verifier/InteropVerifierProviderTests.cs b/tests/PactNet.Tests/Verifier/InteropVerifierProviderTests.cs index 5a8d5088..91d4b023 100644 --- a/tests/PactNet.Tests/Verifier/InteropVerifierProviderTests.cs +++ b/tests/PactNet.Tests/Verifier/InteropVerifierProviderTests.cs @@ -53,7 +53,7 @@ public void HappyPathIntegrationTest() Action action = () => provider.Execute(); - action.Should().Throw(); + action.Should().Throw(); } [Fact] @@ -73,7 +73,7 @@ public void SetPublishOptions_NoBuildUri_IsValid() Action action = () => provider.Execute(); - action.Should().Throw(); + action.Should().Throw(); } } } From 8f98cb5b7bc8addf980e8fc63960d943cd5302e4 Mon Sep 17 00:00:00 2001 From: Adam Rodger Date: Sun, 8 Sep 2024 14:46:22 +0100 Subject: [PATCH 4/4] fix(ci): Cache FFI deps properly after packaging change --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42c6291e..e18b5204 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: enableCrossOsArchive: true path: | build/linux - build/osx + build/macos build/windows - name: Pull interop dependencies