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 conformance tests for ignore_empty #126

Merged
merged 3 commits into from
Nov 6, 2023

Conversation

rodaine
Copy link
Member

@rodaine rodaine commented Nov 3, 2023

Following #124, this adds conformance tests that ensure the ignore_empty rules is consistent with required. Mainly, if a field cannot differentiate between unset and the zero value (i.e., is not nullable), then this rule applies; effectively this is just repeated and map fields, as well as non-optional proto3 scalar outside of a oneof.

Running against protovalidate-go, a few places where ignore_empty should be a noop ends up disabling evaluations. This will be a minor follow-up fix in that library. Patches for the other libraries will follow to bring them into conformance with these tests and those in #124.

Comment on lines +48 to +49
Message: &cases.IgnoreEmptyProto2ScalarOptionalWithDefault{Val: proto.Int32(42)},
Expected: results.Success(true),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that this and the case above on line 39 have the same outcome makes this ambiguous: is this passing because the explicit value is greater than zero (per validation rule) or is it passing because it the default value is considered "empty" and so the validation rule is skipped?

If it is meant to be the latter, a non-conformance implementation could still pass the conformance test case due to the former. So I think this needs to be reformulated to better suss out non-conforming implementations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since optional is nullable, it's a noop for this rule regardless. There's a "nonzero" rule above that is neither the default and not zero that captures that case. I will add tests with a negative value which I think is what will cover the remaining missing range of behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Said another way setting a default doesn't matter for this rule.

@rodaine rodaine merged commit 56ee282 into main Nov 6, 2023
3 checks passed
@rodaine rodaine deleted the rodaine/ignore_empty_conformance branch November 6, 2023 17:29
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

Successfully merging this pull request may close these issues.

5 participants