landro / TesTcl

when you don't have the balls to test your F5 BIG-IP iRules directly in production
https://testcl.com
BSD 3-Clause "New" or "Revised" License
98 stars 30 forks source link

event priority support #29

Closed samstep closed 10 years ago

samstep commented 10 years ago

Hi, I would like to request the ability to support events with priorities, e.g.:

when priority nnn

As per F5 documentation priorit could be a number between 1-1000 (500 is the default value if priority is omitted)

Here is what happens when I try to test an iRule with priority set in TesTcl 1.0.5:

error Expected return code 200 from calling when, got 1 error Error info: wrong # args: should be "when event body" error while executing error "when HTTP_REQUEST priority 100 {

TesTcl should understand if there are multiple event handlers for an event (e.g HTTP_REQUEST) with different priorities and handle the test cases correctly in the order of priority

landro commented 10 years ago

Quite easy to implement support for tolerating optional arguments (so it won't crash). Handling side effects is more difficult. Currently there is no support for chaining irules (or different when command calls). Would you be able to provide a real world example irule file and attach it here, @samstep ?

landro commented 10 years ago

@samstep , can you please try out this branch, and see if it works as expected?

samstep commented 10 years ago

Hi @landro - Itried it and modified it a bit. It has unnecessary "elseif/else" block in my opinion and can be rewritten as:

if {[llength $args] <2} { error "wrong # args for when" } else { set event [lindex $args 0] set body [lindex $args end] }

Sorry I am unable to do a git commit at the moment