aviaviavi / curl-runnings

A declarative test framework for quickly and easily writing integration tests against JSON APIs.
MIT License
158 stars 13 forks source link

How to validate complex object responses #58

Open humbienri opened 4 years ago

humbienri commented 4 years ago

Hello,

Perhaps I am just not getting it, even after having read the example-spec.yaml example. How can I validate a more complicated response body/payload. For example, something like:

{
    "status": "ok",
    "info": {
        "stats": {
            "status": "up",
            "serviceName": "service.name",
            "version": "1.0.11"
        },
        "aConnector": {
            "status": "up"
        }
    },
    "details": {
        "stats": {
            "status": "up",
            "serviceName": "service.atyours",
            "version": "1.0.1"
        },
        "theConnector": {
            "status": "up"
        }
    }
}

I guess I am referring to nesting of json objects so as to confirm that the response body conforms to something more specific. Notice how some of those status keys are duplicated so it's not just a matter of validating that the "status up" exists somewhere in the response, but specifically.

Thanks!

aviaviavi commented 4 years ago

Hi @humbienri, you are correct that this more complex sort of matching is not cleanly supported by curl-runnings right now. You could check that details or info are the exact thing you're expecting, but not much more than that if you have such a similar payload in both spots.

This is something I have been meaning to add, but haven't had the need yet and you're the first to ask for it. 😄 I'll think on ways to implement this, I think there are some relatively lightweight solutions like allowing you to supply a traversal path to run the matcher at.

To make sure I am accounting for what you have in mind, can you give me an example or two of something you're trying to assert about this payload you shared?

humbienri commented 4 years ago

Hello,

I was envisioning doing something like jsonschema validation to a response payload. For example, https://davidwalsh.name/json-validation

be able to specify keys and structure pretty tightly yet not specify hard coded or fixed values but types of values, like strings or numbers, etc.

aviaviavi commented 4 years ago

I really the idea of type checking against a json schema. Probably won't be too hard to add. Making a separate issue for that to track it.