Hi folks!
Here's a patch containing few tests for web client.
I modified the predefined test strings for null-string-body test, and
added none-null body test for POST/PUT.
TRACE request MUST NOT include an entity, according to RFC2616, so I
removed the body.

Comments will be appreciated, thanks!



>From 2405c78b27da00ea8e17ad3ea24a852ace546554 Mon Sep 17 00:00:00 2001
From: Nala Ginrut <nalagin...@gmail.com>
Date: Sat, 14 Sep 2013 12:37:20 +0800
Subject: [PATCH] add new tests for web client

* tests/web-client.test (post-request-headers-null:www.apache.org/,
                         post-request-body:www.apache.org/,
                         put-request-headers-null:www.apache.org/,
                         put-request-body:www.apache.org/)
  Modified/added the predefined test strings for null-string-body test.
  Added none-null body test for POST/PUT.
  Removed entity from TRACE test (TRACE request MUST NOT include an
  entity, according to RFC2616).
---
 test-suite/tests/web-client.test |   72 +++++++++++++++++++++++++++++++++-----
 1 file changed, 63 insertions(+), 9 deletions(-)

diff --git a/test-suite/tests/web-client.test b/test-suite/tests/web-client.test
index 3133b73..2e170ad 100644
--- a/test-suite/tests/web-client.test
+++ b/test-suite/tests/web-client.test
@@ -299,13 +299,28 @@ Content-Language: en
 ")
 
 ;; Unfortunately, POST to http://www.gnu.org/software/guile/ succeeds!
+(define post-request-headers-null:www.apache.org/
+  "POST / HTTP/1.1
+Content-Length: 0
+Content-Type: text/plain;charset=utf-8
+Host: www.apache.org
+Connection: close
+
+")
+
 (define post-request-headers:www.apache.org/
   "POST / HTTP/1.1
+Content-Length: 137
+Content-Type: text/plain;charset=utf-8
 Host: www.apache.org
 Connection: close
 
 ")
 
+(define post-request-body:www.apache.org/
+  "GNU's Ubiquitous Intelligent Language for Extension, a library 
+implementation of the Scheme language plus various convenient facilities.")
+
 (define post-response-headers:www.apache.org/
   "HTTP/1.1 405 Method Not Allowed
 Date: Fri, 11 Jan 2013 11:04:34 GMT
@@ -329,13 +344,28 @@ Content-Type: text/html; charset=iso-8859-1
 </body></html>
 ")
 
+(define put-request-headers-null:www.apache.org/
+  "PUT / HTTP/1.1
+Content-Length: 0
+Content-Type: text/plain;charset=utf-8
+Host: www.apache.org
+Connection: close
+
+")
+
 (define put-request-headers:www.apache.org/
   "PUT / HTTP/1.1
+Content-Length: 137
+Content-Type: text/plain;charset=utf-8
 Host: www.apache.org
 Connection: close
 
 ")
 
+(define put-request-body:www.apache.org/
+  "GNU's Ubiquitous Intelligent Language for Extension, a library 
+implementation of the Scheme language plus various convenient facilities.")
+
 (define put-response-headers:www.apache.org/
   "HTTP/1.1 405 Method Not Allowed
 Date: Fri, 11 Jan 2013 11:04:34 GMT
@@ -361,6 +391,8 @@ Content-Type: text/html; charset=iso-8859-1
 
 (define delete-request-headers:www.apache.org/
   "DELETE / HTTP/1.1
+Content-Length: 0
+Content-Type: text/plain;charset=utf-8
 Host: www.apache.org
 Connection: close
 
@@ -393,6 +425,8 @@ Content-Type: text/html; charset=iso-8859-1
 
 (define options-request-headers:www.apache.org/
   "OPTIONS / HTTP/1.1
+Content-Length: 0
+Content-Type: text/plain;charset=utf-8
 Host: www.apache.org
 Connection: close
 
@@ -483,9 +517,11 @@ Connection: close\r
                                (call-with-input-string expected-request
                                                        read-request)))
             (pass-if "request bodies equal"
-              (equal? (or actual-body #vu8())
-                      (string->bytevector expected-request-body
-                                          request-body-encoding)))))
+              (if expected-request-body
+                  (equal? (or actual-body #vu8())
+                          (string->bytevector expected-request-body
+                                              request-body-encoding))
+                  (not actual-body)))))
         (define (get-char)
           (unless reading?
             (error "Port closed for reading"))
@@ -514,7 +550,7 @@ Connection: close\r
      response-headers response-body response-body-encoding
      (lambda (port)
        (call-with-values (lambda ()
-                           (proc uri #:port port))
+                           (proc uri #:port port #:body request-body))
          (lambda (response body)
            (pass-if "response equal"
              (responses-equal?
@@ -525,27 +561,45 @@ Connection: close\r
 
 (check-transaction
  "GET" "http://www.gnu.org/software/guile/";
- get-request-headers:www.gnu.org/software/guile/ "" "iso-8859-1"
+ get-request-headers:www.gnu.org/software/guile/ #f "iso-8859-1"
  get-response-headers:www.gnu.org/software/guile/
  get-response-body:www.gnu.org/software/guile/ "iso-8859-1"
  http-get)
 
 (check-transaction
  "HEAD" "http://www.gnu.org/software/guile/";
- head-request-headers:www.gnu.org/software/guile/ "" "iso-8859-1"
+ head-request-headers:www.gnu.org/software/guile/ #f "iso-8859-1"
  head-response-headers:www.gnu.org/software/guile/ "" "iso-8859-1"
  http-head)
 
+;; test POST with NULL entity
 (check-transaction
  "POST" "http://www.apache.org/";
- post-request-headers:www.apache.org/ "" "iso-8859-1"
+ post-request-headers-null:www.apache.org/ "" "iso-8859-1"
  post-response-headers:www.apache.org/
  post-response-body:www.apache.org/ "iso-8859-1"
  http-post)
 
 (check-transaction
+ "POST" "http://www.apache.org/";
+ post-request-headers:www.apache.org/ 
+ post-request-body:www.apache.org/ "iso-8859-1"
+ post-response-headers:www.apache.org/
+ post-response-body:www.apache.org/ "iso-8859-1"
+ http-post)
+
+;; test PUT with NULL entity
+(check-transaction
+ "PUT" "http://www.apache.org/";
+ put-request-headers-null:www.apache.org/ "" "iso-8859-1"
+ put-response-headers:www.apache.org/
+ put-response-body:www.apache.org/ "iso-8859-1"
+ http-put)
+
+(check-transaction
  "PUT" "http://www.apache.org/";
- put-request-headers:www.apache.org/ "" "iso-8859-1"
+ put-request-headers:www.apache.org/ 
+ put-request-body:www.apache.org/ "iso-8859-1"
  put-response-headers:www.apache.org/
  put-response-body:www.apache.org/ "iso-8859-1"
  http-put)
@@ -565,7 +619,7 @@ Connection: close\r
 
 (check-transaction
  "TRACE" "http://www.apache.org/";
- trace-request-headers:www.apache.org/ "" "iso-8859-1"
+ trace-request-headers:www.apache.org/ #f "iso-8859-1"
  trace-response-headers:www.apache.org/
  trace-response-body:www.apache.org/ "iso-8859-1"
  http-trace
-- 
1.7.10.4

Reply via email to