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

Verify on HTTP::uri after mocking HTTP::uri #22

Closed
Espenhh opened this issue Oct 14, 2013 · 2 comments
Closed

Verify on HTTP::uri after mocking HTTP::uri #22

Espenhh opened this issue Oct 14, 2013 · 2 comments
Assignees

Comments

@Espenhh
Copy link

Espenhh commented Oct 14, 2013

I'm using "on" to mock an incoming URI, and then my iRule changes this URI (removing a prefix) before sending it to the backend server. I want to test that the resulting URI is right, but this is a problem since I've already mocked out "HTTP::uri".

I've solved it by doing the verify on HTTP::path instead, but that feels like a hack. Any way to solve this?

Example iRule:

rule http {
    when HTTP_REQUEST {
        set newuri [string map {/api/ /} [HTTP::uri]]
        HTTP::uri $newuri
    }
}

Example test:

package require -exact testcl 1.0.2
namespace import ::testcl::*

# Comment in to enable logging
#log::lvSuppressLE info 0

it "should remove '/api' from URI" {
    event HTTP_REQUEST

    on HTTP::uri return "/api/users"

    ## This verify doesn't work:
    verify "result uri is '/users'" "/users" eq {HTTP::uri}

    ## This is the temporary solution I've used:
    verify "result path is '/users'" "/users" eq {HTTP::path}

    run rules/1.tcl http
}
@Sebastian-Brzuzek
Copy link
Contributor

in this case it will be easier to use:
HTTP::uri "/api/users"
instead of
on HTTP::uri return "/api/users"

"on" is fine if you need simple value substitution for whole irule statements, but if you need to verify if actual iRule logic is working it is better to use HTTP stub methods.

@Espenhh
Copy link
Author

Espenhh commented Oct 14, 2013

Thanks, that worked perfectly 👍

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

No branches or pull requests

2 participants