couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject git commit: First fully working version of the JavaScript CLI tests.
Date Mon, 31 Oct 2011 00:05:44 GMT
Updated Branches:
  refs/heads/master 1376d5de8 -> 31edafecb


First fully working version of the JavaScript CLI tests.

This patch has multiple parts:

1. Make remaining tests work with CouchHTTP.
2. Add ./test/javascript/run to make check.
3. Add handling of OPTIONS method to couchjs's http client.
4. Add referer sending to couchjs's http client.

To run *all* tests, run `make check`.

Closes COUCHDB-1312


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/31edafec
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/31edafec
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/31edafec

Branch: refs/heads/master
Commit: 31edafecbe9e089302da43e32da538eb093543f4
Parents: 1376d5d
Author: Jan Lehnardt <jan@apache.org>
Authored: Mon Oct 31 00:59:18 2011 +0100
Committer: Jan Lehnardt <jan@apache.org>
Committed: Mon Oct 31 01:05:16 2011 +0100

----------------------------------------------------------------------
 Makefile.am                                    |    1 +
 share/www/script/couch.js                      |   20 +++++++++++++++++++
 share/www/script/test/attachment_names.js      |    2 -
 share/www/script/test/attachments_multipart.js |   12 +---------
 share/www/script/test/form_submit.js           |    1 -
 src/couchdb/priv/couch_js/http.c               |    8 ++++--
 test/javascript/couch_http.js                  |   12 +++++++++++
 7 files changed, 40 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/31edafec/Makefile.am
----------------------------------------------------------------------
diff --git a/Makefile.am b/Makefile.am
index 039d2ee..01879dc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -83,6 +83,7 @@ THANKS.gz: $(top_srcdir)/THANKS
 
 check: dev
 	$(top_builddir)/test/etap/run $(top_srcdir)/test/etap
