lib: improves testing of curl_http
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 29 Jul 2013 19:50:52 +0000 (15:50 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 29 Jul 2013 20:02:10 +0000 (16:02 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

examples/curl_http.nit
tests/curl_http.args [new file with mode: 0644]
tests/sav/curl_http_args1.sav [new file with mode: 0644]
tests/sav/curl_http_args2.sav [new file with mode: 0644]
tests/sav/curl_http_args3.sav [new file with mode: 0644]

index 50c46e5..aa84120 100644 (file)
@@ -33,7 +33,10 @@ class MyHttpFetcher
   fun request(url: String): nullable CurlRequest do return self.curl.http_request(url)
 
   # Header callback
-  redef fun header_callback(line: String) do print "Header_callback : {line}"
+  redef fun header_callback(line: String) do
+       # We keep this callback silent for testing purposes
+    #if not line.has_prefix("Date:") then print "Header_callback : {line}"
+  end
 
   # Body callback
   redef fun body_callback(line: String) do print "Body_callback : {line}"
@@ -106,7 +109,7 @@ else
       var headers = new HeaderMap
       headers["Accept"] = "Moo"
       downloadFileRequest.headers = headers
-      downloadFileRequest.verbose = true
+      downloadFileRequest.verbose = false
       var downloadResponse = downloadFileRequest.download_to_file(null)
 
       if downloadResponse isa CurlFileResponseSuccess then
diff --git a/tests/curl_http.args b/tests/curl_http.args
new file mode 100644 (file)
index 0000000..86fbf10
--- /dev/null
@@ -0,0 +1,3 @@
+GET example.org
+POST example.com
+GET_FILE example.org
diff --git a/tests/sav/curl_http_args1.sav b/tests/sav/curl_http_args1.sav
new file mode 100644 (file)
index 0000000..c47c136
--- /dev/null
@@ -0,0 +1,52 @@
+Status code : 200
+Body : <!doctype html>
+<html>
+<head>
+    <title>Example Domain</title>
+
+    <meta charset="utf-8" />
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <style type="text/css">
+    body {
+        background-color: #f0f0f2;
+        margin: 0;
+        padding: 0;
+        font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
+        
+    }
+    div {
+        width: 600px;
+        margin: 5em auto;
+        padding: 50px;
+        background-color: #fff;
+        border-radius: 1em;
+    }
+    a:link, a:visited {
+        color: #38488f;
+        text-decoration: none;
+    }
+    @media (max-width: 700px) {
+        body {
+            background-color: #fff;
+        }
+        div {
+            width: auto;
+            margin: 0 auto;
+            border-radius: 0;
+            padding: 1em;
+        }
+    }
+    </style>    
+</head>
+
+<body>
+<div>
+    <h1>Example Domain</h1>
+    <p>This domain is established to be used for illustrative examples in documents. You may use this
+    domain in examples without prior coordination or asking for permission.</p>
+    <p><a href="http://www.iana.org/domains/example">More information...</a></p>
+</div>
+</body>
+</html>
+
diff --git a/tests/sav/curl_http_args2.sav b/tests/sav/curl_http_args2.sav
new file mode 100644 (file)
index 0000000..76528dd
--- /dev/null
@@ -0,0 +1,54 @@
+Body_callback : <!doctype html>
+<html>
+<head>
+    <title>Example Domain</title>
+
+    <meta charset="utf-8" />
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <style type="text/css">
+    body {
+        background-color: #f0f0f2;
+        margin: 0;
+        padding: 0;
+        font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
+        
+    }
+    div {
+        width: 600px;
+        margin: 5em auto;
+        padding: 50px;
+        background-color: #fff;
+        border-radius: 1em;
+    }
+    a:link, a:visited {
+        color: #38488f;
+        text-decoration: none;
+    }
+    @media (max-width: 700px) {
+        body {
+            background-color: #fff;
+        }
+        div {
+            width: auto;
+            margin: 0 auto;
+            border-radius: 0;
+            padding: 1em;
+        }
+    }
+    </style>    
+</head>
+
+<body>
+<div>
+    <h1>Example Domain</h1>
+    <p>This domain is established to be used for illustrative examples in documents. You may use this
+    domain in examples without prior coordination or asking for permission.</p>
+    <p><a href="http://www.iana.org/domains/example">More information...</a></p>
+</div>
+</body>
+</html>
+
+*** Answer ***
+Status code : 200
+Body should be empty, because we decided to manage callbacks : 0
diff --git a/tests/sav/curl_http_args3.sav b/tests/sav/curl_http_args3.sav
new file mode 100644 (file)
index 0000000..0c72a82
--- /dev/null
@@ -0,0 +1,3 @@
+*** Answer ***
+Status code : 200
+Size downloaded : 1270