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

Support matching multiple occurrences of a query parameter exactly #165

Open
mgoltzsche opened this issue Jun 11, 2021 · 0 comments
Open

Comments

@mgoltzsche
Copy link

mgoltzsche commented Jun 11, 2021

Software versions

  • OS: linux
  • Consumer Pact library: Pact go v1.5.3
  • Provider Pact library: Pact go v1.5.3
  • Golang Version: 1.15

Expected behaviour

The pact go library should allow to exactly match multiple occurrences of the same query parameter as it is supported within pact files and by libraries for other platforms as shown e.g. here.

Actual behaviour

The Pact go library doesn't support matching multiple values of the same query parameter precisely.

Steps to reproduce

pact.
  AddInteraction().
  Given("Some state").
  UponReceiving("A request with multiple occurrences of a query parameter").
  WithRequest(dsl.Request{
    Method: "GET",
    Path: dsl.String("/api/v1/resource"),
    Query: dsl.MapMatcher{
      "myparam": dsl.Like([]string{"value1", "value2"}),
    },
  }).
  ...

Unfortunately this doesn't work because the query parameter values are treated as a nested slice resulting in this diff within the consumer test log:

 {
   "query": {
     "myparam": [
-      [
-        "value1",
-        "value2",
-      ],
+      "value1",
+      "value2",
     ]
   }
 }

Actually I'd like to specify the parameters like this:

    ...
    Query: dsl.MapMatcher{
      "myparam": []string{"value1", "value2"},
    },
    ...

However the Pact Go DSL doesn't allow me to do so since it requires me to provide a Matcher for the value but there is no matcher to precisely match an array. Supporting such a matcher could be a solution to this problem.

Workaround

A workaround is to match the query parameter values in a less precise way using dsl.EachLike:

    ...
    Query: dsl.MapMatcher{
      "myparam": dsl.EachLike(dsl.Term("value1", "value1|value2"), 2),
    },
    ...
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

2 participants