-
Notifications
You must be signed in to change notification settings - Fork 5
Add unification assertion mode #23
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
base: main
Are you sure you want to change the base?
Add unification assertion mode #23
Conversation
Signed-off-by: Njal Karevoll <[email protected]>
…/usage Signed-off-by: Njal Karevoll <[email protected]>
358ad76
to
f63d1d3
Compare
Thanks for the PR @nkvoll - after our brief conversation, I thought some more about this. I think if you squint hard, "diff mode" is really a "unification mode" for the entire response instead of just a cherry-picked subset. I wondered if there would be a way to get rid of the modes and have the test do the right thing in all cases, printing diffs when unification fails. It's just a kernel of an idea at this point but maybe we can flesh out how this would work? One problem in unification mode is that if I add a random resource in the response, it will successfully unify right? I'm thinking of a typo where the test says That is, even in unification mode we need to guard against misspelt resources and ensure that the resource name actually exists in the cue output response. So it all feels like we should be having a single way to write assertions that work correctly with partial as well as full responses. |
You'd get some error like this (tried):
In this, There is a test in this PR that validates that extra fields within a resource results in an error (and the same facility also catches any higher-leveled keys that are not in the actual response as well. |
Cool. I missed that nuance. Since every "diff" mode test is also a valid "unification" mode test, we can support a different annotation like, say, I think being able to specify partial responses should be the default mode of operation going forward so that unit tests are truly like, er, unit tests :) |
In fact there is a third mode of operation where a test writer would be able to add a Not suggesting we implement this in this PR but it allows for that possibility. |
foo: "bar" | ||
} | ||
|
||
#mode: "unification" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was left in as an omission, based on thinking around whether it would be nicer to represent it as a definition instead of an attribute. An attribute leads itself nicer to partial unification as mentioned in another top-level PR comment.
Adds a way of asserting via unification instead of diffing in tests.
Diffing always requires including the full desired output in the test, which for some use-cases may obfuscate the point the test is trying to show.
Unification allows to assert on just a sub-set of the complete object and leverages Cue itself to validate that the actual matches the expected output. This may of course lead to a scenario that not all of the output has been validated in each individual test, but makes it easier to see the effects the test-case is stressing.