How to use the couchbase.Mock function in couchbase

To help you get started, we’ve selected a few couchbase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github englercj / kouch / lib / index.js View on Github external
Kouch.prototype.connect = function (dsn, buckets, cb, mock) {
    if (mock) {
        this.cluster = new couchbase.Mock.Cluster(dsn);
    }
    else {
        this.cluster = new couchbase.Cluster(dsn);
    }


    // nothing passed, assume they want the default bucket
    if (!buckets) {
        buckets = { name: 'default' };
    }
    // string bucket name passed, parse into object
    else if (typeof buckets === 'string') {
        buckets = { name: buckets };
    }

    // catch the case of something strange being passed in...
github dsfields / couchbase-promises / tests / unit / couchbase.js View on Github external
describe('#Mock', () => {
    const mock = couchbase.Mock;
    const nmock = nativeCouch.Mock;
    describe('#N1qlQuery', () => {
      it('should reference native couchbase.N1qlQuery', (done) => {
        assert.strictEqual(mock.N1qlQuery, nmock.N1qlQuery);
        done();
      });
    });

    describe('#SpatialQuery', () => {
      it('should reference native couchbase.SpatialQuery', (done) => {
        assert.strictEqual(mock.SpatialQuery, nmock.SpatialQuery);
        done();
      });
    });

    describe('#ViewQuery', () => {
      it('should reference native couchbase.ViewQuery', (done) => {
github cvent / lounge / test / helpers / utils.js View on Github external
exports.getCluser = function () {
  return process.env.LOUNGE_COUCHBASE_MOCK
    ? new couchbase.Mock.Cluster('couchbase://127.0.0.1')
    : new couchbase.Cluster('couchbase://127.0.0.1')
}
github dsfields / couchbase-promises / lib / couchbase.js View on Github external
'use strict';

const couchbase = require('couchbase');
const elv = require('elv');

const Bucket = require('./bucket');
const Cluster = require('./cluster');
const promises = require('./promises');

const Mock = {
  Cluster: require('./mock-cluster'),
  SpatialQuery: couchbase.Mock.SpatialQuery,
  ViewQuery: couchbase.Mock.ViewQuery,
  N1qlQuery: couchbase.Mock.N1qlQuery,
  Mock: null,
  Error: couchbase.Mock.Error,
  errors: couchbase.Mock.errors
};

Mock.Mock = Mock;

class Couchbase {

  static get Cluster() { return Cluster; }
  static get SpatialQuery() { return couchbase.SpatialQuery; }
  static get ViewQuery() { return couchbase.ViewQuery; }
  static get N1qlQuery() { return couchbase.N1qlQuery; }
  static get CbasQuery() { return couchbase.CbasQuery; }
github dsfields / couchbase-promises / lib / couchbase.js View on Github external
'use strict';

const couchbase = require('couchbase');
const elv = require('elv');

const Bucket = require('./bucket');
const Cluster = require('./cluster');
const promises = require('./promises');

const Mock = {
  Cluster: require('./mock-cluster'),
  SpatialQuery: couchbase.Mock.SpatialQuery,
  ViewQuery: couchbase.Mock.ViewQuery,
  N1qlQuery: couchbase.Mock.N1qlQuery,
  Mock: null,
  Error: couchbase.Mock.Error,
  errors: couchbase.Mock.errors
};

Mock.Mock = Mock;

class Couchbase {

  static get Cluster() { return Cluster; }
  static get SpatialQuery() { return couchbase.SpatialQuery; }
  static get ViewQuery() { return couchbase.ViewQuery; }
  static get N1qlQuery() { return couchbase.N1qlQuery; }
  static get CbasQuery() { return couchbase.CbasQuery; }
  static get SearchQuery() { return couchbase.SearchQuery; }
github cvent / lounge / lib / lounge.js View on Github external
debug(`connect to open bucket`)
      this.bucket = options.bucket

      if (this.bucket) {
        this.db = Driver.create(this.bucket, this.config)
      }

      process.nextTick(() => retFn(null, this.bucket))
    } else if (options.bucket && typeof options.bucket === 'string' &&
      options.connectionString && typeof options.connectionString === 'string') {
      debug(`connect. cluster: ${options.connectionString} bucket: ${options.bucket}`)

      const clusterOpts = options.certpath ? {
        certpath: options.certpath
      } : null
      const ClusterCtor = options.mock || process.env.LOUNGE_COUCHBASE_MOCK ? couchbase.Mock.Cluster : couchbase.Cluster
      let args = typeof options.password === 'string'
        ? [options.bucket, options.password, retFn]
        : [options.bucket, retFn]

      const cluster = new ClusterCtor(options.connectionString, clusterOpts)

      if (typeof cluster.authenticate === 'function' && options.username) {
        cluster.authenticate(options.username, options.password)
        args = [options.bucket, retFn]
      }

      this.bucket = cluster.openBucket(...args)
    }
  }
github dsfields / couchbase-promises / lib / mock-cluster.js View on Github external
constructor(cnstr) {
    const native = new couchbase.Mock.Cluster(cnstr);

    native.authenticate = function(auther) {};
    native.query = function(query, params, callback) {
      process.nextTick(() => {
        callback(null, true);
      });
    }

    state.set(this, native);
  }