You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For some iRules which interact with multiple events (HTTP_REQUEST -> HTTP_REQUEST_RELEASE -> HTTP_RESPONSE), some variables can be set (sample: to store some states) and reused in events coming after the one which set the variable (sample: to change behavior, header content, ...).
With TesTcl, it can be tested by using a dedicated IT by event and use variables to mock wanted state.
Unfortunately, when one iRule is ran with variables array arguments, the following iRule runs (in other IT) reuse this variables.
Snippet reproduction:
Consider simple_irule.tcl:
rule simple {
when HTTP_REQUEST_RELEASE {
# Set FooBar header with value from 'somevar' variable, 42 otherwise
if { [info exists somevar] } {
HTTP::header insert FooBar $somevar
} else {
HTTP::header insert FooBar "42"
}
}
}
And test_simple_irule.tcl:
package require -exact testcl 1.0.14
namespace import ::testcl::*
# Comment in to enable logging
#log::lvSuppressLE debug 0
it "first" {
event HTTP_REQUEST_RELEASE
verify "FooBar header" "valueFirstFromVar" eq {HTTP::header "FooBar"}
# Run with variables
array set vars {somevar valueFirstFromVar}
run simple_irule.tcl simple vars
}
it "second" {
event HTTP_REQUEST_RELEASE
verify "FooBar header" "42" eq {HTTP::header "FooBar"}
run simple_irule.tcl simple
}
The second IT fails with:
**************************************************************************
* it first
**************************************************************************
verification of 'FooBar header' done.
-> Test ok
**************************************************************************
* it second
**************************************************************************
-> Test failure!!
-> -> Verification 'FooBar header' failed - expression: {42} eq {valueFirstFromVar}
error Verification 'FooBar header' failed - expression: {42} eq {valueFirstFromVar}
Logging info locals in iRule display that somevar is existing in second iRule call.
A workaround could be to call iRule in all IT by populating array with all variables all times ... but when you want that a use case where variable doesn't exist, it is tricky 😢.
The text was updated successfully, but these errors were encountered:
For some iRules which interact with multiple events (
HTTP_REQUEST
->HTTP_REQUEST_RELEASE
->HTTP_RESPONSE
), some variables can be set (sample: to store some states) and reused in events coming after the one which set the variable (sample: to change behavior, header content, ...).With TesTcl, it can be tested by using a dedicated IT by event and use variables to mock wanted state.
Unfortunately, when one iRule is ran with variables array arguments, the following iRule runs (in other IT) reuse this variables.
Snippet reproduction:
Consider
simple_irule.tcl
:And
test_simple_irule.tcl
:The second IT fails with:
Logging info locals in iRule display that
somevar
is existing in second iRule call.A workaround could be to call iRule in all IT by populating array with all variables all times ... but when you want that a use case where variable doesn't exist, it is tricky 😢.
The text was updated successfully, but these errors were encountered: