You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2017/01/11 11:46:01 UTC

[14/15] couchdb-nano git commit: modify tests to work mocked and unmocked with CouchDB 2.0 from Docker

modify tests to work mocked and unmocked with CouchDB 2.0 from Docker


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

Branch: refs/heads/master
Commit: cb870b82e352b07e158556bebbea53948107ce43
Parents: 6be3aec
Author: Glynn Bird <gl...@gmail.com>
Authored: Wed Oct 26 15:01:12 2016 +0100
Committer: Glynn Bird <gl...@gmail.com>
Committed: Thu Oct 27 08:33:47 2016 +0100

----------------------------------------------------------------------
 .travis.yml                           |  4 +++-
 lib/nano.js                           |  4 ----
 package.json                          |  3 ++-
 scripts/run_couchdb_on_travis.sh      | 13 +++++++++++++
 tests/fixtures/shared/cookie.json     |  8 ++------
 tests/integration/database/compact.js |  1 -
 tests/integration/database/list.js    |  6 ++++--
 tests/integration/design/compact.js   |  4 ++--
 tests/integration/design/show.js      |  4 +++-
 tests/integration/multipart/get.js    |  6 ++++--
 tests/integration/shared/cookie.js    | 29 ++++++++++++++---------------
 11 files changed, 47 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index c0f8448..0e7bd2c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,8 +14,10 @@ node_js:
   - "4.2"
   - "node"
 services:
-  - couchdb
+  - docker
 os:
   - linux
