-
Notifications
You must be signed in to change notification settings - Fork 30
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
Helpers for mocking and verifying statuscodes, headers etc. #23
Comments
Regarding nr 1. - why not. It would probably make sense to put it into a custom testcl namespace ::testcl::utils. Could you provide a pull request containing:
Regarding nr. 2 - could you please try rename headerName into something else - it might shadow a global variable or something @Sebastian-Brzuzek, what do you think? BTW, we should try to use the google group for discussing before opening tickets: https://groups.google.com/forum/#!forum/testcl-user |
I can't see any benefit with ready to use mock functions - almost the same amount of writing and no additional functionality. @Espenhh what about using this kind of test script in your case? package require -exact testcl 1.0.2
namespace import ::testcl::*
# Comment in to enable logging
#log::lvSuppressLE info 0
proc verifyEq {what expected calculated} {
verify "$what is '$expected'" $expected eq $calculated
}
before {
event HTTP_REQUEST
}
it "should remove '/api' from URI" {
HTTP::uri "/api/users"
HTTP::header "Accept" "application/json"
on active_members pool_api return 0
verifyEq "Status code" 503 {HTTP::status}
verifyEq "Header Content-Type" "text/plain" {HTTP::header "Content-Type"}
verifyEq "Header Cache-Control" "no-cache" {HTTP::header "Cache-Control"}
verifyEq "Header X-Forwarded-SSL" "true" {HTTP::header "X-Forwarded-SSL"}
run rules/2.tcl http
} @landro what do you think about providing some additional subpackage like ::TesTcl::verify:: for ready to use most common verification procedures (ex. verify::header or verify::statusCode)? |
and about error... proc verifyHeader {headerName expectedHeaderValue} {
verify "Header '$headerName' should be '$expectedHeaderValue'" $expectedHeaderValue eq [list HTTP::header $headerName]
} |
@Sebastian-Brzuzek I've been thinking about this stuff today. As you said, we should try to keep testcl as tiny as possible. Less code means less code to maintain ... Before we add lots of functionality, we really need to get feedback from our user base (which I believe is quite small ... ). Makes sense? |
@Sebastian-Brzuzek that solution solved it perfectly! Thanks :) I agree that it's good to keep the library small at this point. Maybe the documentation could include an example using procedures to show people what's possible, I guess a lot of people who will be using this library are not very proficient in the Tcl language, so a little help in the right direction would be good :) Feel free to close this issue if you don't want to include any helper-functions at this point. |
@Espenhh I think it is great idea to add some more examples to documentation or even better to update existing examples with this kind of procedures to not force people read too many examples/docs. @landro I fully agree that we should get feedback. Is there some voting mechanism which we can use to find what is "common"? I was using https://www.google.com/moderator/ for this kind of problems, but maybe there is something better. We should agree on some rules like adding only procedures which will collect some minimum number of votes? BTW, I think we should move this discussion to our mailing list https://groups.google.com/forum/#!forum/testcl-user and close this issue until we will decide which procedures to add and how to organize this. @landro do you agree? |
I'll close this for now, and open a discussen on the google group. 2013/10/15 Sebastian Brzuzek notifications@github.com
BEKK Open TesTcl - a unit test framework for iRules |
I've created some procedures for mocking headers and uri's, and for verifying status codes and return headers. When I write a lot of tests, this makes them easier to read.
Question 1:
Is there a possibility that these types of utility functions could be included in the TesTcl core?
Question 2:
One of my utility functions (the one named "verifyHeader" below) isn't working, it's producing this error:
Any idea what can be the cause of this error? I guess it's might be just some TCL syntax error on my part...
This is the test I've written with the procedures, and one of the tests (Isolated the procedures might seem overkill, but I've got 10-15 more of these tests...)
This is the iRule:
The text was updated successfully, but these errors were encountered: