Skip to content

Commit

Permalink
doc: Add docs on matching on maps to the README
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Feb 7, 2024
1 parent 3f369a9 commit 131ffc4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,45 @@ builder
))
```

### Matching repeated fields

You can apply matching rules to enforce the minimum or maximum number fo fields, as well as applying rules for each
item.

For instance, assume that `numbers` is a repeated String field. You could define
```json
"numbers": "atLeast(1), eachValue(matching(regex, '\\d+', '100))"
```
This will make aure that there is always at least one number, and that any numbers match the given regular expression.

**Note: `atLeast` and `atMost` require version 0.3.12+**

This would also work if `numbers` was a numeric repeated field. In fact, it would work with any primitive field by
applying the regex to the string representation of the field value.

### Matching on map fields

With maps, you can apply matching rules on either the keys in the map, or the values, or both. For instance, given
```protobuf
message ExampleRequest {
map<string, string> labels = 1;
bool ok = 2;
}
```

You could define a test like
```json
"request": {
"labels": {
"pact:match": "eachKey(matching(regex, '\\d+', '')), eachValue(matching(regex, '(\\w|\\s)+', '')), atLeast(1)",
"100": "this is a label"
},
"ok": "true"
}
```
This will require the map of labels to only have keys and values that match the given regular expressions, and the map
must have at least one entry. `"100": "this is a label"` is the example value used in the consumer test.

## Running within docker containers

The plugin will try to use an IP6 address when opening the port for the gRPC server. Docker will only support IP6
Expand Down

0 comments on commit 131ffc4

Please sign in to comment.