-
-
Notifications
You must be signed in to change notification settings - Fork 288
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
HaveJSONPath matcher proposal #637
Comments
Mentioned on the other thread, a third way of writing this would be Eventually(k.Object(deployment)).Should(HaveField("Status.Conditions",
ContainElement(SatisfyAll(
HaveField("Type", Equal("Available")), // Find the condition of type Available
HaveField("Reason", Equal("MinimumReplicasAvailable")), // Check the Reason
)),
)) which may be preferred over the previous example with |
hey there - @JoelSpeed 's correct that there are simpler ways to pull off matchers like this without needing to use With that said, I love the idea of adding also - is there a JSONPath dependency this would rely on - and if so, what do you have in mind? or would you be implementing a parser? (both are fine, just wanting to understand). I see that the PR you linked to above uses an implementation in the k8s go-client util directory which would be an awkward dependency to pull in vs a standalone implementation of lastly - it doesn't look like there's a formal JSONPath specification - and I notice that the k8s-specific JSONPath support requires enclosing the JSONPath query in |
I like the idea that The how and when I'm not too sure of, but I definitely agree it should follow the specification when formalised and I think ideally should use a well maintained library. Maybe it would make most sense to revisit this once the specification is formalised? |
Hi, I originally raised this PR kubernetes-sigs/controller-runtime#2174 which added a new matcher to a custom matcher library for Kubernetes however it was suggested that it might have wider benefits in the Gomega project itself. Just checking to see if there's any interest here.
The
HaveJSONPath
matcher works similarly to theHaveField
matcher however it has the added benefit of JSON path expressions. This enables a simplified method of traversing complex structs and matching against specific fields.For example, where
k.Object
is a helper function that polls an API and updates the contents ofdeployment
:With
HaveJSONPath
:example JSON of
deployment
when marshalled:HaveJSONPath
also supports returning structs or slices for assertions and should work with any struct.The text was updated successfully, but these errors were encountered: