From: Stephen D. <sd...@us...> - 2005-04-27 00:18:08
|
Update of /cvsroot/naviserver/naviserver/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22902 Modified Files: http.test ns_adp_compress.test tclresp.test Log Message: Convert to new nstest_http command for testing http responses. Index: ns_adp_compress.test =================================================================== RCS file: /cvsroot/naviserver/naviserver/tests/ns_adp_compress.test,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ns_adp_compress.test 3 Apr 2005 06:38:01 -0000 1.2 --- ns_adp_compress.test 27 Apr 2005 00:17:54 -0000 1.3 *************** *** 31,88 **** # - source harness.tcl - package require tcltest 2.2 namespace import -force ::tcltest::* ! if {[info exists ::env(AOLSERVER_HTTP_TEST)]} { ! testConstraint serverTests true ! } - if {[testConstraint serverTests]} { - foreach {host port} [split $::env(AOLSERVER_HTTP_TEST) :] break - } ! set setup { ! set sock [socket $host $port] ! fconfigure $sock -translation binary -encoding binary -buffering none ! } ! set cleanup { ! close $sock } - set test 0 - test ns_adp_compress-1.[incr test] {fetch compressed page w/o Accept-Encoding} \ - -constraints serverTests -setup $setup -body { - puts $sock "GET /ns_adp_compress.adp HTTP/1.0\n" - set response [read $sock] - set lines [split $response "\n"] - assertEquals "HTTP/1.0 200 OK\r" [lindex $lines 0] - assertEquals 0 [string match "Content-Encoding: gzip" $response] - } -cleanup $cleanup -result {} - test ns_adp_compress-1.[incr test] {fetch compressed page w/ Accept-Encoding} \ - -constraints serverTests -setup $setup -body { - puts $sock "GET /ns_adp_compress.adp HTTP/1.0" - puts $sock "Accept-Encoding: gzip\n" - set response [read $sock] - set lines [split $response "\n"] - assertEquals "HTTP/1.0 200 OK\r" [lindex $lines 0] - assertEquals 1 [string match "*\r\nContent-Encoding: gzip\r\n*" $response] ! set gzipBytes [list 1f 8b 08 00 00 00 00 00 00 03 2b c9 c8 2c 56 00 \ ! a2 44 85 92 d4 e2 12 2e 2e 00 30 7d 05 2a c1 1c 72 c8 00 00 00 10] ! set responseBytes [list] ! foreach {start end} \ ! [lindex [regexp -inline -indices "\r\n\r\n" $response] 0] break ! if {$end ne ""} { ! incr end ! binary scan [string range $response $end end] "H*" values ! set responseBytes [regexp -all -inline {..} $values] ! } else { ! set responseBytes $response ! } ! assertEquals $gzipBytes $responseBytes ! } -cleanup $cleanup -result {} cleanupTests --- 31,58 ---- # package require tcltest 2.2 namespace import -force ::tcltest::* ! eval ::tcltest::configure $argv ! if {[ns_config test listenport]} { ! testConstraint serverListen true } ! test ns_adp_conpress-1.1 {no Accept-Encoding} -constraints serverListen -body { ! nstest_http -getbody 1 GET /ns_adp_compress.adp ! } -result {200 {this is a test}} ! ! test ns_adp_conpress-1.2 {Accept-Encoding gzip} -constraints serverListen -body { ! set response [nstest_http -setheaders {accept-encoding gzip} \ ! -getheaders {content-encoding} -getbody 1 GET /ns_adp_compress.adp] ! binary scan [lindex $response 2] "H*" values ! list [lindex $response 0] [lindex $response 1] [regexp -all -inline {..} $values] ! } -result "200 gzip \{1f 8b 08 00 00 00 00 00 00 03 2b c9 c8 2c 56 00 a2 44 85 92 d4 e2 12 00 26 33 05 16 0d 1e e7 ea 00 00 00 0e\}" ! ! cleanupTests Index: tclresp.test =================================================================== RCS file: /cvsroot/naviserver/naviserver/tests/tclresp.test,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tclresp.test 18 Apr 2005 13:04:14 -0000 1.1 --- tclresp.test 27 Apr 2005 00:17:54 -0000 1.2 *************** *** 16,24 **** - set driverlocation http://[ns_config "ns/server/test/module/nssock" hostname] - set self ${driverlocation}:[ns_config "ns/server/test/module/nssock" port] - - - test tclresp-1.1.1 {basic syntax} -body { ns_headers --- 16,19 ---- *************** *** 138,142 **** ns_register_proc GET /tclresp {ns_headers 200 ;#} } -body { ! nstest_http -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 133,137 ---- ns_register_proc GET /tclresp {ns_headers 200 ;#} } -body { ! nstest_http -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 146,150 **** ns_register_proc GET /tclresp {ns_headers 200 text/plain ;#} } -body { ! nstest_http -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 141,145 ---- ns_register_proc GET /tclresp {ns_headers 200 text/plain ;#} } -body { ! nstest_http -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 154,158 **** ns_register_proc GET /tclresp {ns_headers 200 text/plain 99 ;#} } -body { ! nstest_http -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 149,153 ---- ns_register_proc GET /tclresp {ns_headers 200 text/plain 99 ;#} } -body { ! nstest_http -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 164,168 **** ns_register_proc GET /tclresp {ns_return 200 text/plain x ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 159,163 ---- ns_register_proc GET /tclresp {ns_return 200 text/plain x ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 174,178 **** ns_register_proc GET /tclresp {ns_respond -string x ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 169,173 ---- ns_register_proc GET /tclresp {ns_respond -string x ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 182,186 **** ns_register_proc GET /tclresp {ns_respond -type text/plain -string x ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 177,181 ---- ns_register_proc GET /tclresp {ns_respond -type text/plain -string x ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 188,202 **** test tclresp-4.3 {ns_respond} -constraints serverListen -setup { ! ns_register_proc GET /tclresp {ns_respond -status 99 -string x ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp ! } -result {99 */* 1 x} test tclresp-4.4 {ns_respond} -constraints serverListen -setup { ns_register_proc GET /tclresp {ns_respond -length 2 -string xxx ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 183,197 ---- test tclresp-4.3 {ns_respond} -constraints serverListen -setup { ! ns_register_proc GET /tclresp {ns_respond -status 200 -string x ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp ! } -result {200 */* 1 x} test tclresp-4.4 {ns_respond} -constraints serverListen -setup { ns_register_proc GET /tclresp {ns_respond -length 2 -string xxx ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 210,214 **** #} } -body { ! nstest_http -getbody 1 -getheaders k GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 205,209 ---- #} } -body { ! nstest_http -getbody 1 -getheaders k GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 218,222 **** ns_register_proc GET /tclresp {ns_respond -file [ns_pagepath 10bytes] ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 213,217 ---- ns_register_proc GET /tclresp {ns_respond -file [ns_pagepath 10bytes] ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 226,230 **** ns_register_proc GET /tclresp {ns_respond -file noexist ;#} } -body { ! nstest_http GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 221,225 ---- ns_register_proc GET /tclresp {ns_respond -file noexist ;#} } -body { ! nstest_http GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 234,238 **** ns_register_proc GET /tclresp {ns_respond -length 5 -fileid [open [ns_pagepath 10bytes]] ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 229,233 ---- ns_register_proc GET /tclresp {ns_respond -length 5 -fileid [open [ns_pagepath 10bytes]] ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 244,248 **** ns_register_proc GET /tclresp {ns_returnfile 200 text/plain [ns_pagepath 10bytes] ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 239,243 ---- ns_register_proc GET /tclresp {ns_returnfile 200 text/plain [ns_pagepath 10bytes] ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 252,256 **** ns_register_proc GET /tclresp {ns_returnfile 200 text/plain noexist ;#} } -body { ! nstest_http GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 247,251 ---- ns_register_proc GET /tclresp {ns_returnfile 200 text/plain noexist ;#} } -body { ! nstest_http GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 262,266 **** ns_register_proc GET /tclresp {ns_returnfp 200 text/plain [open [ns_pagepath 10bytes]] 5 ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 257,261 ---- ns_register_proc GET /tclresp {ns_returnfp 200 text/plain [open [ns_pagepath 10bytes]] 5 ;#} } -body { ! nstest_http -getbody 1 -getheaders {content-type content-length} GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 272,276 **** ns_register_proc GET /tclresp {ns_returnbadrequest oops ;#} } -body { ! nstest_http -getbody 1 GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 267,271 ---- ns_register_proc GET /tclresp {ns_returnbadrequest oops ;#} } -body { ! nstest_http -getbody 1 GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 282,286 **** ns_register_proc GET /tclresp {ns_returnnotfound ;#} } -body { ! nstest_http -getbody 1 GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 277,281 ---- ns_register_proc GET /tclresp {ns_returnnotfound ;#} } -body { ! nstest_http -getbody 1 GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 290,294 **** ns_register_proc GET /tclresp {ns_returnunauthorized ;#} } -body { ! nstest_http -getbody 1 GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 285,289 ---- ns_register_proc GET /tclresp {ns_returnunauthorized ;#} } -body { ! nstest_http -getbody 1 GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 298,302 **** ns_register_proc GET /tclresp {ns_returnforbidden ;#} } -body { ! nstest_http -getbody 1 GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 293,297 ---- ns_register_proc GET /tclresp {ns_returnforbidden ;#} } -body { ! nstest_http -getbody 1 GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 306,315 **** test tclresp-9.1 {ns_returnerror} -constraints serverListen -setup { ! ns_register_proc GET /tclresp {ns_returnerror 99 oops ;#} } -body { ! nstest_http -getbody 1 GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp ! } -match glob -result {99 *oops*} --- 301,310 ---- test tclresp-9.1 {ns_returnerror} -constraints serverListen -setup { ! ns_register_proc GET /tclresp {ns_returnerror 400 oops ;#} } -body { ! nstest_http -getbody 1 GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp ! } -match glob -result {400 *oops*} *************** *** 318,322 **** ns_register_proc GET /tclresp {ns_returnnotice 200 TITLE MESSAGE ;#} } -body { ! nstest_http -getbody 1 GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 313,317 ---- ns_register_proc GET /tclresp {ns_returnnotice 200 TITLE MESSAGE ;#} } -body { ! nstest_http -getbody 1 GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 328,332 **** ns_register_proc GET /tclresp {ns_returnredirect http://example.com/x ;#} } -body { ! nstest_http -getbody 1 -getheaders location GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 323,327 ---- ns_register_proc GET /tclresp {ns_returnredirect http://example.com/x ;#} } -body { ! nstest_http -getbody 1 -getheaders location GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 338,342 **** ns_register_proc GET /tclresp {ns_headers 200; ns_write x ;#} } -body { ! nstest_http -getbody 1 GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 333,337 ---- ns_register_proc GET /tclresp {ns_headers 200; ns_write x ;#} } -body { ! nstest_http -getbody 1 GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 348,352 **** ns_register_proc GET /tclresp {ns_connsendfp [open [ns_pagepath 10bytes]] 5 ;#} } -body { ! nstest_http -getbody 1 GET $self/tclresp } -cleanup { ns_unregister_proc GET /tclresp --- 343,347 ---- ns_register_proc GET /tclresp {ns_connsendfp [open [ns_pagepath 10bytes]] 5 ;#} } -body { ! nstest_http -getbody 1 GET /tclresp } -cleanup { ns_unregister_proc GET /tclresp *************** *** 355,358 **** - unset -nocomplain driverlocation self cleanupTests --- 350,352 ---- Index: http.test =================================================================== RCS file: /cvsroot/naviserver/naviserver/tests/http.test,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** http.test 3 Apr 2005 06:38:01 -0000 1.2 --- http.test 27 Apr 2005 00:17:53 -0000 1.3 *************** *** 31,87 **** # - source harness.tcl package require tcltest 2.2 namespace import -force ::tcltest::* ! if {[info exists ::env(AOLSERVER_HTTP_TEST)]} { ! testConstraint serverTests true ! } ! if {[testConstraint serverTests]} { ! foreach {host port} [split $::env(AOLSERVER_HTTP_TEST) :] break } - set setup { - set sock [socket $host $port] - fconfigure $sock -translation binary -encoding binary -buffering none - } - set cleanup { - close $sock - } - set test 0 - test http-1.[incr test] {bad method} \ - -constraints serverTests -setup $setup -body { - puts $sock "." - set response [read $sock] - assertEquals {} $response - } -cleanup $cleanup -result {} ! test http-1.[incr test] {HTTP/0.9 GET} \ ! -constraints serverTests -setup $setup -body { ! puts $sock "GET /asdfasdfasdf\n" ! set response [read $sock] ! assertEquals 0 [regexp {^HTTP/\S+ \d+ .*} $response] ! assertEquals 1 [regexp {<TITLE>Not Found</TITLE>} $response] ! } -cleanup $cleanup -result {} - test http-1.[incr test] {HTTP/1.0 GET} \ - -constraints serverTests -setup $setup -body { - puts $sock "GET /asdfasdfasdf HTTP/1.0\n" - set response [read $sock] - assertEquals 1 [regexp {^HTTP/\S+ \d+ .*} $response] - assertEquals 1 [regexp {<TITLE>Not Found</TITLE>} $response] - } -cleanup $cleanup -result {} - test http-1.[incr test] {HTTP/1.1 GET} \ - -constraints serverTests -setup $setup -body { - puts $sock "GET /asdfasdfasdf HTTP/1.0\nHost: $host:$port\n" - set response [read $sock] - assertEquals 1 [regexp {^HTTP/\S+ \d+ .*} $response] - assertEquals 1 [regexp {<TITLE>Not Found</TITLE>} $response] - } -cleanup $cleanup -result {} cleanupTests --- 31,65 ---- # package require tcltest 2.2 namespace import -force ::tcltest::* ! eval ::tcltest::configure $argv ! if {[ns_config test listenport]} { ! testConstraint serverListen true } ! test http-1.1 {bad request} -constraints serverListen -body { ! nstest_http -getbody 1 bogus ! } -result {{}} ! ! test http-1.2 {HTTP/0.9 GET} -constraints serverListen -body { ! nstest_http -http "" -getbody 1 GET /noexist ! } -match glob -result {*Not Found*} ! ! test http-1.3 {HTTP/1.0 GET} -constraints serverListen -body { ! nstest_http -getbody 1 GET /noexist ! } -match glob -result {404 *Not Found*} ! ! test http-1.4 {HTTP/1.1 GET} -constraints serverListen -body { ! nstest_http -http 1.1 -getbody 1 GET /noexist ! } -match glob -result {404 *Not Found*} ! cleanupTests |