I’m testing a restful service.
There are four ways it can be interacted with:
- Regular authenticated user through the Layer7 network layer
- Trusted Client through Layer7
- Regular, direct to application server
- Trusted, direct to server
The difference between those test conditions are in the queryParams and Headers that get sent.
The Layer7 is controlled by config. The whole test execution is either one way, or the other. So I could add conditional execution to return a different http() request with the appropriate headers applied. So far, so good. Perhaps ugly and painful, but doable.
The Trusted vs. Regular depends on characteristics of the user in the feed. Which means I have to decide at run time whether to add a queryParam to the request.
Solution 1:
`
.doIfElse( session => session( SOME_VAR ).as[String] == “someValue” ) {
http( desc )
.get( url )
.queryParam( “foo”, “bar” )
…
} {
http( desc )
.get( url )
…
}
`
That smacks of a major violation of the DRY principle, and is not very expressive of the real intent. On top of that, you can’t save that into a val and use it in a resources() call.
For my particular need, I can just do something like this:
`
http( desc )
.get( url + “${QUERY_PARAMS}” )
`
Then at the moment when I know if I need to add the universal query parameters or not, I can just set the value of QUERY_PARAMS to an empty string, or to “?foo=bar” and hope that any subsequent calls to .queryParam() will do the right thing.
If I had my way, it would read something more like this:
http( desc ) .get( url ) .if( session => true ) { queryParam( "foo", "bar" ) } // or .queryParamIf( session => true, "foo", "bar" )
But that’s going to require some serious DSL extensions to get something like that built. And naturally, it needs to support .param, .queryParam, and maybe even .check
I have the feeling that conditionals within http requests would benefit more than just me. So I wanted to throw that out there as something to think about and discuss and plan out.
Thoughts? Opinions?