Skip to content

Commit

Permalink
remove non-paginated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Mar 12, 2018
1 parent 9168f5d commit 6ee22f5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 243 deletions.
44 changes: 0 additions & 44 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,6 @@ Bigtable.prototype.getInstances = function(gaxOptions, callback) {
parent: this.projectName,
};

// @TODO this option shouldn't exist in the GAPIC client.
// Ref: https://github.com/googleapis/nodejs-bigtable/pull/35/files#r173892576
// gaxOptions.autoPaginate = false;

this.request(
{
client: 'BigtableInstanceAdminClient',
Expand All @@ -598,40 +594,6 @@ Bigtable.prototype.getInstances = function(gaxOptions, callback) {
);
};

/**
* Get {@link Instance} objects for all of your Compute instances as a readable
* object stream.
*
* @param {object} [query] Configuration object. See
* {@link Bigtable#getInstances} for a complete list of options.
* @returns {stream}
*
* @example
* const Bigtable = require('@google-cloud/bigtable');
* const bigtable = new Bigtable();
*
* bigtable.getInstancesStream()
* .on('error', console.error)
* .on('data', function(instance) {
* // `instance` is an Instance object.
* })
* .on('end', function() {
* // All instances retrieved.
* });
*
* //-
* // If you anticipate many results, you can end a stream early to prevent
* // unnecessary processing and API requests.
* //-
* bigtable.getInstancesStream()
* .on('data', function(instance) {
* this.end();
* });
*/
Bigtable.prototype.getInstancesStream = common.paginator.streamify(
'getInstances'
);

/**
* Get a reference to a Compute instance.
*
Expand Down Expand Up @@ -745,12 +707,6 @@ Bigtable.prototype.request = function(config, callback) {
}
};

/*! Developer Documentation
*
* These methods can be auto-paginated.
*/
common.paginator.extend(Bigtable, ['getInstances']);

/*! Developer Documentation
*
* All async methods (except for streams) will return a Promise in the event
Expand Down
41 changes: 3 additions & 38 deletions src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,9 @@ Instance.prototype.getClusters = function(gaxOptions, callback) {
}

var reqOpts = {
parent: this.projectName,
parent: this.id,
};

// @TODO this option shouldn't exist in the GAPIC client.
// Ref: https://github.com/googleapis/nodejs-bigtable/pull/35/files#r173892576
gaxOptions.autoPaginate = false;

this.bigtable.request(
{
client: 'BigtableInstanceAdminClient',
Expand All @@ -553,7 +549,7 @@ Instance.prototype.getClusters = function(gaxOptions, callback) {
return;
}

var clusters = resp.clusters.map(function(instanceData) {
var clusters = resp.clusters.map(function(clusterObj) {
var cluster = self.cluster(clusterObj.name);
cluster.metadata = clusterObj;
return cluster;
Expand All @@ -564,37 +560,6 @@ Instance.prototype.getClusters = function(gaxOptions, callback) {
);
};

/**
* Get {@link Cluster} objects for all of your clusters as a readable object
* stream.
*
* @param {object} [query] Configuration object. See
* {@link Instance#getClusters} for a complete list of options.
* @returns {stream}
*
* @example
* instance.getClustersStream()
* .on('error', console.error)
* .on('data', function(cluster) {
* // `cluster` is a Cluster object.
* })
* .on('end', function() {
* // All clusters retrieved.
* });
*
* //-
* // If you anticipate many results, you can end a stream early to prevent
* // unnecessary processing and API requests.
* //-
* instance.getClustersStream()
* .on('data', function(cluster) {
* this.end();
* });
*/
Instance.prototype.getClustersStream = common.paginator.streamify(
'getClusters'
);

/**
* Get the instance metadata.
*
Expand Down Expand Up @@ -846,7 +811,7 @@ Instance.prototype.table = function(name) {
*
* These methods can be auto-paginated.
*/
common.paginator.extend(Instance, ['getClusters', 'getTables']);
common.paginator.extend(Instance, ['getTables']);

/*! Developer Documentation
*
Expand Down
34 changes: 1 addition & 33 deletions system-test/bigtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var async = require('async');
var uuid = require('uuid');

var Bigtable = require('../');
var Instance = require('../src/instance.js');
var Cluster = require('../src/cluster.js');
var Table = require('../src/table.js');
var Family = require('../src/family.js');
Expand Down Expand Up @@ -87,7 +86,7 @@ describe('Bigtable', function() {
});
});

describe.only('instances', function() {
describe('instances', function() {
it('should get a list of instances', function(done) {
bigtable.getInstances(function(err, instances) {
assert.ifError(err);
Expand All @@ -96,22 +95,6 @@ describe('Bigtable', function() {
});
});

it('should get a list of instances in stream mode', function(done) {
var instances = [];

bigtable
.getInstancesStream()
.on('error', done)
.on('data', function(instance) {
assert(instance instanceof Instance);
instances.push(instance);
})
.on('end', function() {
assert(instances.length > 0);
done();
});
});

it('should check if an instance exists', function(done) {
INSTANCE.exists(function(err, exists) {
assert.ifError(err);
Expand Down Expand Up @@ -166,21 +149,6 @@ describe('Bigtable', function() {
});
});

it('should retrieve a list of clusters in stream mode', function(done) {
var clusters = [];

INSTANCE.getClustersStream()
.on('error', done)
.on('data', function(cluster) {
assert(cluster instanceof Cluster);
clusters.push(cluster);
})
.on('end', function() {
assert(clusters.length > 0);
done();
});
});

it('should check if a cluster exists', function(done) {
CLUSTER.exists(function(err, exists) {
assert.ifError(err);
Expand Down
88 changes: 9 additions & 79 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ function fakeRetryRequest() {
);
}

var fakePaginator = {
extend: function() {
this.calledWith_ = arguments;
},
streamify: function(methodName) {
return methodName;
},
};

function createFake(Class) {
function Fake() {
this.calledWith_ = arguments;
Expand All @@ -98,7 +89,6 @@ describe('Bigtable', function() {
before(function() {
Bigtable = proxyquire('../', {
'@google-cloud/common': {
paginator: fakePaginator,
util: fakeUtil,
},
'google-auto-auth': fakeGoogleAutoAuth,
Expand Down Expand Up @@ -141,17 +131,6 @@ describe('Bigtable', function() {
}
}

it('should extend the correct methods', function() {
var args = fakePaginator.calledWith_;

assert.strictEqual(args[0], Bigtable);
assert.deepEqual(args[1], ['getInstances']);
});

it('should streamify the correct methods', function() {
assert.strictEqual(bigtable.getInstancesStream, 'getInstances');
});

it('should promisify all the things', function() {
assert(promisified);
});
Expand Down Expand Up @@ -484,8 +463,10 @@ describe('Bigtable', function() {
bigtable.request = function(config) {
assert.strictEqual(config.client, 'BigtableInstanceAdminClient');
assert.strictEqual(config.method, 'listInstances');
assert.strictEqual(config.reqOpts.parent, bigtable.projectName);
assert.strictEqual(config.gaxOpts, undefined);
assert.deepStrictEqual(config.reqOpts, {
parent: bigtable.projectName,
});
assert.deepEqual(config.gaxOpts, {});
done();
};

Expand All @@ -500,40 +481,18 @@ describe('Bigtable', function() {
done();
};

bigtable.getInstances({gaxOptions}, assert.ifError);
});

it('should copy all query options', function(done) {
var fakeOptions = {
a: 'a',
b: 'b',
};

bigtable.request = function(config) {
Object.keys(fakeOptions).forEach(function(key) {
assert.strictEqual(config.reqOpts[key], fakeOptions[key]);
});

assert.notStrictEqual(config.reqOpts, fakeOptions);
done();
};

bigtable.getInstances(fakeOptions, assert.ifError);
bigtable.getInstances(gaxOptions, assert.ifError);
});

it('should return an error to the callback', function(done) {
var error = new Error('err');
var response = {};

bigtable.request = function(config, callback) {
callback(error, response);
callback(error);
};

bigtable.getInstances(function(err, instances, nextQuery, apiResponse) {
bigtable.getInstances(function(err) {
assert.strictEqual(err, error);
assert.strictEqual(instances, null);
assert.strictEqual(nextQuery, null);
assert.strictEqual(apiResponse, response);
done();
});
});
Expand All @@ -550,13 +509,10 @@ describe('Bigtable', function() {
],
};

var responseArg2 = {};
var responseArg3 = {};

var fakeInstances = [{}, {}];

bigtable.request = function(config, callback) {
callback(null, response, responseArg2, responseArg3);
callback(null, response);
};

var instanceCount = 0;
Expand All @@ -566,42 +522,16 @@ describe('Bigtable', function() {
return fakeInstances[instanceCount++];
};

bigtable.getInstances(function(err, instances, nextQuery, apiResponse) {
bigtable.getInstances(function(err, instances, apiResponse) {
assert.ifError(err);
assert.strictEqual(instances[0], fakeInstances[0]);
assert.strictEqual(instances[0].metadata, response.instances[0]);
assert.strictEqual(instances[1], fakeInstances[1]);
assert.strictEqual(instances[1].metadata, response.instances[1]);
assert.strictEqual(nextQuery, null);
assert.strictEqual(apiResponse, response);
done();
});
});

it('should provide a nextQuery object', function(done) {
var response = {
instances: [],
nextPageToken: 'a',
};

var options = {
a: 'b',
};

bigtable.request = function(config, callback) {
callback(null, response);
};

bigtable.getInstances(options, function(err, instances, nextQuery) {
var expectedQuery = extend({}, options, {
pageToken: response.nextPageToken,
});

assert.ifError(err);
assert.deepEqual(nextQuery, expectedQuery);
done();
});
});
});

describe('instance', function() {
Expand Down
Loading

0 comments on commit 6ee22f5

Please sign in to comment.