+before_script:
+  - ./scripts/run_couchdb_on_travis.sh
 before_install:
   - npm update -g npm

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/lib/nano.js
----------------------------------------------------------------------
diff --git a/lib/nano.js b/lib/nano.js
index 440cdde..528e3f5 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -191,12 +191,8 @@ module.exports = exports = nano = function dbScope(cfg) {
 
     return httpAgent(req, function(e, h, b) { 
       rh = h && h.headers || {};
-      if ( _.isEmpty(rh) ) {
-        rh = h && h.request && h.request.headers || {};
-      }
       rh.statusCode = h && h.statusCode || 500;
       rh.uri = req.uri;
-
       if (e) {
         log({err: 'socket', body: b, headers: rh});
         return callback(errs.merge(e, {

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 3f7c092..78d8eb9 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,8 @@
     "tape-it": "^0.3.1"
   },
   "scripts": {
-    "test": "DEBUG=* NOCK_OFF=true istanbul cover tape tests/*/*/*.js",
+    "test": "bash scripts/run_couchdb_on_travis.sh; npm run mocha",
+    "mocha": "DEBUG=* NOCK_OFF=true istanbul cover tape tests/*/*/*.js",
     "unmocked": "NOCK_OFF=true tape tests/*/*/*.js",
     "mocked": "tape tests/*/*/*.js",
     "jshint": "jshint tests/*/*/*.js lib/*.js",

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/scripts/run_couchdb_on_travis.sh
----------------------------------------------------------------------
diff --git a/scripts/run_couchdb_on_travis.sh b/scripts/run_couchdb_on_travis.sh
new file mode 100755
index 0000000..fa7a30c
--- /dev/null
+++ b/scripts/run_couchdb_on_travis.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+if [ ! -z $TRAVIS ]; then
+	# Install CouchDB Master
+	docker run --ulimit nofile=2048:2048 -d -p 5984:5984 klaemo/couchdb:2.0-dev@sha256:336fd3d9a89475205fc79b6a287ee550d258fac3b62c67b8d13b8e66c71d228f --with-haproxy \
+	    --with-admin-party-please -n 1
+
+	# wait for couchdb to start
+	while [ '200' != $(curl -s -o /dev/null -w %{http_code} http://127.0.0.1:5984) ]; do
+	  echo waiting for couch to load... ;
+	  sleep 1;
+	done
+fi
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/tests/fixtures/shared/cookie.json
----------------------------------------------------------------------
diff --git a/tests/fixtures/shared/cookie.json b/tests/fixtures/shared/cookie.json
index fef043c..c1b9d48 100644
--- a/tests/fixtures/shared/cookie.json
+++ b/tests/fixtures/shared/cookie.json
@@ -4,8 +4,8 @@
   , "status"   : 201
   , "response" : "{ \"ok\": true }"
   }
-, { "path"     : "/_config/admins/admin"
-  , "method"   : "put"
+, { "path"     : "/_users"
+  , "method"   : "post"
   , "body"     : "*"
   , "response" : "{\"ok\": true}"
   }
@@ -28,10 +28,6 @@
   , "body"     : "{\"foo\":\"baz\"}"
   , "response" : "{\"ok\":true,\"id\":\"234\",\"rev\":\"1-333231\"}"
   }
-, { "path"     : "/_config/admins/admin"
-  , "method"   : "delete"
-  , "response" : "{\"ok\": true}"
-  }
 , { "method"   : "delete"
   , "path"     : "/shared_cookie"
   , "response" : "{ \"ok\": true }"

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/tests/integration/database/compact.js
----------------------------------------------------------------------
diff --git a/tests/integration/database/compact.js b/tests/integration/database/compact.js
index 98c9468..9db90fe 100644
--- a/tests/integration/database/compact.js
+++ b/tests/integration/database/compact.js
@@ -36,7 +36,6 @@ it('should have run the compaction', function(assert) {
       assert.equal(error, null, 'info should respond');
       assert.equal(info['doc_count'], 0, 'document count is not 3');
       assert.equal(info['doc_del_count'], 1, 'document should be deleted');
-      assert.equal(info['update_seq'][0], '2', 'seq is two');
       assert.end();
     });
   });

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/tests/integration/database/list.js
----------------------------------------------------------------------
diff --git a/tests/integration/database/list.js b/tests/integration/database/list.js
index 8759a75..f30159c 100644
--- a/tests/integration/database/list.js
+++ b/tests/integration/database/list.js
@@ -19,8 +19,10 @@ var nano = harness.locals.nano;
 
 it('should ensure _replicator and _users are created', function(assert) {
   nano.db.create('_replicator', function() {
-    nano.db.create('_users', function() {
-      assert.end();
+    nano.db.destroy('_users', function() {
+      nano.db.create('_users', function() {
+        assert.end();
+      });
     });
   });
 });

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/tests/integration/design/compact.js
----------------------------------------------------------------------
diff --git a/tests/integration/design/compact.js b/tests/integration/design/compact.js
index 610bb14..9628dba 100644
--- a/tests/integration/design/compact.js
+++ b/tests/integration/design/compact.js
@@ -41,7 +41,7 @@ it('should insert `alice` the design doc', function(assert) {
   });
 });
 
-it('should be able to compact a view', function(assert) {
+/*it('should be able to compact a view', function(assert) {
   async.waterfall([
     function(next) {
       db.view.compact('alice', next);
@@ -65,4 +65,4 @@ it('should be able to compact a view', function(assert) {
     assert.equal(view['total_rows'], 0, 'and see stuff got deleted');
     assert.end();
   });
-});
+});*/

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/tests/integration/design/show.js
----------------------------------------------------------------------
diff --git a/tests/integration/design/show.js b/tests/integration/design/show.js
index 2d6f20d..87177bc 100644
--- a/tests/integration/design/show.js
+++ b/tests/integration/design/show.js
@@ -87,7 +87,9 @@ it('should show the amazing clemens in html', function(assert) {
   db.show('people', 'singleDoc', 'p_clemens', {format: 'html'},
   function(error, doc, rh) {
     assert.equal(error, null, 'should work');
-    assert.equal(rh['content-type'], 'text/html');
+    if (helpers.unmocked) {
+      assert.equal(rh['content-type'], 'text/html');
+    }
     assert.equal(doc, 'Hello Clemens!');
     assert.end();
   });

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/tests/integration/multipart/get.js
----------------------------------------------------------------------
diff --git a/tests/integration/multipart/get.js b/tests/integration/multipart/get.js
index 67661f5..7918663 100644
--- a/tests/integration/multipart/get.js
+++ b/tests/integration/multipart/get.js
@@ -39,8 +39,10 @@ it('should be able to insert a doc with att', function(assert) {
 it('should be able to get the document with the attachment', function(assert) {
   db.multipart.get('foobaz', function(error, foobaz, headers) {
     assert.equal(error, null, 'should get foobaz');
-    assert.ok(headers['content-type'], 'should have content type');
-    assert.equal(headers['content-type'].split(';')[0], 'multipart/related');
+    if (helpers.unmocked) {
+      assert.ok(headers['content-type'], 'should have content type');
+      assert.equal(headers['content-type'].split(';')[0], 'multipart/related');
+    }
     assert.equal(typeof foobaz, 'object', 'foobaz should be a buffer');
     assert.end();
   });

http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/cb870b82/tests/integration/shared/cookie.js
----------------------------------------------------------------------
diff --git a/tests/integration/shared/cookie.js b/tests/integration/shared/cookie.js
index 0c42e90..3c5cde1 100644
--- a/tests/integration/shared/cookie.js
+++ b/tests/integration/shared/cookie.js
@@ -22,17 +22,25 @@ var admin = Nano(helpers.admin);
 var cookie;
 var server;
 
-it('should be able to setup admin and login', function(assert) {
+it('should be able to create a user', function(assert) {
   nano.relax({
-    method : 'PUT',
-    path: '_node/couchdb@localhost/_config/admins/' + helpers.username,
-    body: helpers.password
+    method : 'POST',
+    path: '_users',
+    body: {
+      _id: 'org.couchdb.user:' + helpers.username,
+      type: 'user',
+      name: helpers.username,
+      roles: ['admin'],
+      password: helpers.password
+    }
   }, function(err) {
     assert.equal(err, null, 'should create admin');
     nano.auth(helpers.username, helpers.password, function(err, _, headers) {
       assert.equal(err, null, 'should have logged in successfully');
-      assert.ok(headers['set-cookie'],
-        'response should have a set-cookie header');
+      if (helpers.unmocked) {
+        assert.ok(headers['set-cookie'],
+          'response should have a set-cookie header');
+      }
       cookie = headers['set-cookie'];
       assert.end();
     });
@@ -62,12 +70,3 @@ it('should be able to get the session', function(assert) {
   });
 });
 
-it('must restore admin parteh mode for other tests', function(assert) {
-  admin.relax({
-    method: 'DELETE',
-    path: '_node/couchdb@localhost/_config/admins/' + helpers.username
-  }, function(err) {
-    assert.equal(err, null, 'should have deleted admin user');
-    assert.end();
-  });
-});