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

eachValue matcher not working as expected #22

Open
rholshausen opened this issue Apr 4, 2023 · 12 comments
Open

eachValue matcher not working as expected #22

rholshausen opened this issue Apr 4, 2023 · 12 comments
Labels
bug Something isn't working smartbear-supported Issues with this label have been added to the Pactflow team's Jira backlog

Comments

@rholshausen
Copy link
Contributor

Original issue: pact-foundation/pact-plugins#22

eachValue matcher for checking list of items not working as expected.

"item": ['somevalue1', 'somevalue2']
"item": "eachValue(matching(type, '00000000000000000000000000000000'))"

Getting below error from pact-plugin:

pact_protobuf_plugin::mock_service: Failed to match the request message - BodyMismatches({"$.item": [BodyMismatch { path: "$.item[0]", expected: Some(b""), actual: Some(b"00000000000000000000000000000000"), mismatch: "Unable to match '' using EachValue(MatchingRuleDefinition { value: \"00000000000000000000000000000000\", value_type: Unknown, rules: [Left(Type)], generator: None })" }]})
@rholshausen rholshausen added the bug Something isn't working label Apr 4, 2023
@mefellows mefellows added smartbear-supported Issues with this label have been added to the Pactflow team's Jira backlog and removed smartbear-supported Issues with this label have been added to the Pactflow team's Jira backlog labels May 21, 2023
@github-actions
Copy link

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-1017). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

rholshausen added a commit that referenced this issue Jun 6, 2023
@rholshausen
Copy link
Contributor Author

0.3.2 released with this fix

@jasonltaylor
Copy link

@rholshausen It looks like there may still be an issue with nesting? Or could be user error on my part. Once I add the eachValue to the permissions field below (where permissions is just a repeated string):

		"response": {
			"resource_permissions": {
				"pact:match": "eachValue(matching($'ResourceUserPermission'))",
				"ResourceUserPermission": {
					"resource": {
						"application_resource": "matching(type, 'foo')",
						"permissions": "eachValue(matching(type, 'foo'))",
						"groups": ["bar"]
					},
					"effect": {
						"result": "ENFORCE_EFFECT_ALLOW"
					}
				}
			}
		}

I run into an error:

2023-06-14T16:14:46.396606Z ERROR ThreadId(01) pact_ffi::plugins: Failed to call out to plugin - "*" is not allowed in an identifier in path expression "$.resource_permissions*.resource.permissions" at index 22

@mefellows
Copy link
Contributor

That's an interesting syntax. Ron is there something in Pact Go I need to support differently to allow this scenario?

@rholshausen
Copy link
Contributor Author

No, that should be all handled in the plugin

@rholshausen
Copy link
Contributor Author

This bit is wrong resource_permissions*, it is not setting the matching rule correctly.

@rholshausen
Copy link
Contributor Author

Ok, try 0.3.3.

@jasonltaylor
Copy link

@rholshausen With 0.3.3, still seeing an issue with regex:

"groups": "eachValue(matching(regex, '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|\\*', '00000000000000000000000000000000'))"

Looks like it may be adding double quotes to the string?

$.resource_permissions[9].resource.groups -> Expected '3:(groups, LengthDelimited, String) = "*"' to match '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|\*'

If I intentionally mismatch without a eachValue I don't see the double quotes in the error:

$.resource_permissions[9].resource.groups[0] -> Expected '*' to match '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'

@jasonltaylor
Copy link

Actually, I guess it looks more like it is just pulling in some metadata/not parsing out the value properly?

@rholshausen
Copy link
Contributor Author

Ah, that is a bug with the Pact libs: pact-foundation/pact-reference#283. It will need the Pact libs to be released and then we can update the plugin.

@rholshausen
Copy link
Contributor Author

3rd time the charm? Try 0.3.4

@jasonltaylor
Copy link

Is working with 0.3.4 - tx!

opicaud pushed a commit to opicaud/pact-protobuf-plugin that referenced this issue Sep 6, 2023
opicaud pushed a commit to opicaud/pact-protobuf-plugin that referenced this issue Sep 6, 2023
opicaud pushed a commit to opicaud/pact-protobuf-plugin that referenced this issue Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working smartbear-supported Issues with this label have been added to the Pactflow team's Jira backlog
Projects
None yet
Development

No branches or pull requests

3 participants