+	$(top_builddir)/test/javascript/run
 
 cover: dev
 	rm -f cover/*.coverdata

http://git-wip-us.apache.org/repos/asf/couchdb/blob/31edafec/share/www/script/couch.js
----------------------------------------------------------------------
diff --git a/share/www/script/couch.js b/share/www/script/couch.js
index 75cae8e..a381d31 100644
--- a/share/www/script/couch.js
+++ b/share/www/script/couch.js
@@ -396,6 +396,26 @@ CouchDB.newXhr = function() {
   }
 };
 
+CouchDB.xhrbody = function(xhr) {
+  if (xhr.responseText) {
+    return xhr.responseText;
+  } else if (xhr.body) {
+    return xhr.body
+  } else {
+    throw new Error("No XMLHTTPRequest support detected");
+  }
+}
+
+CouchDB.xhrheader = function(xhr, header) {
+  if(xhr.getResponseHeader) {
+    return xhr.getResponseHeader(header);
+  } else if(xhr.headers) {
+    return xhr.headers[header] || null;
+  } else {
+    throw new Error("No XMLHTTPRequest support detected");
+  }
+}
+
 CouchDB.request = function(method, uri, options) {
   options = typeof(options) == 'object' ? options : {};
   options.headers = typeof(options.headers) == 'object' ? options.headers : {};

http://git-wip-us.apache.org/repos/asf/couchdb/blob/31edafec/share/www/script/test/attachment_names.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/attachment_names.js b/share/www/script/test/attachment_names.js
index 777b5ec..ced0ead 100644
--- a/share/www/script/test/attachment_names.js
+++ b/share/www/script/test/attachment_names.js
@@ -60,7 +60,6 @@ couchTests.attachment_names = function(debug) {
 
   var resp = JSON.parse(xhr.responseText);
   TEquals(201, xhr.status, "attachment_name: standalone API");
-  TEquals("Created",  xhr.statusText, "attachment_name: standalone API");
   TEquals(true, resp.ok, "attachment_name: standalone API");
 
   // bulk docs
@@ -71,7 +70,6 @@ couchTests.attachment_names = function(debug) {
   });
 
   TEquals(201, xhr.status, "attachment_name: bulk docs");
-  TEquals("Created", xhr.statusText, "attachment_name: bulk docs");
 
 
   // leading underscores

http://git-wip-us.apache.org/repos/asf/couchdb/blob/31edafec/share/www/script/test/attachments_multipart.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/attachments_multipart.js b/share/www/script/test/attachments_multipart.js
index 4f4590f..9b9ddbd 100644
--- a/share/www/script/test/attachments_multipart.js
+++ b/share/www/script/test/attachments_multipart.js
@@ -120,11 +120,7 @@ couchTests.attachments_multipart= function(debug) {
   // now test receiving multipart docs
   
   function getBoundary(xhr) {
-    if (xhr instanceof XMLHttpRequest) {
-      var ctype = xhr.getResponseHeader("Content-Type");
-    } else {
-      var ctype = xhr.headers['Content-Type'];
-    }
+    var ctype = CouchDB.xhrheader(xhr, "Content-Type");
     var ctypeArgs = ctype.split("; ").slice(1);
     var boundary = null;
     for(var i=0; i<ctypeArgs.length; i++) {
@@ -142,11 +138,7 @@ couchTests.attachments_multipart= function(debug) {
   
   function parseMultipart(xhr) {
     var boundary = getBoundary(xhr);
-    if (xhr instanceof XMLHttpRequest) {
-      var mimetext = xhr.responseText;
-    } else {
-      var mimetext = xhr.body;
-    }
+    var mimetext = CouchDB.xhrbody(xhr);
     // strip off leading boundary
     var leading = "--" + boundary + "\r\n";
     var last = "\r\n--" + boundary + "--";

http://git-wip-us.apache.org/repos/asf/couchdb/blob/31edafec/share/www/script/test/form_submit.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/form_submit.js b/share/www/script/test/form_submit.js
index 39833d1..710bf47 100644
--- a/share/www/script/test/form_submit.js
+++ b/share/www/script/test/form_submit.js
@@ -16,7 +16,6 @@ couchTests.form_submit = function(debug) {
     db.deleteDb();
     db.createDb();
 
-    // PUT on existing DB should return 412 instead of 500
     var json = "{}";
     var xhr = CouchDB.request("POST", "/test_suite_db/baz", {body: json});
     T(xhr.status == 415);

http://git-wip-us.apache.org/repos/asf/couchdb/blob/31edafec/src/couchdb/priv/couch_js/http.c
----------------------------------------------------------------------
diff --git a/src/couchdb/priv/couch_js/http.c b/src/couchdb/priv/couch_js/http.c
index 0685abb..fb54869 100644
--- a/src/couchdb/priv/couch_js/http.c
+++ b/src/couchdb/priv/couch_js/http.c
@@ -102,7 +102,7 @@ typedef struct {
 } HTTPData;
 
 
-char* METHODS[] = {"GET", "HEAD", "POST", "PUT", "DELETE", "COPY", NULL};
+char* METHODS[] = {"GET", "HEAD", "POST", "PUT", "DELETE", "COPY", "OPTIONS", NULL};
 
 
 #define GET     0
@@ -111,6 +111,7 @@ char* METHODS[] = {"GET", "HEAD", "POST", "PUT", "DELETE", "COPY", NULL};
 #define PUT     3
 #define DELETE  4
 #define COPY    5
+#define OPTIONS 6
 
 
 static JSBool
@@ -196,7 +197,7 @@ http_open(JSContext* cx, JSObject* req, jsval mth, jsval url, jsval snc)
         if(strcasecmp(METHODS[methid], method) == 0) break;
     }
     
-    if(methid > COPY) {
+    if(methid > OPTIONS) {
         JS_ReportError(cx, "Invalid method specified.");
         goto done;
     }
@@ -399,6 +400,7 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
         curl_easy_setopt(HTTP_HANDLE, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
         curl_easy_setopt(HTTP_HANDLE, CURLOPT_ERRORBUFFER, ERRBUF);
         curl_easy_setopt(HTTP_HANDLE, CURLOPT_COOKIEFILE, "");
+        curl_easy_setopt(HTTP_HANDLE, CURLOPT_REFERER, "http://127.0.0.1:5984/");
         curl_easy_setopt(HTTP_HANDLE, CURLOPT_USERAGENT,
                                             "CouchHTTP Client - Relax");
     }
@@ -408,7 +410,7 @@ go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t bodylen)
         goto done;
     }
 
-    if(http->method < 0 || http->method > COPY) {
+    if(http->method < 0 || http->method > OPTIONS) {
         JS_ReportError(cx, "INTERNAL: Unknown method.");
         goto done;
     }

http://git-wip-us.apache.org/repos/asf/couchdb/blob/31edafec/test/javascript/couch_http.js
----------------------------------------------------------------------
diff --git a/test/javascript/couch_http.js b/test/javascript/couch_http.js
index 5f4716d..141993e 100644
--- a/test/javascript/couch_http.js
+++ b/test/javascript/couch_http.js
@@ -60,3 +60,15 @@ CouchDB.urlPrefix = "";
 CouchDB.newXhr = function() {
   return new CouchHTTP();
 };
+
+CouchDB.xhrheader = function(xhr, header) {
+  if(typeof(xhr) == "CouchHTTP") {
+    return xhr.getResponseHeader(header);
+  } else {
+    return xhr.headers[header];
+  }
+}
+
+CouchDB.xhrbody = function(xhr) {
+  return xhr.responseText || xhr.body;
+}


Mime
View raw message