pact-foundation / pact-net

.NET version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
846 stars 232 forks source link

Ruby still needed? #403

Closed dbro04 closed 2 years ago

dbro04 commented 2 years ago

It is very cool, that pact 4.0 doesn't use ruby anymore. But how can I upload a contract to pact broker without ruby on windows? The pact cli still uses ruby and I have to get the old pact.net windows nuget package or I have to use node and get this working in my CI. Why is there no windows pact broker upload without ruby?

mefellows commented 2 years ago

We are constantly improving and changing the APIs that support integration with the Pact Broker (such as publishinsg) and having to implement the behaviour in every language/client is inefficient.

We provide CLI tools as both a downloadable CLI and Docker container to perform common functionality such as this.

adamrodger commented 2 years ago

Yep, as @mefellows says, the officially recommended way to upload pact files is via the CLI at the end of your CI run.

The problem with trying to support file uploads as part of PactNet itself is that you should only upload the file as long as all the consumer tests have passed. That's a tricky thing to do, because the tests for a single provider/consumer pair may be spread across multiple test collections. That puts an onus on the user to use things like xUnit test collections to ensure that all the tests run together, and if the user gets that wrong then it can cause major problems (such as uploading a partial pact file).

That can't really be detected automatically from PactNet, so the only way the user can know that the upload had effectively done the wrong thing would be to inspect the contents manually afterwards, and obviously that not a great developer experience.

The other problem is that creating shared fixtures to ensure that the upload only happens at the end is also problematic when tests fail. The cleanup code always runs, even when tests have failed, but you only want to upload your pact file if all consumer tests passed.

So, instead, the recommended way is to run one step in your CI which executes all your consumer tests (no need to put them in fixtures/collections in PactNet 4.x because the file is written in merge mode always), and then a subsequent step uploads the file(s) using the CLI. That way, the upload step will only run if the entire test run passed, so you don't end up uploading incomplete pact files.

dbro04 commented 2 years ago

I agree with @adamrodger , but 1 have 2 problems with this: 1.If I use the standalone cli. I will still get ruby on my machines.

  1. There is no nuget package for cli standalone.
adamrodger commented 2 years ago

You can use the new Rust CLI if you don't want Ruby on your machine at all.

We can't really supply a NuGet for the CLI since that's not what NuGet is for. You could look to create a Chocolatey or Scoop package for it if you need that, or if not then either use the Docker container or add the exe to your CI manually

bethesque commented 2 years ago

You can use the new Rust CLI if you don't want Ruby on your machine at all.

The Rust CLI does not support interactions with the Pact Broker. If you don't want Ruby on your machine, you'll need to use the Docker image of the Pact CLI (which has Ruby in it 😆 but you won't need to see it)