pact-foundation / pact-jvm

JVM 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://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

WARNING: Pact file has no interactions with pact-verify in Leiningen plugin #1372

Open jarmy opened 3 years ago

jarmy commented 3 years ago

I have a pact that is using pact-specification 2.0 that I'm trying to verify with the au.com.dius.pact.provider/lein "4.1.20" plugin. When we run the pact-verify task, we get the following message:

% ./lein with-profile pact pact-verify

Verifying a pact between :graphql and :sod
  [from URL https://pact-broker.docker.savagebeast.com]
         WARNING: Pact file has no interactions
% ./lein --version
Leiningen 2.6.1 on Java 1.8.0_272 OpenJDK 64-Bit Server VM

Here's the clojure/lein definition:

  :profiles {:pact {:plugins [[au.com.dius.pact.provider/lein "4.1.20" :exclusions [commons-logging]]]}}
  :pact {
         :service-providers {
             :sod {
                 :protocol "http"
                 :host "localhost"
                 :port 3000
                 :has-pact-with {
                     :graphql {
                               :pact-source "https://pact-broker.docker.savagebeast.com"
                               }
                     }
                 }
             }
         }

And the pact file we're trying to verify:

{
  "consumer": {
    "name": "graphql"
  },
  "provider": {
    "name": "sod"
  },
  "interactions": [
    {
      "description": "POST request for search on demand results",
      "request": {
        "method": "POST",
        "path": "/sod/jsonrpc",
        "headers": {
          "Accept": "application/json"
        },
        "body": {
          "jsonrpc": "2.0",
          "method": "sod-v3.search",
          "params": [
            "jamiro",
            [
              "AR",
              "TR"
            ],
            {
              "listenerId": "399"
            },
            0,
            20,
            false
          ]
        }
      },
      "response": {
        "status": 200,
        "headers": {
        },
        "body": {
          "jsonrpc": "2.0",
          "id": "null",
          "result": {
            "annotations": {
            },
            "results": [
              "AR:1483",
              "AR:431482",
              "TR:5761576",
              "AR:4553512",
              "AR:5276999",
              "AR:1291911",
              "AR:3183539",
              "AR:2587975",
              "AR:4804250",
              "AR:4099386",
              "TR:13374694",
              "AR:683520",
              "TR:5164843",
              "AR:3585588",
              "AR:1311776",
              "AR:220003",
              "TR:13647594",
              "TR:5973496",
              "AR:853471",
              "AR:2076170"
            ]
          }
        },
        "matchingRules": {
          "$.body.result": {
            "match": "type"
          },
          "$.body.result.annotations": {
            "match": "type"
          },
          "$.body.result.results": {
            "match": "type"
          }
        }
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}
uglyog commented 3 years ago

I'm not able to replicate this. See my test project here: https://github.com/uglyog/pact-lein-test

In that project, I started the broker using docker-compose, published your pact to it, and the ran the verify and it worked as expected.

$ lein with-profile pact pact-verify

Verifying a pact between :consumer1 and :provider1
  [from URL http://localhost:9292/pacts/provider/sod/consumer/graphql/version/1.0.3]
  POST request for search on demand results
      Request Failed - Connect to localhost:5050 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

NOTE: Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')

Failures:

1) Verifying a pact between :consumer1 and :provider1 - POST request for search on demand results

    1.1)       Connect to localhost:5050 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

Note that I've given the full URL to the Pact file in the broker.

uglyog commented 3 years ago

Oh, I see the issue. You're pointing to the root of the broker. Let me add support for that.

uglyog commented 3 years ago

I'm trying to enable this for you, but I need to enable debug logs with Leiningen. I can't work out how to do this.

You will have to use the full URL to the Pact in the broker.

jarmy commented 3 years ago

Aha, very nice! I was able to get the test to run using :pact-source "https://pact-broker.docker.savagebeast.com/pacts/provider/sod/consumer/graphql/latest"

./lein with-profile pact pact-verify

Verifying a pact between :graphql and :sod
  [from URL https://pact-broker.docker.savagebeast.com/pacts/provider/sod/consumer/graphql/latest]
  POST request for search on demand results
    returns a response which
      has status code 200 (OK)
      has a matching body (OK)