'use strict';

var assert = require('assert');
var harness = require('./harness.js');

describe('#cluster management', function() {
  function allTests(H) {
    it('should be able to access a cluster manager', function () {
      var cluster = new H.lib.Cluster(H.connstr);
      var clusterMgr = cluster.manager(H.muser, H.mpass);
      assert(clusterMgr);
    });

    it('should be able to list buckets', function () {
      var cluster = new H.lib.Cluster(H.connstr);
      var clusterMgr = cluster.manager(H.muser, H.mpass);
      clusterMgr.listBuckets(function (err, list) {
        assert(!err);
        assert(list);
      });
    });
  }
  describe('#RealBucket', function() {
    allTests.bind(this, harness);

    it('should not be able to list buckets with wrong password', function (done) {
      var cluster = new harness.lib.Cluster(harness.connstr);
      var clusterMgr = cluster.manager(harness.muser, 'junk');
      clusterMgr.listBuckets(function (err, list) {
        assert(err);
        assert.equal(err.message, 'operation failed (401)');
        assert(!list);
        done();
      });
    });
  });
  describe('#MockBucket', allTests.bind(this, harness.mock));
});

'use strict';

var assert = require('assert');
var harness = require('./harness.js');

describe('#cluster management', function() {
  function allTests(H) {
    it('should be able to access a cluster manager', function () {
      var cluster = new H.lib.Cluster(H.connstr);
      var clusterMgr = cluster.manager(H.muser, H.mpass);
      assert(clusterMgr);
    });

    it('should be able to list buckets', function () {
      var cluster = new H.lib.Cluster(H.connstr);
      var clusterMgr = cluster.manager(H.muser, H.mpass);
      clusterMgr.listBuckets(function (err, list) {
        assert(!err);
        assert(list);
      });
    });
  }
  describe('#RealBucket', function() {
    allTests.call(this, harness);

    it('should not be able to list buckets with wrong password', function (done) {
      var cluster = new harness.lib.Cluster(harness.connstr);
      var clusterMgr = cluster.manager(harness.muser, 'junk');
      clusterMgr.listBuckets(function (err, list) {
        assert(err);
        assert.equal(err.message, 'operation failed (401)');
        assert(!list);
        done();
      });
    });
  });
  describe('#MockBucket', allTests.bind(this, harness.mock));
});

Fix bug with cluster management on real buckets
JSCBC-409: Fix bug with cluster management on real buckets

Motivation
----------
A bug was causing certain cluster management tests to fail to
execute correctly during 'RealBucket' tests.

Changes
-------
Fixed incorrect use of bind rather than call.

Change-Id: Ia60b3940b2aad09da63fd6000d26bbea57f1c794
Reviewed-on: http://review.couchbase.org/82480
Reviewed-by: Sergey Avseyev <87f6d5e4fd3644c3c20800cde7fd3ad1569370b3@gmail.com>
Reviewed-by: Mike Goldsmith <c43a3c67d7a1203c37ce25b098df0254011e1ce6@gmail.com>
Tested-by: Brett Lawson <c8c4369773d7d7226e031f0c4af62e3f38a08510@gmail.com>
