Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for publishing verification results with branches #151

Closed
bethesque opened this issue Sep 29, 2021 · 12 comments
Closed

Add support for publishing verification results with branches #151

bethesque opened this issue Sep 29, 2021 · 12 comments
Assignees

Comments

@bethesque
Copy link
Member

bethesque commented Sep 29, 2021

This change allows the provider version associated with verification results to be created with a branch.

  • Add a "branch" option to the API exposed to the users
  • When fetching the pacts for verification, set the branch as providerVersionBranch in the request.
  • When publishing the verification results, before creating the tags, send a PUT using the pb:branch-version relation from the provider resource (with params branch and version), or the pb:pacticipant-branch-version relation from the index (with params pacticipant, branch and version).
  • If the branch is set, and the broker does not support branches (ie. the relations are not there), raise an appropriate error (or print warning - which ever works best for rust) indicating that the broker does not support branches, and they should update to Pact Broker version 2.86.0 or later for branch support.

Sorry to add yet another call to the results publishing! I imagine the rust code for publishing verification results looks about as bad as the ruby code does now 😆 There will be an "all in one" verification results publishing endpoint coming at some stage, but I don't want to wait for that to be done before we can get people using branches.

@mefellows
Copy link
Member

We already support branch in the selectors, does this mean it will automatically flow in the verification results publish, or does that need to be passed in to that API somehow?

There is a tiny Pact CLI in rust that supports publishing pacts, albeit I'm not sure we want it personally. We have enough things to maintain!

@bethesque
Copy link
Member Author

We already support branch in the selectors, does this mean it will automatically flow in the verification results publish, or does that need to be passed in to that API somehow?

That's for the consumer version. The change is to set the branch for the provider version. But that reminds me, it also needs to be sent in the 'pacts for verification' call. I'll update the original comment.

@mefellows mefellows self-assigned this Sep 29, 2021
@mefellows
Copy link
Member

I've started picking this up. Note to myself on testing:

publish a pact with a branch, use consumer version selectors with a branch, publish a verification with a branch, then look at the matrix page

@mefellows
Copy link
Member

mefellows commented Sep 29, 2021

@bethesque so I have a consumer where I have published with a branch:

pact-broker publish ${PWD}/pacts --consumer-app-version ${GIT_COMMIT} --branch ${GIT_BRANCH}
...
Created version aa2dccc+1632918640 of pactflow-example-consumer (branch master)
Publishing pactflow-example-consumer/pactflow-example-provider-dredd pact to pact broker at https://testdemo.pactflow.io
The latest version of this pact can be accessed at the following URL:
https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-dredd/consumer/pactflow-example-consumer/latest

But whenever I query via the pacts for verification endpoint, there are never any results:

curl --location --request POST 'https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-dredd/for-verification' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ********** ' \
--data-raw '{
    "consumerVersionSelectors": [
        {
            "branch": "master"
        }
    ],
    "providerVersionBranch": "main",
    "includePendingStatus": true,
    "includeWipPactsSince": "2020-01-01"
}'

API Response:

{
    "_embedded": {
        "pacts": []
    },
    "_links": {
        "self": {
            "href": "https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-dredd/for-verification",
            "title": "Pacts to be verified"
        }
    }
}

I assume I'm doing something wrong. I've read https://github.com/pact-foundation/pact_broker/blob/master/lib/pact_broker/doc/views/provider-pacts-for-verification.markdown but can't see what I'm doing wrong. This is also true of the deployed selector. When I revert back to tag things work again - any pointers?

@mefellows
Copy link
Member

OK, so after a sleep I realised that I'd only been testing a bi-directional contract provider. Changing to the standard Pact provider, it works. Moving on for now...

@mefellows
Copy link
Member

mefellows commented Sep 30, 2021

Looks like it does the trick:

02:54:10 [INFO] Publishing verification results back to the Pact Broker
02:54:10 [DEBUG] (1) pact_verifier: Publishing a failure result to PactBroker(https://testdemo.pactflow.io, provider_name='pactflow-example-provider-springboot')
02:54:10 [INFO] Fetching path '/pacticipants/pactflow-example-provider-springboot' from pact broker
02:54:10 [DEBUG] (1) reqwest::connect: starting new connection: https://testdemo.pactflow.io/
02:54:10 [DEBUG] (1) rustls::client::hs: No cached session for DNSNameRef("testdemo.pactflow.io")
02:54:10 [DEBUG] (1) rustls::client::hs: Not resuming any session
02:54:10 [DEBUG] (1) rustls::client::hs: ALPN protocol is Some(b"h2")
02:54:10 [DEBUG] (1) rustls::client::hs: Using ciphersuite TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
02:54:10 [DEBUG] (1) rustls::client::hs: Server supports tickets
02:54:10 [DEBUG] (1) rustls::client::tls12: ECDHE curve is ECParameters { curve_type: NamedCurve, named_group: secp256r1 }
02:54:10 [DEBUG] (1) rustls::client::tls12: Server DNS name is DNSName("testdemo.pactflow.io")
02:54:10 [DEBUG] (1) rustls::client::tls12: Session saved
02:54:10 [DEBUG] (1) reqwest::async_impl::client: response '200 OK' for https://testdemo.pactflow.io/pacticipants/pactflow-example-provider-springboot
02:54:10 [DEBUG] (1) pact_verifier::pact_broker: templated URL = https://testdemo.pactflow.io/pacticipants/pactflow-example-provider-springboot/branches/{branch}/versions/{version}
02:54:10 [DEBUG] (1) pact_verifier::pact_broker: Looking up value for key 'branch'
02:54:10 [DEBUG] (1) pact_verifier::pact_broker: Looking up value for key 'version'
02:54:10 [DEBUG] (1) pact_verifier::pact_broker: final URL = https://testdemo.pactflow.io/pacticipants/pactflow-example-provider-springboot/branches/foo/versions/1.0.0
02:54:10 [DEBUG] (1) pact_verifier::pact_broker: Sending JSON to https://testdemo.pactflow.io/pacticipants/pactflow-example-provider-springboot/branches/foo/versions/1.0.0 using PUT: {}
02:54:11 [DEBUG] (1) reqwest::async_impl::client: response '200 OK' for https://testdemo.pactflow.io/pacticipants/pactflow-example-provider-springboot/branches/foo/versions/1.0.0
02:54:11 [DEBUG] (1) pact_verifier::pact_broker: Pushed branch foo for provider version 1.0.0
02:54:11 [DEBUG] (1) pact_verifier::pact_broker: Sending JSON to https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-springboot/consumer/pactflow-example-consumer-java-junit/pact-version/962996774330b571104b62713a51b433626b9c9b/metadata/c1tdW2JdPW1hc3RlciZzW11bbF09dHJ1ZSZzW11bY3ZdPTI3MTU5JnA9ZmFsc2U/verification-results using POST: {"providerApplicationVersion":"1.0.0","success":false,"testResults":[{"interactionId":"404249f54d348484168670b62849413556edfafc","success":true},{"interactionId":"ba08b56e3fecb8a49c7f7a2d509d9fe3183a44cf","mismatches":[{"attribute":"status","description":"expected 404 but was 200"}],"success":false},{"interactionId":"c2f17b767dc87e687fae00aa6e8c09ffa8b799f4","success":true},{"interactionId":"e9c670b824fc598496a4281b481f01069a94c9ec","success":true},{"interactionId":"807afa8ea1392d2bd4b4b0b12dbf1636e8f07097","success":true}],"verifiedBy":{"implementation":"Pact-Rust","version":"0.1.5"}}
02:54:11 [DEBUG] (1) reqwest::async_impl::client: response '201 Created' for https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-springboot/consumer/pactflow-example-consumer-java-junit/pact-version/962996774330b571104b62713a51b433626b9c9b/metadata/c1tdW2JdPW1hc3RlciZzW11bbF09dHJ1ZSZzW11bY3ZdPTI3MTU5JnA9ZmFsc2U/verification-results
02:54:11 [INFO] Results published to Pact Broker

Screen Shot 2021-09-30 at 12 56 47 pm

@bethesque
Copy link
Member Author

Wonderful!

@bethesque
Copy link
Member Author

Ok, giving this some more thought, I can't see why the provider being bi-directional would make a difference. The pacts for verification endpoint doesn't know or care about bi-directional. We'll have to keep an eye on this as we roll out bi-directional.

@bethesque
Copy link
Member Author

pact-broker publish ${PWD}/pacts --consumer-app-version ${GIT_COMMIT} --branch ${GIT_BRANCH}
...
Created version aa2dccc+1632918640 of pactflow-example-consumer (branch master)
Publishing pactflow-example-consumer/pactflow-example-provider-dredd pact to pact broker at > https://testdemo.pactflow.io
The latest version of this pact can be accessed at the following URL:
https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-dredd/consumer/pactflow-example-consumer/latest

That looks like it's publishing with the old API, not the new one. Maybe the other consumer used a newer version of the CLI?

@mefellows
Copy link
Member

I think the PR is merged, but not yet released. Once the next FFI lib version is released we can close this off, and it will be available to all clients.

@mefellows
Copy link
Member

pact-broker publish ${PWD}/pacts --consumer-app-version ${GIT_COMMIT} --branch ${GIT_BRANCH}
...
Created version aa2dccc+1632918640 of pactflow-example-consumer (branch master)
Publishing pactflow-example-consumer/pactflow-example-provider-dredd pact to pact broker at > https://testdemo.pactflow.io
The latest version of this pact can be accessed at the following URL:
https://testdemo.pactflow.io/pacts/provider/pactflow-example-provider-dredd/consumer/pactflow-example-consumer/latest

That looks like it's publishing with the old API, not the new one. Maybe the other consumer used a newer version of the CLI?

I'll take a look and try it from scratch. Perhaps one of the examples was out of date or I needed to pull a fresh image.

@adamrodger
Copy link
Contributor

I think this can be closed - this was implemented in PactNet using an updated FFI so that support is now there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants